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