diff options
author | Ivan Chen <ivan@tagg.id> | 2021-03-26 18:08:13 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-03-26 18:08:57 -0400 |
commit | cb1781dc3294ad56ecd538c7aa30d3a9583ea330 (patch) | |
tree | 7091a32d459d8adffe9e79e67f24a214376f4ea3 /src | |
parent | b4c8fc3585feeeed4724a8629880ca798242055e (diff) |
better enum type
Diffstat (limited to 'src')
-rw-r--r-- | src/components/onboarding/UniversitySelection.tsx | 18 | ||||
-rw-r--r-- | src/screens/onboarding/Login.tsx | 23 | ||||
-rw-r--r-- | src/screens/onboarding/OnboardingStepThree.tsx | 42 | ||||
-rw-r--r-- | src/types/types.ts | 6 |
4 files changed, 45 insertions, 44 deletions
diff --git a/src/components/onboarding/UniversitySelection.tsx b/src/components/onboarding/UniversitySelection.tsx index 8ef013d3..9ca6822a 100644 --- a/src/components/onboarding/UniversitySelection.tsx +++ b/src/components/onboarding/UniversitySelection.tsx @@ -5,7 +5,7 @@ import {UniversityType} from '../../types'; import {normalize} from '../../utils'; interface UniversitySelectionProps { - selected: UniversityType | undefined; + selected: UniversityType; setSelected: (selected: UniversityType) => void; } @@ -17,23 +17,23 @@ const UniversitySelection: React.FC<UniversitySelectionProps> = ({ { imagePath: require('../../assets/images/badges/brown_badge.png'), title: 'Brown', - key: 'Brown University', + key: UniversityType.Brown, }, { imagePath: require('../../assets/images/badges/brown_badge.png'), title: 'Cornell', - key: 'Cornell University', - }, - { - imagePath: require('../../assets/images/badges/brown_badge.png'), - title: 'Harvard', - key: 'Harvard University', + key: UniversityType.Cornell, }, + // { + // imagePath: require('../../assets/images/badges/brown_badge.png'), + // title: 'Harvard', + // key: UniversityType.Harvard, + // }, ]; const renderButton = ( imagePath: ImageSourcePropType, title: string, - key: string, + key: UniversityType, ) => ( <TouchableOpacity style={ diff --git a/src/screens/onboarding/Login.tsx b/src/screens/onboarding/Login.tsx index a5713fc5..e19e3e5f 100644 --- a/src/screens/onboarding/Login.tsx +++ b/src/screens/onboarding/Login.tsx @@ -27,7 +27,7 @@ import { import {OnboardingStackParams} from '../../routes/onboarding'; import {fcmService} from '../../services'; import {RootState} from '../../store/rootReducer'; -import {BackgroundGradientType} from '../../types'; +import {BackgroundGradientType, UniversityType} from '../../types'; import {normalize, userLogin} from '../../utils'; import UpdateRequired from './UpdateRequired'; @@ -167,22 +167,25 @@ const Login: React.FC<LoginProps> = ({navigation}: LoginProps) => { } catch (err) { Alert.alert(ERROR_INVALID_LOGIN); } - } else if (statusCode === 200 && data.university === '') { + } else if ( + statusCode === 200 && + data.university === UniversityType.Empty + ) { /** - * A user account was created during onboarding step 2 but user didn't - * finish step 3, thus does not have a universtiy. - * Redirecting user back to onboarding to finish the process - */ + * A user account was created during onboarding step 2 but user didn't + * finish step 3, thus does not have a universtiy. + * Redirecting user back to onboarding to finish the process + */ navigation.navigate('OnboardingStepThree', { userId: data.UserID, username: username, }); } else if (statusCode === 200 && !data.isOnboarded) { /** - * A user account was created and finished the onboarding process but - * did not have an invitation code at the time so the user's account - * is not activated (isOnboarded) yet. - */ + * A user account was created and finished the onboarding process but + * did not have an invitation code at the time so the user's account + * is not activated (isOnboarded) yet. + */ navigation.navigate('InvitationCodeVerification', { userId: data.UserID, username: username, diff --git a/src/screens/onboarding/OnboardingStepThree.tsx b/src/screens/onboarding/OnboardingStepThree.tsx index a91c36fe..29028421 100644 --- a/src/screens/onboarding/OnboardingStepThree.tsx +++ b/src/screens/onboarding/OnboardingStepThree.tsx @@ -47,17 +47,25 @@ interface OnboardingStepThreeProps { navigation: OnboardingStepThreeNavigationProp; } +type FormType = { + smallPic: string; + university: UniversityType; + birthdate: string | undefined; + gender: string; + isValidGender: boolean; + classYear: number; + attemptedSubmit: boolean; +}; + const OnboardingStepThree: React.FC<OnboardingStepThreeProps> = ({ route, navigation, }) => { const {userId, username} = route.params; - let emptyDate: string | undefined; - let emptyUniversity: UniversityType | undefined; - const [form, setForm] = React.useState({ + const [form, setForm] = React.useState<FormType>({ smallPic: '', - university: emptyUniversity, - birthdate: emptyDate, + university: UniversityType.Empty, + birthdate: undefined, gender: '', isValidGender: true, classYear: -1, @@ -160,11 +168,11 @@ const OnboardingStepThree: React.FC<OnboardingStepThreeProps> = ({ Alert.alert(ERROR_SELECT_CLASS_YEAR); return; } - if (!form.university) { + if (form.university === UniversityType.Empty) { Alert.alert(ERROR_SELECT_UNIVERSITY); return; } - if (form.birthdate === emptyDate) { + if (!form.birthdate) { Alert.alert(ERROR_SELECT_BIRTHDAY); return; } @@ -178,7 +186,6 @@ const OnboardingStepThree: React.FC<OnboardingStepThreeProps> = ({ attemptedSubmit: true, }); } - let invalidFields: boolean = false; const request = new FormData(); if (form.smallPic) { request.append('smallProfilePicture', { @@ -188,16 +195,13 @@ const OnboardingStepThree: React.FC<OnboardingStepThreeProps> = ({ }); } - if (form.birthdate) { - request.append('birthday', form.birthdate); - } if (customGender) { if (form.isValidGender) { request.append('gender', form.gender); } else { setForm({...form, attemptedSubmit: false}); setTimeout(() => setForm({...form, attemptedSubmit: true})); - invalidFields = true; + return; } } else { if (form.isValidGender) { @@ -205,17 +209,9 @@ const OnboardingStepThree: React.FC<OnboardingStepThreeProps> = ({ } } - if (form.classYear !== -1) { - request.append('university_class', form.classYear); - } - - if (form.university) { - request.append('university', form.university); - } - - if (invalidFields) { - return; - } + request.append('birthday', form.birthdate); + request.append('university_class', form.classYear); + request.append('university', form.university); patchEditProfile(request, userId) .then((_) => diff --git a/src/types/types.ts b/src/types/types.ts index 360b2ffe..c1456e5f 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -22,8 +22,10 @@ export interface CategoryPreviewType { export type FriendshipStatusType = 'friends' | 'requested' | 'no_record'; export enum UniversityType { - brown = 'Brown University', - cornell = 'Cornell University', + Brown = 'Brown University', + Cornell = 'Cornell University', + // Harvard = 'Harvard University', + Empty = '', } export interface ProfileType { |