From 8024accd32811d45f2220c79f274d547e0c4c773 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 15 Apr 2021 17:22:22 -0400 Subject: cleaned up Verification to be PasswordVerification --- .../onboarding/InvitationCodeVerification.tsx | 13 +- src/screens/onboarding/PasswordResetRequest.tsx | 3 +- src/screens/onboarding/PasswordVerification.tsx | 220 ++++++++++++++++ src/screens/onboarding/Verification.tsx | 281 --------------------- src/screens/onboarding/index.ts | 2 +- 5 files changed, 223 insertions(+), 296 deletions(-) create mode 100644 src/screens/onboarding/PasswordVerification.tsx delete mode 100644 src/screens/onboarding/Verification.tsx (limited to 'src/screens') diff --git a/src/screens/onboarding/InvitationCodeVerification.tsx b/src/screens/onboarding/InvitationCodeVerification.tsx index 6bc0ac9d..d84b2ba2 100644 --- a/src/screens/onboarding/InvitationCodeVerification.tsx +++ b/src/screens/onboarding/InvitationCodeVerification.tsx @@ -1,7 +1,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; -import React, {useContext} from 'react'; +import React from 'react'; import {Alert, KeyboardAvoidingView, StyleSheet, View} from 'react-native'; import {Text} from 'react-native-animatable'; import { @@ -27,7 +27,6 @@ import { import {OnboardingStackParams} from '../../routes'; import {BackgroundGradientType} from '../../types'; import {SCREEN_WIDTH, userLogin} from '../../utils'; -import {ChatContext} from '../../App'; type InvitationCodeVerificationRouteProp = RouteProp< OnboardingStackParams, @@ -59,7 +58,6 @@ const InvitationCodeVerification: React.FC = ({ setValue, }); const dispatch = useDispatch(); - const {chatClient} = useContext(ChatContext); const handleInvitationCodeVerification = async () => { if (value.length === 6) { @@ -200,10 +198,6 @@ const styles = StyleSheet.create({ flexDirection: 'row', justifyContent: 'space-around', }, - noInviteCode: { - flexDirection: 'row', - justifyContent: 'center', - }, youveBeenAddedLabel: { marginVertical: '5%', width: SCREEN_WIDTH * 0.8, @@ -213,11 +207,6 @@ const styles = StyleSheet.create({ fontWeight: '500', marginBottom: '10%', }, - inviteCodeLink: { - color: 'white', - fontSize: 18, - textDecorationLine: 'underline', - }, }); export default InvitationCodeVerification; diff --git a/src/screens/onboarding/PasswordResetRequest.tsx b/src/screens/onboarding/PasswordResetRequest.tsx index a63eae81..8a891bbb 100644 --- a/src/screens/onboarding/PasswordResetRequest.tsx +++ b/src/screens/onboarding/PasswordResetRequest.tsx @@ -74,9 +74,8 @@ const PasswordResetRequest: React.FC = ({ handlePasswordResetRequest(form.value), ); if (success) { - navigation.navigate('Verification', { + navigation.navigate('PasswordVerification', { id: form.value, - screenType: VerificationScreenType.Password, }); } } else { diff --git a/src/screens/onboarding/PasswordVerification.tsx b/src/screens/onboarding/PasswordVerification.tsx new file mode 100644 index 00000000..6bda37a7 --- /dev/null +++ b/src/screens/onboarding/PasswordVerification.tsx @@ -0,0 +1,220 @@ +import {RouteProp} from '@react-navigation/native'; +import {StackNavigationProp} from '@react-navigation/stack'; +import React from 'react'; +import { + Alert, + KeyboardAvoidingView, + Platform, + StyleSheet, + TouchableOpacity, + View, +} from 'react-native'; +import {Text} from 'react-native-animatable'; +import { + CodeField, + Cursor, + useBlurOnFulfill, + useClearByFocusCell, +} from 'react-native-confirmation-code-field'; +import {trackPromise} from 'react-promise-tracker'; +import { + ArrowButton, + Background, + LoadingIndicator, + SubmitButton, +} from '../../components'; +import {codeRegex} from '../../constants'; +import { + ERROR_INVALID_VERIFICATION_CODE_FORMAT, + ERROR_SOMETHING_WENT_WRONG, +} from '../../constants/strings'; +import {OnboardingStackParams} from '../../routes'; +import { + handlePasswordCodeVerification, + handlePasswordResetRequest, +} from '../../services'; +import {BackgroundGradientType} from '../../types'; + +type VerificationScreenRouteProp = RouteProp< + OnboardingStackParams, + 'PasswordVerification' +>; +type VerificationScreenNavigationProp = StackNavigationProp< + OnboardingStackParams, + 'PasswordVerification' +>; +interface VerificationProps { + route: VerificationScreenRouteProp; + navigation: VerificationScreenNavigationProp; +} + +const Verification: React.FC = ({route, navigation}) => { + const [value, setValue] = React.useState(''); + const ref = useBlurOnFulfill({value, cellCount: 6}); + const [valueProps, getCellOnLayoutHandler] = useClearByFocusCell({ + value, + setValue, + }); + const {id} = route.params; + + const handleVerification = async () => { + if (codeRegex.test(value)) { + try { + const success = await trackPromise( + handlePasswordCodeVerification(id, value), + ); + if (success) { + navigation.navigate('PasswordReset', {value: id}); + } + } catch (error) { + console.log(error); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); + } + } else { + Alert.alert(ERROR_INVALID_VERIFICATION_CODE_FORMAT); + } + }; + + /** + * Sends the send_otp request so to provide a new verification code upon tapping the Resend Code button. + */ + const handleResend = async () => { + try { + trackPromise(handlePasswordResetRequest(id)); + } catch (error) { + console.log(error); + Alert.alert(ERROR_SOMETHING_WENT_WRONG); + } + }; + + const Footer = () => ( + + navigation.navigate('PasswordResetRequest')} + /> + + ); + + return ( + + + Enter 6 digit code + + We sent a 6 digit verification code to the phone number you provided. + + ( + + + {symbol || (isFocused ? : null)} + + + )} + /> + + + Resend Code + + + +