diff options
Diffstat (limited to 'src/screens')
-rw-r--r-- | src/screens/onboarding/Login.tsx | 15 | ||||
-rw-r--r-- | src/screens/onboarding/OnboardingStepThree.tsx | 72 | ||||
-rw-r--r-- | src/screens/profile/EditProfile.tsx | 38 |
3 files changed, 54 insertions, 71 deletions
diff --git a/src/screens/onboarding/Login.tsx b/src/screens/onboarding/Login.tsx index 6d9d3a97..a5713fc5 100644 --- a/src/screens/onboarding/Login.tsx +++ b/src/screens/onboarding/Login.tsx @@ -167,7 +167,22 @@ const Login: React.FC<LoginProps> = ({navigation}: LoginProps) => { } catch (err) { Alert.alert(ERROR_INVALID_LOGIN); } + } else if (statusCode === 200 && data.university === '') { + /** + * 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. + */ navigation.navigate('InvitationCodeVerification', { userId: data.UserID, username: username, diff --git a/src/screens/onboarding/OnboardingStepThree.tsx b/src/screens/onboarding/OnboardingStepThree.tsx index f22d720f..81f4dc97 100644 --- a/src/screens/onboarding/OnboardingStepThree.tsx +++ b/src/screens/onboarding/OnboardingStepThree.tsx @@ -1,4 +1,3 @@ -import AsyncStorage from '@react-native-community/async-storage'; import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; import moment from 'moment'; @@ -20,24 +19,19 @@ import { RegistrationWizard, TaggDropDown, TaggInput, + UniversitySelection, } from '../../components'; +import {CLASS_YEAR_LIST, genderRegex, TAGG_PURPLE} from '../../constants'; import { - CLASS_YEAR_LIST, - EDIT_PROFILE_ENDPOINT, - genderRegex, - TAGG_PURPLE, -} from '../../constants'; -import { - ERROR_DOUBLE_CHECK_CONNECTION, - ERROR_PROFILE_CREATION_SHORT, ERROR_SELECT_BIRTHDAY, ERROR_SELECT_CLASS_YEAR, ERROR_SELECT_GENDER, - ERROR_SOMETHING_WENT_WRONG_REFRESH, + ERROR_SELECT_UNIVERSITY, ERROR_UPLOAD_SMALL_PROFILE_PIC, } from '../../constants/strings'; import {OnboardingStackParams} from '../../routes/onboarding'; -import {BackgroundGradientType} from '../../types'; +import {patchEditProfile} from '../../services'; +import {BackgroundGradientType, UniversityType} from '../../types'; import {normalize, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; type OnboardingStepThreeRouteProp = RouteProp< @@ -59,8 +53,10 @@ const OnboardingStepThree: React.FC<OnboardingStepThreeProps> = ({ }) => { const {userId, username} = route.params; let emptyDate: string | undefined; + let emptyUniversity: UniversityType | undefined; const [form, setForm] = React.useState({ smallPic: '', + university: emptyUniversity, birthdate: emptyDate, gender: '', isValidGender: true, @@ -164,6 +160,10 @@ const OnboardingStepThree: React.FC<OnboardingStepThreeProps> = ({ Alert.alert(ERROR_SELECT_CLASS_YEAR); return; } + if (!form.university) { + Alert.alert(ERROR_SELECT_UNIVERSITY); + return; + } if (form.birthdate === emptyDate) { Alert.alert(ERROR_SELECT_BIRTHDAY); return; @@ -209,43 +209,24 @@ const OnboardingStepThree: React.FC<OnboardingStepThreeProps> = ({ request.append('university_class', form.classYear); } + if (form.university !== '') { + request.append('university', form.university); + } + if (invalidFields) { return; } - const endpoint = EDIT_PROFILE_ENDPOINT + `${userId}/`; - try { - const token = await AsyncStorage.getItem('token'); - let response = await fetch(endpoint, { - method: 'PATCH', - headers: { - 'Content-Type': 'multipart/form-data', - Authorization: 'Token ' + token, - }, - body: request, - }); - let statusCode = response.status; - let data = await response.json(); - if (statusCode === 200) { + patchEditProfile(request, userId) + .then((_) => navigation.navigate('InvitationCodeVerification', { userId: route.params.userId, username: username, - }); - } else if (statusCode === 400) { - Alert.alert( - 'Profile update failed. 😔', - data.error || 'Something went wrong! ðŸ˜', - ); - } else { - Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); - } - } catch (error) { - Alert.alert(ERROR_PROFILE_CREATION_SHORT, ERROR_DOUBLE_CHECK_CONNECTION); - return { - name: 'Profile creation error', - description: error, - }; - } + }), + ) + .catch((error) => { + Alert.alert(error); + }); }; return ( @@ -264,6 +245,15 @@ const OnboardingStepThree: React.FC<OnboardingStepThreeProps> = ({ /> </View> <View style={styles.contentContainer}> + <UniversitySelection + selected={form.university} + setSelected={(selected) => { + setForm({ + ...form, + university: selected, + }); + }} + /> <TaggDropDown onValueChange={(value: string) => handleClassYearUpdate(value)} items={classYearList} diff --git a/src/screens/profile/EditProfile.tsx b/src/screens/profile/EditProfile.tsx index 56bed11f..8afaeb6d 100644 --- a/src/screens/profile/EditProfile.tsx +++ b/src/screens/profile/EditProfile.tsx @@ -46,6 +46,7 @@ import { ERROR_UPLOAD_SMALL_PROFILE_PIC, } from '../../constants/strings'; import TaggLoadingIndicator from '../../components/common/TaggLoadingIndicator'; +import {patchEditProfile} from '../../services'; type EditProfileNavigationProp = StackNavigationProp< MainStackParams, @@ -364,38 +365,15 @@ const EditProfile: React.FC<EditProfileProps> = ({route, navigation}) => { return; } - const endpoint = EDIT_PROFILE_ENDPOINT + `${userId}/`; - try { - const token = await AsyncStorage.getItem('token'); - let response = await fetch(endpoint, { - method: 'PATCH', - headers: { - 'Content-Type': 'multipart/form-data', - Authorization: 'Token ' + token, - }, - body: request, - }); - let statusCode = response.status; - let data = await response.json(); - if (statusCode === 200) { + patchEditProfile(request, userId) + .then((_) => { setNeedsUpdate(true); navigation.pop(); - } else if (statusCode === 400) { - Alert.alert( - 'Profile update failed. 😔', - data.error || 'Something went wrong! ðŸ˜', - ); - } else { - Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH); - } - } catch (error) { - Alert.alert(ERROR_DOUBLE_CHECK_CONNECTION); - return { - name: 'Profile creation error', - description: error, - }; - } - }, [isCustomGender, form, navigation, userId]); + }) + .catch((error) => { + Alert.alert(error); + }); + }, [form, isCustomGender, university_class, userId, navigation]); React.useLayoutEffect(() => { navigation.setOptions({ |