Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folasade/imp 19 profile tab #31

Closed
wants to merge 14 commits into from
126 changes: 84 additions & 42 deletions package-lock.json

Large diffs are not rendered by default.

52 changes: 30 additions & 22 deletions src/app/(Authentication)/SignUp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,58 @@ import styles from './styles';
import { signUpUser } from '../../../supabase/queries/auth';

export default function SignUpScreen() {
const [firstName, setFirstName] = useState('');
const [middleName, setMiddleName] = useState('');
const [lastName, setLastName] = useState('');
const [fullName, setFullName] = useState('');
const [email, setEmail] = useState('');
const [address, setAddress] = useState('');
const [streetName, setStreetName] = useState('');
const [usState, setUsState] = useState('');
const [city, setCity] = useState('');
const [zip, setZip] = useState('');
const [password, setPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');

return (
<View style={styles.container}>
<TextInput
style={styles.input}
value={firstName}
onChangeText={setFirstName}
placeholder="First name"
value={fullName}
onChangeText={setFullName}
placeholder="Full Legal name"
autoCapitalize="words"
/>
<TextInput
style={styles.input}
value={middleName}
onChangeText={setMiddleName}
placeholder="Middle name"
value={email}
onChangeText={setEmail}
placeholder="Email address"
keyboardType="email-address"
autoCapitalize="none"
/>
<TextInput
style={styles.input}
value={streetName}
onChangeText={setStreetName}
placeholder="Street Name"
autoCapitalize="words"
/>
<TextInput
style={styles.input}
value={lastName}
onChangeText={setLastName}
placeholder="Last name"
value={city}
onChangeText={setCity}
placeholder="City"
autoCapitalize="words"
/>
<TextInput
style={styles.input}
value={email}
onChangeText={setEmail}
placeholder="Email address"
keyboardType="email-address"
autoCapitalize="none"
value={usState}
onChangeText={setUsState}
placeholder="State"
autoCapitalize="words"
/>
<TextInput
style={styles.input}
value={address}
onChangeText={setAddress}
placeholder="Mailing address"
value={zip}
onChangeText={setZip}
placeholder="Zip Code"
autoCapitalize="words"
/>
<TextInput
Expand All @@ -70,7 +78,7 @@ export default function SignUpScreen() {
<TouchableOpacity
style={styles.button}
onPress={() =>
signUpUser(firstName, middleName, lastName, email, address, password)
signUpUser(fullName, email, password, streetName, city, usState, zip)
}
>
<Text>Sign Up</Text>
Expand Down
34 changes: 34 additions & 0 deletions src/app/(BottomTabNavigation)/Profile/DeleteAccount/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { useEffect, useState } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';

import {
deleteCurrentUser,
getCurrentUserInfo,
signOutUser,
} from '../../../../supabase/queries/auth';
import { userInstance, User } from '../../../../types/types';
import styles from '../styles';

function DeleteAccountScreen() {
const [currSession, setCurrSession] = useState<User>(userInstance);
useEffect(() => {
getCurrentUserInfo().then(result => {
stephaniewong2 marked this conversation as resolved.
Show resolved Hide resolved
setCurrSession(result);
});
}, []);
return (
<View>
<Text>Are you sure you want to delete your account?</Text>
<TouchableOpacity
style={styles.button}
onPress={() => {
deleteCurrentUser(currSession.id);
signOutUser();
}}
>
<Text>YES</Text>
</TouchableOpacity>
</View>
);
}
export default DeleteAccountScreen;
18 changes: 18 additions & 0 deletions src/app/(BottomTabNavigation)/Profile/DeleteAccount/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { StyleSheet } from 'react-native';

import { colors } from '../../../../styles/colors';

export default StyleSheet.create({
container: {
flex: 1,
backgroundColor: colors.white,
alignItems: 'center',
justifyContent: 'center',
},
button: {
margin: 10,
alignItems: 'center',
backgroundColor: colors.midGrey,
padding: 10,
},
});
67 changes: 67 additions & 0 deletions src/app/(BottomTabNavigation)/Profile/EditAddress/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { router } from 'expo-router';
import React, { useEffect, useState } from 'react';
import { Text, View, TextInput, TouchableOpacity } from 'react-native';

import styles from './styles';
import {
getCurrentUserInfo,
updateCurrUserAddress,
} from '../../../../supabase/queries/auth';

function EditNameScreen() {
const [streetName, setStreetName] = useState<string>();
const [usState, setUsState] = useState<string>();
const [city, setCity] = useState<string>();
const [zip, setZip] = useState<string>();
useEffect(() => {
getCurrentUserInfo().then(result => {
setStreetName(result.streetName);
setUsState(result.state);
setCity(result.city);
setZip(result.zip);
});
}, []);
return (
<View>
<Text>Edit Address</Text>
<TextInput
stephaniewong2 marked this conversation as resolved.
Show resolved Hide resolved
style={styles.input}
value={streetName}
onChangeText={setStreetName}
placeholder="Input Street Name"
/>
<TextInput
style={styles.input}
value={city}
onChangeText={setCity}
placeholder="Input City Here"
/>
<TextInput
style={styles.input}
value={usState}
onChangeText={setUsState}
placeholder="Input State Here"
/>
<TextInput
style={styles.input}
value={zip}
onChangeText={setZip}
placeholder="Input Zip Code Here"
/>
<TouchableOpacity
style={styles.button}
onPress={() => {
if (streetName && city && usState && zip) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as above for Edit Name!

updateCurrUserAddress(streetName, city, usState, zip);
router.push('/Profile/');
} else {
router.push('/Profile/');
}
}}
>
<Text>Update Address</Text>
</TouchableOpacity>
</View>
);
}
export default EditNameScreen;
27 changes: 27 additions & 0 deletions src/app/(BottomTabNavigation)/Profile/EditAddress/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { StyleSheet } from 'react-native';

import { colors } from '../../../../styles/colors';

export default StyleSheet.create({
container: {
flex: 1,
backgroundColor: colors.white,
alignItems: 'center',
justifyContent: 'center',
},
button: {
margin: 10,
alignItems: 'center',
backgroundColor: colors.midGrey,
padding: 10,
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
width: 310,
borderRadius: 5,
borderColor: colors.midGrey,
},
});
46 changes: 46 additions & 0 deletions src/app/(BottomTabNavigation)/Profile/EditName/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { router } from 'expo-router';
import React, { useEffect, useState } from 'react';
import { Text, View, TouchableOpacity, TextInput } from 'react-native';

import styles from './styles';
import {
getCurrentUserInfo,
updateCurrUserName,
} from '../../../../supabase/queries/auth';
import { User, userInstance } from '../../../../types/types';

function EditNameScreen() {
const [currSession, setCurrSession] = useState<User>(userInstance);
const [fullName, setFullName] = useState<string>();
useEffect(() => {
getCurrentUserInfo().then(result => {
stephaniewong2 marked this conversation as resolved.
Show resolved Hide resolved
setCurrSession(result);
setFullName(result.fullName);
});
}, []);
return (
<View>
<Text>Edit Name {currSession.fullName}</Text>
<TextInput
style={styles.input}
value={fullName}
onChangeText={setFullName}
placeholder="Full Name"
/>
<TouchableOpacity
style={styles.button}
onPress={() => {
if (fullName) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement is reached every time because fullName always has the user's name since we fetch it and set it at the start. I don't know how big of an issue it would be to run this query each time or if this would change with AuthContext but if you think running the query each time is okay, let's remove the if-else and just run both every time since that is what it is currently doing. Context: tested by logging inside if statement and reached even when name was not changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is something that's probably best to fix after auth context is implemented as it will be easier/less power to check if the name changed at all. But I agree that it's not the best to query each time and I need to fix.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay let's just address this when we implement Auth Context then

updateCurrUserName(fullName);
router.push('/Profile/');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird bug but whenever I click Update Name, I am redirected to the Cases screen with all the Case Cards instead of the Profile screen. Tried changing to /Profile but that did not do anything :(

} else {
router.push('/Profile/');
}
}}
>
<Text>Update Name</Text>
</TouchableOpacity>
</View>
);
}
export default EditNameScreen;
27 changes: 27 additions & 0 deletions src/app/(BottomTabNavigation)/Profile/EditName/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { StyleSheet } from 'react-native';

import { colors } from '../../../../styles/colors';

export default StyleSheet.create({
container: {
flex: 1,
backgroundColor: colors.white,
alignItems: 'center',
justifyContent: 'center',
},
button: {
margin: 10,
alignItems: 'center',
backgroundColor: colors.midGrey,
padding: 10,
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
width: 310,
borderRadius: 5,
borderColor: colors.midGrey,
},
});
21 changes: 21 additions & 0 deletions src/app/(BottomTabNavigation)/Profile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { router } from 'expo-router';
import React from 'react';
import { Text, TouchableOpacity, View } from 'react-native';

Expand All @@ -11,6 +12,26 @@ function ProfileScreen() {
<TouchableOpacity onPress={() => signOutUser()} style={styles.button}>
<Text>Sign Out</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
router.push('/Profile/DeleteAccount');
}}
>
<Text>Delete Account</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => router.push('/Profile/EditName')}
>
<Text>Edit Name</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => router.push('/Profile/EditAddress')}
>
<Text>Edit Address</Text>
</TouchableOpacity>
</View>
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function StartScreen() {
// });
supabase.auth.onAuthStateChange((_event, session) => {
if (session) {
router.replace('/Cases');
if (_event !== 'USER_UPDATED') {
router.replace('/Cases');
}
} else {
router.replace('Welcome');
}
Expand Down
15 changes: 15 additions & 0 deletions src/supabase/createAdminClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createClient } from '@supabase/supabase-js';
import 'react-native-url-polyfill/auto';

if (
!process.env.EXPO_PUBLIC_SUPABASE_URL ||
!process.env.SUPABASE_SERVICE_KEY
) {
throw new Error('Supabase environment variables are not defined.');
}
const supabaseAdmin = createClient(
process.env.EXPO_PUBLIC_SUPABASE_URL,
process.env.SUPABASE_SERVICE_KEY,
);

export default supabaseAdmin;
Loading