From e86478f52e191c52fea20980278174af46f50953 Mon Sep 17 00:00:00 2001 From: Ashm Walia <40498934+ashmgarv@users.noreply.github.com> Date: Tue, 6 Oct 2020 22:06:06 -0700 Subject: TMA 207 : Updated the Onboarding Process (#42) --- src/routes/onboarding/Onboarding.tsx | 5 + src/routes/onboarding/OnboardingStack.tsx | 7 +- src/screens/onboarding/Checkpoint.tsx | 6 +- src/screens/onboarding/RegistrationOne.tsx | 160 +++++------- src/screens/onboarding/RegistrationThree.tsx | 362 +++++++++++++++++++++++++++ src/screens/onboarding/RegistrationTwo.tsx | 260 +++++-------------- src/screens/onboarding/Verification.tsx | 47 +++- src/screens/onboarding/index.ts | 1 + 8 files changed, 529 insertions(+), 319 deletions(-) create mode 100644 src/screens/onboarding/RegistrationThree.tsx (limited to 'src') diff --git a/src/routes/onboarding/Onboarding.tsx b/src/routes/onboarding/Onboarding.tsx index b14bd85c..7b2eb85d 100644 --- a/src/routes/onboarding/Onboarding.tsx +++ b/src/routes/onboarding/Onboarding.tsx @@ -4,6 +4,7 @@ import { Login, RegistrationOne, RegistrationTwo, + RegistrationThree, Verification, ProfileOnboarding, Checkpoint, @@ -39,6 +40,10 @@ const Onboarding: React.FC = () => { name="RegistrationTwo" component={RegistrationTwo} /> + = ({route, navigation}) => { @@ -50,10 +50,10 @@ const Checkpoint: React.FC = ({route, navigation}) => { return ( - + - Email verified! + You are registered! We're almost there. Would you like to setup your profile now? diff --git a/src/screens/onboarding/RegistrationOne.tsx b/src/screens/onboarding/RegistrationOne.tsx index 720fcaed..9e9cabf5 100644 --- a/src/screens/onboarding/RegistrationOne.tsx +++ b/src/screens/onboarding/RegistrationOne.tsx @@ -10,16 +10,23 @@ import { Platform, TouchableOpacity, KeyboardAvoidingView, + ActivityIndicator, } from 'react-native'; import {OnboardingStackParams} from '../../routes'; + import { ArrowButton, RegistrationWizard, TaggInput, Background, } from '../../components'; -import {nameRegex, emailRegex} from '../../constants'; + +import {usePromiseTracker, trackPromise} from 'react-promise-tracker'; + +import {SEND_OTP_ENDPOINT} from '../../constants'; + +import {emailRegex} from '../../constants'; type RegistrationScreenOneRouteProp = RouteProp< OnboardingStackParams, @@ -34,66 +41,20 @@ interface RegistrationOneProps { navigation: RegistrationScreenOneNavigationProp; } /** - * Registration screen 1 for First Name, Last Name, and email + * Registration screen 1 for Email * @param navigation react-navigation navigation object */ const RegistrationOne: React.FC = ({navigation}) => { - // refs for changing focus - const lnameRef = useRef(); + // // refs for changing focus const emailRef = useRef(); - /** - * Handles focus change to the next input field. - * @param field key for field to move focus onto - */ - const handleFocusChange = (field: string): void => { - switch (field) { - case 'lname': - const lnameField: any = lnameRef.current; - lnameField.focus(); - break; - case 'email': - const emailField: any = emailRef.current; - emailField.focus(); - break; - default: - return; - } - }; // registration form state const [form, setForm] = useState({ - fname: '', - lname: '', email: '', - isValidFname: false, - isValidLname: false, isValidEmail: false, attemptedSubmit: false, }); - /* - * Handles changes to the first name field value and verifies the input by updating state and running a validation function. - */ - const handleFnameUpdate = (fname: string) => { - let isValidFname: boolean = nameRegex.test(fname); - setForm({ - ...form, - fname, - isValidFname, - }); - }; - /* - * Handles changes to the last name field value and verifies the input by updating state and running a validation function. - */ - const handleLnameUpdate = (lname: string) => { - let isValidLname: boolean = nameRegex.test(lname); - setForm({ - ...form, - lname, - isValidLname, - }); - }; - /* * Handles changes to the email field value and verifies the input by updating state and running a validation function. */ @@ -107,9 +68,9 @@ const RegistrationOne: React.FC = ({navigation}) => { }; /** - * Handles a click on the "next" arrow button by navigating to RegistrationTwo if First Name and Last Name are filled + * Handles a click on the "next" arrow button by navigating to Verification if email is filled correctly */ - const goToRegisterTwo = async () => { + const goToVerification = async () => { if (!form.attemptedSubmit) { setForm({ ...form, @@ -117,12 +78,30 @@ const RegistrationOne: React.FC = ({navigation}) => { }); } try { - if (form.isValidFname && form.isValidLname && form.isValidEmail) { - navigation.navigate('RegistrationTwo', { - firstName: form.fname, - lastName: form.lname, - email: form.email, - }); + if (form.isValidEmail) { + let sendOtpResponse = await trackPromise( + fetch(SEND_OTP_ENDPOINT, { + method: 'POST', + body: JSON.stringify({ + email: form.email, + }), + }), + ); + let otpStatusCode = sendOtpResponse.status; + if (otpStatusCode === 200) { + navigation.navigate('Verification', { + email: form.email, + }); + } else if (otpStatusCode === 409) { + Alert.alert( + 'This email is already registered with us, please use another email.', + ); + } else { + Alert.alert( + "Looks like Our email servers might be down πŸ˜“'", + "Try again in a couple minutes. We're sorry for the inconvenience.", + ); + } } else { setForm({...form, attemptedSubmit: false}); setTimeout(() => setForm({...form, attemptedSubmit: true})); @@ -133,7 +112,7 @@ const RegistrationOne: React.FC = ({navigation}) => { "Try again in a couple minutes. We're sorry for the inconvenience.", ); return { - name: 'Registration error', + name: 'Send OTP error', description: error, }; } @@ -145,24 +124,28 @@ const RegistrationOne: React.FC = ({navigation}) => { direction="backward" onPress={() => navigation.navigate('Login')} /> - + - navigation.navigate('RegistrationTwo', { - firstName: form.fname, - lastName: form.lname, - email: form.email, - }) - } + disabled={!form.isValidEmail} + onPress={goToVerification} /> ); + /** + * An activity indicator to indicate that the app is working during the send_otp request. + */ + const LoadingIndicator = () => { + const {promiseInProgress} = usePromiseTracker(); + return promiseInProgress ? ( + + ) : ( + <> + ); + }; + return ( @@ -171,39 +154,8 @@ const RegistrationOne: React.FC = ({navigation}) => { behavior={Platform.OS === 'ios' ? 'padding' : 'height'} style={styles.container}> - SIGN UP + ENTER EMAIL - handleFocusChange('lname')} - blurOnSubmit={false} - valid={form.isValidFname} - invalidWarning="Please enter a valid first name." - attemptedSubmit={form.attemptedSubmit} - width={280} - /> - handleFocusChange('email')} - blurOnSubmit={false} - ref={lnameRef} - valid={form.isValidLname} - invalidWarning="Please enter a valid last name." - attemptedSubmit={form.attemptedSubmit} - width={280} - /> = ({navigation}) => { invalidWarning={'Please enter a valid email address.'} attemptedSubmit={form.attemptedSubmit} width={280} - onSubmitEditing={goToRegisterTwo} + onSubmitEditing={goToVerification} /> +