diff options
| author | Ivan Chen <ivan@tagg.id> | 2021-03-26 19:53:32 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-26 19:53:32 -0400 |
| commit | bef5728b24a71d1bf327a72e425346020a997037 (patch) | |
| tree | deabc8fa1f5bd2fd983a6dc7784379498b194fb2 /src/screens/onboarding/Login.tsx | |
| parent | 641a084bb6172b801349067dff0490525d0effea (diff) | |
| parent | fca7886b673211ed566d7d5bb96ee5e594e8005a (diff) | |
Merge pull request #331 from IvanIFChen/tma728-select-school-onboarding
[TMA-728] Select university during onboarding
Diffstat (limited to 'src/screens/onboarding/Login.tsx')
| -rw-r--r-- | src/screens/onboarding/Login.tsx | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/screens/onboarding/Login.tsx b/src/screens/onboarding/Login.tsx index 6d9d3a97..97f4fe87 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'; @@ -156,18 +156,39 @@ const Login: React.FC<LoginProps> = ({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) { Alert.alert(ERROR_INVALID_LOGIN); } + } 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 + */ + 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, |
