From e240ab56296ddbcd6a5407f0307d4400f734e27f Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 25 Mar 2021 14:20:43 -0400 Subject: added redirection --- src/screens/onboarding/Login.tsx | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/screens/onboarding/Login.tsx b/src/screens/onboarding/Login.tsx index 6d9d3a97..64157e7b 100644 --- a/src/screens/onboarding/Login.tsx +++ b/src/screens/onboarding/Login.tsx @@ -167,6 +167,11 @@ const Login: React.FC = ({navigation}: LoginProps) => { } catch (err) { Alert.alert(ERROR_INVALID_LOGIN); } + } else if (statusCode === 200 && data.university === '') { + navigation.navigate('OnboardingStepThree', { + userId: data.UserID, + username: username, + }); } else if (statusCode === 200 && !data.isOnboarded) { navigation.navigate('InvitationCodeVerification', { userId: data.UserID, -- cgit v1.2.3-70-g09d2 From c4047f0bd2293437373c19e84266cd8d010adc3c Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 25 Mar 2021 14:43:21 -0400 Subject: refactored editprofile endpoint --- src/screens/onboarding/OnboardingStepThree.tsx | 38 ++++++-------------------- src/screens/profile/EditProfile.tsx | 36 +++++------------------- src/services/UserProfileService.ts | 29 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/screens/onboarding/OnboardingStepThree.tsx b/src/screens/onboarding/OnboardingStepThree.tsx index f22d720f..6d379b5e 100644 --- a/src/screens/onboarding/OnboardingStepThree.tsx +++ b/src/screens/onboarding/OnboardingStepThree.tsx @@ -37,6 +37,7 @@ import { ERROR_UPLOAD_SMALL_PROFILE_PIC, } from '../../constants/strings'; import {OnboardingStackParams} from '../../routes/onboarding'; +import {patchEditProfile} from '../../services'; import {BackgroundGradientType} from '../../types'; import {normalize, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; @@ -213,39 +214,16 @@ const OnboardingStepThree: React.FC = ({ 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 ( diff --git a/src/screens/profile/EditProfile.tsx b/src/screens/profile/EditProfile.tsx index 56bed11f..fc428ee3 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,37 +365,14 @@ const EditProfile: React.FC = ({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, - }; - } + }) + .catch((error) => { + Alert.alert(error); + }); }, [isCustomGender, form, navigation, userId]); React.useLayoutEffect(() => { diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index dd77db9f..041dd4c3 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -3,6 +3,7 @@ import moment from 'moment'; import {Alert} from 'react-native'; import RNFetchBlob from 'rn-fetch-blob'; import { + EDIT_PROFILE_ENDPOINT, GET_FB_POSTS_ENDPOINT, GET_IG_POSTS_ENDPOINT, GET_TWITTER_POSTS_ENDPOINT, @@ -356,3 +357,31 @@ export const sendRegister = async ( return undefined; } }; + +export const patchEditProfile = async (form: FormData, userId: string) => { + 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: form, + }); + let statusCode = response.status; + if (statusCode === 200) { + return true; + } else if (statusCode === 400) { + let data = await response.json(); + throw ( + 'Profile update failed. πŸ˜”' + data.error || 'Something went wrong! 😭' + ); + } else { + throw ERROR_SOMETHING_WENT_WRONG_REFRESH; + } + } catch (error) { + throw ERROR_DOUBLE_CHECK_CONNECTION; + } +}; -- cgit v1.2.3-70-g09d2 From 76a6ab8c12669865c99e961d93b97613c63da3a5 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 25 Mar 2021 14:44:04 -0400 Subject: fixed warning --- src/screens/profile/EditProfile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/screens/profile/EditProfile.tsx b/src/screens/profile/EditProfile.tsx index fc428ee3..8afaeb6d 100644 --- a/src/screens/profile/EditProfile.tsx +++ b/src/screens/profile/EditProfile.tsx @@ -373,7 +373,7 @@ const EditProfile: React.FC = ({route, navigation}) => { .catch((error) => { Alert.alert(error); }); - }, [isCustomGender, form, navigation, userId]); + }, [form, isCustomGender, university_class, userId, navigation]); React.useLayoutEffect(() => { navigation.setOptions({ -- cgit v1.2.3-70-g09d2 From 40ae1e53f7e2f5a916a41b785980e24e7a5b4c59 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 25 Mar 2021 15:56:03 -0400 Subject: added UI for university selection --- src/components/onboarding/UniversitySelection.tsx | 93 +++++++++++++++++++++++ src/components/onboarding/index.ts | 1 + src/screens/onboarding/OnboardingStepThree.tsx | 23 +++--- 3 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 src/components/onboarding/UniversitySelection.tsx (limited to 'src') diff --git a/src/components/onboarding/UniversitySelection.tsx b/src/components/onboarding/UniversitySelection.tsx new file mode 100644 index 00000000..37a95790 --- /dev/null +++ b/src/components/onboarding/UniversitySelection.tsx @@ -0,0 +1,93 @@ +import React, {useState} from 'react'; +import {Image, ImageSourcePropType, StyleSheet, Text, View} from 'react-native'; +import {TouchableOpacity} from 'react-native-gesture-handler'; +import {normalize} from '../../utils'; + +interface UniversitySelectionProps { + selected: string; + setSelected: (selected: string) => void; +} + +const UniversitySelection: React.FC = ({selected, setSelected}) => { + const crestData = [ + { + imagePath: require('../../assets/images/badges/brown_badge.png'), + title: 'Brown', + key: 'Brown University', + }, + { + 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', + }, + ]; + const renderButton = ( + imagePath: ImageSourcePropType, + title: string, + key: string, + ) => ( + setSelected(key)}> + + {title} + + ); + return ( + <> + University Badge + + {crestData.map((data) => + renderButton(data.imagePath, data.title, data.key), + )} + + + ); +}; + +const styles = StyleSheet.create({ + title: { + color: 'white', + fontSize: normalize(15), + lineHeight: normalize(18), + fontWeight: '700', + marginBottom: 10, + }, + container: { + flexDirection: 'row', + justifyContent: 'space-around', + marginBottom: 10, + }, + crest: { + height: normalize(25), + aspectRatio: 31 / 38, + marginBottom: 5, + }, + crestContainer: { + alignItems: 'center', + padding: 10, + }, + crestContainerSelected: { + alignItems: 'center', + borderWidth: 2, + borderColor: 'white', + borderRadius: 5, + padding: 8, + backgroundColor: '#fff2', + }, + crestLabel: { + color: 'white', + fontSize: normalize(15), + lineHeight: normalize(18), + fontWeight: '500', + }, +}); + +export default UniversitySelection; diff --git a/src/components/onboarding/index.ts b/src/components/onboarding/index.ts index b790933f..fdb85090 100644 --- a/src/components/onboarding/index.ts +++ b/src/components/onboarding/index.ts @@ -10,3 +10,4 @@ export {default as TaggDropDown} from './TaggDropDown'; export {default as SocialMediaLinker} from './SocialMediaLinker'; export {default as LinkSocialMedia} from './LinkSocialMedia'; export {default as MomentCategory} from './MomentCategory'; +export {default as UniversitySelection} from './UniversitySelection'; diff --git a/src/screens/onboarding/OnboardingStepThree.tsx b/src/screens/onboarding/OnboardingStepThree.tsx index 6d379b5e..dffdf2fe 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,20 +19,13 @@ 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_UPLOAD_SMALL_PROFILE_PIC, } from '../../constants/strings'; import {OnboardingStackParams} from '../../routes/onboarding'; @@ -62,6 +54,7 @@ const OnboardingStepThree: React.FC = ({ let emptyDate: string | undefined; const [form, setForm] = React.useState({ smallPic: '', + university: '', birthdate: emptyDate, gender: '', isValidGender: true, @@ -210,6 +203,10 @@ const OnboardingStepThree: React.FC = ({ request.append('university_class', form.classYear); } + if (form.university !== '') { + request.append('university', form.university); + } + if (invalidFields) { return; } @@ -242,6 +239,12 @@ const OnboardingStepThree: React.FC = ({ /> + { + setForm({ + ...form, + university: selected + }) + }}/> handleClassYearUpdate(value)} items={classYearList} -- cgit v1.2.3-70-g09d2 From 3728df66381c77db8fe37032bbddb0a0aca79f2e Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 25 Mar 2021 16:11:53 -0400 Subject: updated to use formdata for register, make university required --- src/constants/strings.ts | 7 ++++--- src/screens/onboarding/OnboardingStepThree.tsx | 4 ++++ src/services/UserProfileService.ts | 19 +++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/constants/strings.ts b/src/constants/strings.ts index cb442b7b..66d4a6d9 100644 --- a/src/constants/strings.ts +++ b/src/constants/strings.ts @@ -6,6 +6,7 @@ export const ADD_COMMENT_TEXT = (username?: string) => username ? `Reply to ${us export const COMING_SOON_MSG = 'Creating more fun things for you, surprises coming soon πŸ˜‰'; export const ERROR_ATTEMPT_EDIT_SP = 'Can\'t let you do that yet! Please onboard Suggested People first!'; export const ERROR_AUTHENTICATION = 'An error occurred during authentication. Please login again!'; +export const ERROR_BADGES_EXCEED_LIMIT = 'You can\'t have more than 5 badges!'; export const ERROR_CATEGORY_CREATION = 'There was a problem creating your categories. Please refresh and try again.'; export const ERROR_CATEGORY_UPDATE = 'There was a problem updating your categories. Please refresh and try again'; export const ERROR_DELETE_CATEGORY = 'There was a problem while deleting category. Please try again'; @@ -35,6 +36,7 @@ export const ERROR_REGISTRATION = (str: string) => `Registration failed πŸ˜”, ${ export const ERROR_SELECT_BIRTHDAY = 'Please select your birthday'; export const ERROR_SELECT_CLASS_YEAR = 'Please select your Class Year'; export const ERROR_SELECT_GENDER = 'Please select your gender'; +export const ERROR_SELECT_UNIVERSITY = 'Please select your University'; export const ERROR_SERVER_DOWN = 'mhm, looks like our servers are down, please refresh and try again in a few mins'; export const ERROR_SOMETHING_WENT_WRONG = 'Oh dear, don’t worry someone will be held responsible for this error, In the meantime refresh the app'; export const ERROR_SOMETHING_WENT_WRONG_REFRESH = "Ha, looks like this one's on us, please refresh and try again"; @@ -44,21 +46,20 @@ export const ERROR_UNABLE_TO_FIND_PROFILE = 'We were unable to find this profile export const ERROR_UNABLE_TO_VIEW_PROFILE = 'Unable to view this profile'; export const ERROR_UPLOAD = 'An error occurred while uploading. Please try again!'; export const ERROR_UPLOAD_BADGES = 'Unable to upload your badges. Please retry!'; -export const ERROR_BADGES_EXCEED_LIMIT = 'You can\'t have more than 5 badges!'; export const ERROR_UPLOAD_LARGE_PROFILE_PIC = "Can't have the first image seen on the profile be blank, please upload a large picture"; export const ERROR_UPLOAD_MOMENT = 'Unable to upload moment. Please retry'; -export const ERROR_UPLOAD_SP_PHOTO = 'Unable to update suggested people photo. Please retry!'; export const ERROR_UPLOAD_SMALL_PROFILE_PIC = "Can't have a profile without a pic to represent you, please upload a small profile picture"; +export const ERROR_UPLOAD_SP_PHOTO = 'Unable to update suggested people photo. Please retry!'; export const ERROR_VERIFICATION_FAILED_SHORT = 'Verification failed πŸ˜“'; export const MARKED_AS_MSG = (str: string) => `Marked as ${str}`; export const MOMENT_DELETED_MSG = 'Moment deleted....Some moments have to go, to create space for greater ones'; export const NO_NEW_NOTIFICATIONS = 'You have no new notifications'; export const NO_RESULTS_FOUND = 'No Results Found!'; +export const SUCCESS_BADGES_UPDATE = 'Badges updated successfully!' export const SUCCESS_CATEGORY_DELETE = 'Category successfully deleted, but its memory will live on'; export const SUCCESS_INVITATION_CODE = 'Welcome to Tagg!'; export const SUCCESS_LINK = (str: string) => `Successfully linked ${str} πŸŽ‰`; export const SUCCESS_PIC_UPLOAD = 'Beautiful, the picture was uploaded successfully!'; -export const SUCCESS_BADGES_UPDATE = 'Badges updated successfully!' export const SUCCESS_PWD_RESET = 'Your password was reset successfully!'; export const SUCCESS_VERIFICATION_CODE_SENT = 'New verification code sent! Check your phone messages for your code'; export const UP_TO_DATE = 'Up-to-Date!'; diff --git a/src/screens/onboarding/OnboardingStepThree.tsx b/src/screens/onboarding/OnboardingStepThree.tsx index dffdf2fe..120380c1 100644 --- a/src/screens/onboarding/OnboardingStepThree.tsx +++ b/src/screens/onboarding/OnboardingStepThree.tsx @@ -158,6 +158,10 @@ const OnboardingStepThree: React.FC = ({ 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; diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 041dd4c3..a5b42814 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -340,16 +340,19 @@ export const sendRegister = async ( password: string, ) => { try { + const form = new FormData() + form.append('first_name', firstName) + form.append('last_name', lastName) + form.append('email', email) + form.append('phone_number', phone) + form.append('username', username) + form.append('password', password) const response = await fetch(REGISTER_ENDPOINT, { method: 'POST', - body: JSON.stringify({ - first_name: firstName, - last_name: lastName, - email: email, - phone_number: phone, - username: username, - password: password, - }), + headers: { + 'Content-Type': 'multipart/form-data', + }, + body: form }); return response; } catch (error) { -- cgit v1.2.3-70-g09d2 From 70c4baa05d13d36bc56e8647c13ba40701450504 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 25 Mar 2021 16:17:48 -0400 Subject: added comments --- src/screens/onboarding/Login.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/screens/onboarding/Login.tsx b/src/screens/onboarding/Login.tsx index 64157e7b..a5713fc5 100644 --- a/src/screens/onboarding/Login.tsx +++ b/src/screens/onboarding/Login.tsx @@ -168,11 +168,21 @@ const Login: React.FC = ({navigation}: LoginProps) => { 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, -- cgit v1.2.3-70-g09d2 From 883a6c51d4c3e442df5e6c0f3dc6fada2f370f8e Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 26 Mar 2021 14:58:15 -0400 Subject: using university type --- src/components/onboarding/UniversitySelection.tsx | 12 ++++++++---- src/screens/onboarding/OnboardingStepThree.tsx | 23 ++++++++++++++--------- src/types/types.ts | 6 ++++++ 3 files changed, 28 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/components/onboarding/UniversitySelection.tsx b/src/components/onboarding/UniversitySelection.tsx index 37a95790..8ef013d3 100644 --- a/src/components/onboarding/UniversitySelection.tsx +++ b/src/components/onboarding/UniversitySelection.tsx @@ -1,14 +1,18 @@ -import React, {useState} from 'react'; +import React from 'react'; import {Image, ImageSourcePropType, StyleSheet, Text, View} from 'react-native'; import {TouchableOpacity} from 'react-native-gesture-handler'; +import {UniversityType} from '../../types'; import {normalize} from '../../utils'; interface UniversitySelectionProps { - selected: string; - setSelected: (selected: string) => void; + selected: UniversityType | undefined; + setSelected: (selected: UniversityType) => void; } -const UniversitySelection: React.FC = ({selected, setSelected}) => { +const UniversitySelection: React.FC = ({ + selected, + setSelected, +}) => { const crestData = [ { imagePath: require('../../assets/images/badges/brown_badge.png'), diff --git a/src/screens/onboarding/OnboardingStepThree.tsx b/src/screens/onboarding/OnboardingStepThree.tsx index 120380c1..81f4dc97 100644 --- a/src/screens/onboarding/OnboardingStepThree.tsx +++ b/src/screens/onboarding/OnboardingStepThree.tsx @@ -26,11 +26,12 @@ import { ERROR_SELECT_BIRTHDAY, ERROR_SELECT_CLASS_YEAR, ERROR_SELECT_GENDER, + ERROR_SELECT_UNIVERSITY, ERROR_UPLOAD_SMALL_PROFILE_PIC, } from '../../constants/strings'; import {OnboardingStackParams} from '../../routes/onboarding'; import {patchEditProfile} from '../../services'; -import {BackgroundGradientType} from '../../types'; +import {BackgroundGradientType, UniversityType} from '../../types'; import {normalize, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; type OnboardingStepThreeRouteProp = RouteProp< @@ -52,9 +53,10 @@ const OnboardingStepThree: React.FC = ({ }) => { const {userId, username} = route.params; let emptyDate: string | undefined; + let emptyUniversity: UniversityType | undefined; const [form, setForm] = React.useState({ smallPic: '', - university: '', + university: emptyUniversity, birthdate: emptyDate, gender: '', isValidGender: true, @@ -158,7 +160,7 @@ const OnboardingStepThree: React.FC = ({ Alert.alert(ERROR_SELECT_CLASS_YEAR); return; } - if (form.university === '') { + if (!form.university) { Alert.alert(ERROR_SELECT_UNIVERSITY); return; } @@ -243,12 +245,15 @@ const OnboardingStepThree: React.FC = ({ /> - { - setForm({ - ...form, - university: selected - }) - }}/> + { + setForm({ + ...form, + university: selected, + }); + }} + /> handleClassYearUpdate(value)} items={classYearList} diff --git a/src/types/types.ts b/src/types/types.ts index dc2817bd..412d9000 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -21,12 +21,18 @@ export interface CategoryPreviewType { export type FriendshipStatusType = 'friends' | 'requested' | 'no_record'; +export enum UniversityType { + brown = 'Brown', + cornell = 'Cornell', +} + export interface ProfileType { name: string; biography: string; website: string; gender: string; university_class: number; + university: UniversityType | undefined; profile_completion_stage: number; suggested_people_linked: number; birthday: Date | undefined; -- cgit v1.2.3-70-g09d2 From a7be1ca4e5490ed6a27bd4c90f15b9ac85b0356f Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 26 Mar 2021 14:31:31 -0700 Subject: resolves undefined error --- src/components/profile/ProfileMoreInfoDrawer.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/components/profile/ProfileMoreInfoDrawer.tsx b/src/components/profile/ProfileMoreInfoDrawer.tsx index 2fec5cca..a77a2e84 100644 --- a/src/components/profile/ProfileMoreInfoDrawer.tsx +++ b/src/components/profile/ProfileMoreInfoDrawer.tsx @@ -24,11 +24,9 @@ const ProfileMoreInfoDrawer: React.FC = (props) => { const {setIsOpen, userXId, isBlocked, handleBlockUnblock, userXName} = props; const { user: {userId, username}, - } = useSelector((state: RootState) => state.user); + profile, + } = useSelector((state: RootState) => state?.user); const isOwnProfile = !userXId || userXName === username; - const {suggested_people_linked} = useSelector( - (state: RootState) => state.user.profile, - ); const goToEditProfile = () => { navigation.push('EditProfile', { @@ -39,7 +37,7 @@ const ProfileMoreInfoDrawer: React.FC = (props) => { }; const goToUpdateSPProfile = () => { - if (suggested_people_linked === 0) { + if (profile.suggested_people_linked === 0) { Alert.alert(ERROR_ATTEMPT_EDIT_SP); } else { // Sending undefined for updatedSelectedBadges to mark that there was no update yet -- cgit v1.2.3-70-g09d2 From d52e3bcecb96206f4bee843bb8047496f37a370c Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 26 Mar 2021 14:43:37 -0700 Subject: tiny mistakes --- src/screens/onboarding/OnboardingStepThree.tsx | 2 +- src/types/types.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/screens/onboarding/OnboardingStepThree.tsx b/src/screens/onboarding/OnboardingStepThree.tsx index 81f4dc97..097cfb1c 100644 --- a/src/screens/onboarding/OnboardingStepThree.tsx +++ b/src/screens/onboarding/OnboardingStepThree.tsx @@ -209,7 +209,7 @@ const OnboardingStepThree: React.FC = ({ request.append('university_class', form.classYear); } - if (form.university !== '') { + if (form.university !== undefined) { request.append('university', form.university); } diff --git a/src/types/types.ts b/src/types/types.ts index 80e404e6..360b2ffe 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -22,8 +22,8 @@ export interface CategoryPreviewType { export type FriendshipStatusType = 'friends' | 'requested' | 'no_record'; export enum UniversityType { - brown = 'Brown', - cornell = 'Cornell', + brown = 'Brown University', + cornell = 'Cornell University', } export interface ProfileType { -- cgit v1.2.3-70-g09d2 From b4c8fc3585feeeed4724a8629880ca798242055e Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 26 Mar 2021 14:47:26 -0700 Subject: simplified --- src/screens/onboarding/OnboardingStepThree.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/screens/onboarding/OnboardingStepThree.tsx b/src/screens/onboarding/OnboardingStepThree.tsx index 097cfb1c..a91c36fe 100644 --- a/src/screens/onboarding/OnboardingStepThree.tsx +++ b/src/screens/onboarding/OnboardingStepThree.tsx @@ -209,7 +209,7 @@ const OnboardingStepThree: React.FC = ({ request.append('university_class', form.classYear); } - if (form.university !== undefined) { + if (form.university) { request.append('university', form.university); } -- cgit v1.2.3-70-g09d2 From cb1781dc3294ad56ecd538c7aa30d3a9583ea330 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 26 Mar 2021 18:08:13 -0400 Subject: better enum type --- src/components/onboarding/UniversitySelection.tsx | 18 +++++----- src/screens/onboarding/Login.tsx | 23 +++++++------ src/screens/onboarding/OnboardingStepThree.tsx | 42 ++++++++++------------- src/types/types.ts | 6 ++-- 4 files changed, 45 insertions(+), 44 deletions(-) (limited to 'src') 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 = ({ { 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, ) => ( = ({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 = ({ 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({ smallPic: '', - university: emptyUniversity, - birthdate: emptyDate, + university: UniversityType.Empty, + birthdate: undefined, gender: '', isValidGender: true, classYear: -1, @@ -160,11 +168,11 @@ const OnboardingStepThree: React.FC = ({ 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 = ({ attemptedSubmit: true, }); } - let invalidFields: boolean = false; const request = new FormData(); if (form.smallPic) { request.append('smallProfilePicture', { @@ -188,16 +195,13 @@ const OnboardingStepThree: React.FC = ({ }); } - 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 = ({ } } - 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 { -- cgit v1.2.3-70-g09d2 From 488cd69657d33ca6986aa631614495cf205c56d2 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 26 Mar 2021 18:12:42 -0400 Subject: minor change --- src/screens/onboarding/Login.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/screens/onboarding/Login.tsx b/src/screens/onboarding/Login.tsx index e19e3e5f..97f4fe87 100644 --- a/src/screens/onboarding/Login.tsx +++ b/src/screens/onboarding/Login.tsx @@ -156,12 +156,15 @@ const Login: React.FC = ({navigation}: LoginProps) => { let statusCode = response.status; let data = await response.json(); + if (statusCode === 200) { + await AsyncStorage.setItem('token', data.token); + await AsyncStorage.setItem('userId', data.UserID); + await AsyncStorage.setItem('username', username); + } + if (statusCode === 200 && data.isOnboarded) { //Stores token received in the response into client's AsynStorage try { - await AsyncStorage.setItem('token', data.token); - await AsyncStorage.setItem('userId', data.UserID); - await AsyncStorage.setItem('username', username); userLogin(dispatch, {userId: data.UserID, username}); fcmService.sendFcmTokenToServer(); } catch (err) { -- cgit v1.2.3-70-g09d2 From ca8b6c15856d3552b4a00ba36ef8a203d01f952e Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 26 Mar 2021 18:16:09 -0400 Subject: added correct badges --- src/assets/universities/cornell-clicked.png | Bin 0 -> 12362 bytes src/assets/universities/cornell-search.png | Bin 0 -> 12171 bytes src/assets/universities/cornell.png | Bin 0 -> 12353 bytes src/components/onboarding/UniversitySelection.tsx | 6 +++--- 4 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 src/assets/universities/cornell-clicked.png create mode 100644 src/assets/universities/cornell-search.png create mode 100644 src/assets/universities/cornell.png (limited to 'src') diff --git a/src/assets/universities/cornell-clicked.png b/src/assets/universities/cornell-clicked.png new file mode 100644 index 00000000..d6450b29 Binary files /dev/null and b/src/assets/universities/cornell-clicked.png differ diff --git a/src/assets/universities/cornell-search.png b/src/assets/universities/cornell-search.png new file mode 100644 index 00000000..ce41e7bc Binary files /dev/null and b/src/assets/universities/cornell-search.png differ diff --git a/src/assets/universities/cornell.png b/src/assets/universities/cornell.png new file mode 100644 index 00000000..bf15f8b2 Binary files /dev/null and b/src/assets/universities/cornell.png differ diff --git a/src/components/onboarding/UniversitySelection.tsx b/src/components/onboarding/UniversitySelection.tsx index 9ca6822a..92bec47f 100644 --- a/src/components/onboarding/UniversitySelection.tsx +++ b/src/components/onboarding/UniversitySelection.tsx @@ -15,17 +15,17 @@ const UniversitySelection: React.FC = ({ }) => { const crestData = [ { - imagePath: require('../../assets/images/badges/brown_badge.png'), + imagePath: require('../../assets/universities/brown.png'), title: 'Brown', key: UniversityType.Brown, }, { - imagePath: require('../../assets/images/badges/brown_badge.png'), + imagePath: require('../../assets/universities/cornell.png'), title: 'Cornell', key: UniversityType.Cornell, }, // { - // imagePath: require('../../assets/images/badges/brown_badge.png'), + // imagePath: require('../../assets/universities/harvard.png'), // title: 'Harvard', // key: UniversityType.Harvard, // }, -- cgit v1.2.3-70-g09d2 From fca7886b673211ed566d7d5bb96ee5e594e8005a Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 26 Mar 2021 18:17:17 -0400 Subject: minor fix --- src/types/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/types/types.ts b/src/types/types.ts index c1456e5f..48b52366 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -42,7 +42,7 @@ export interface ProfileInfoType { website: string; gender: string; university_class: number; - university: UniversityType | undefined; + university: UniversityType; profile_completion_stage: number; suggested_people_linked: number; birthday: Date | undefined; -- cgit v1.2.3-70-g09d2