aboutsummaryrefslogtreecommitdiff
path: root/src/screens/onboarding
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-03-19 18:10:41 -0400
committerGitHub <noreply@github.com>2021-03-19 18:10:41 -0400
commitec7aa3cacd5c613e0d6ff589274ac58ce62bd6a8 (patch)
tree18d6061d24b34df136cfb7d7a4e3f61580b82b7d /src/screens/onboarding
parentf8a2634372eb7bda871a11cd14aca758782a1d2e (diff)
parent8013dd29f447990f95cc4ad9557238fc825bcc54 (diff)
Merge pull request #309 from IvanIFChen/tma707-login-after-invitation-code
[TMA-707] Login directly after entering correct invitation code
Diffstat (limited to 'src/screens/onboarding')
-rw-r--r--src/screens/onboarding/InvitationCodeVerification.tsx14
-rw-r--r--src/screens/onboarding/Login.tsx1
-rw-r--r--src/screens/onboarding/OnboardingStepThree.tsx4
3 files changed, 12 insertions, 7 deletions
diff --git a/src/screens/onboarding/InvitationCodeVerification.tsx b/src/screens/onboarding/InvitationCodeVerification.tsx
index 41d17f29..7cd4b3bf 100644
--- a/src/screens/onboarding/InvitationCodeVerification.tsx
+++ b/src/screens/onboarding/InvitationCodeVerification.tsx
@@ -1,3 +1,4 @@
+import AsyncStorage from '@react-native-community/async-storage';
import {RouteProp} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
import React from 'react';
@@ -9,6 +10,7 @@ import {
useBlurOnFulfill,
useClearByFocusCell,
} from 'react-native-confirmation-code-field';
+import {useDispatch} from 'react-redux';
import {
ArrowButton,
Background,
@@ -25,7 +27,7 @@ import {
} from '../../constants/strings';
import {OnboardingStackParams} from '../../routes';
import {BackgroundGradientType} from '../../types';
-import {SCREEN_WIDTH} from '../../utils';
+import {SCREEN_WIDTH, userLogin} from '../../utils';
type InvitationCodeVerificationRouteProp = RouteProp<
OnboardingStackParams,
@@ -56,6 +58,7 @@ const InvitationCodeVerification: React.FC<InvitationCodeVerificationProps> = ({
value,
setValue,
});
+ const dispatch = useDispatch();
const handleInvitationCodeVerification = async () => {
if (value.length === 6) {
@@ -71,10 +74,11 @@ const InvitationCodeVerification: React.FC<InvitationCodeVerificationProps> = ({
);
if (verifyInviteCodeResponse.status === 200) {
- navigation.navigate('Login');
- setTimeout(() => {
- Alert.alert(SUCCESS_INVITATION_CODE);
- }, 500);
+ const userId = route.params.userId;
+ const username = route.params.username;
+ await AsyncStorage.setItem('userId', userId);
+ await AsyncStorage.setItem('username', username);
+ userLogin(dispatch, {userId, username});
} else {
Alert.alert(ERROR_INVALID_INVITATION_CODE);
}
diff --git a/src/screens/onboarding/Login.tsx b/src/screens/onboarding/Login.tsx
index cfa39dbd..6d9d3a97 100644
--- a/src/screens/onboarding/Login.tsx
+++ b/src/screens/onboarding/Login.tsx
@@ -170,6 +170,7 @@ const Login: React.FC<LoginProps> = ({navigation}: LoginProps) => {
} else if (statusCode === 200 && !data.isOnboarded) {
navigation.navigate('InvitationCodeVerification', {
userId: data.UserID,
+ username: username,
});
setTimeout(() => {
Alert.alert(ERROR_NOT_ONBOARDED);
diff --git a/src/screens/onboarding/OnboardingStepThree.tsx b/src/screens/onboarding/OnboardingStepThree.tsx
index 64a2a2f7..f22d720f 100644
--- a/src/screens/onboarding/OnboardingStepThree.tsx
+++ b/src/screens/onboarding/OnboardingStepThree.tsx
@@ -57,7 +57,7 @@ const OnboardingStepThree: React.FC<OnboardingStepThreeProps> = ({
route,
navigation,
}) => {
- const {userId} = route.params;
+ const {userId, username} = route.params;
let emptyDate: string | undefined;
const [form, setForm] = React.useState({
smallPic: '',
@@ -224,12 +224,12 @@ const OnboardingStepThree: React.FC<OnboardingStepThreeProps> = ({
},
body: request,
});
- console.log(route.params.userId);
let statusCode = response.status;
let data = await response.json();
if (statusCode === 200) {
navigation.navigate('InvitationCodeVerification', {
userId: route.params.userId,
+ username: username,
});
} else if (statusCode === 400) {
Alert.alert(