From 2bd196c6165cbf45544dbc0a021daf5d313fde3c Mon Sep 17 00:00:00 2001 From: Ashm Walia <40498934+ashmgarv@users.noreply.github.com> Date: Tue, 13 Oct 2020 13:13:45 -0700 Subject: [TMA-238] (Small change) Do not skip invitation code verification (#54) * Do not skip invitation code verification * Check code length before calling the backend API * Nitpick --- src/constants/api.ts | 4 +- .../onboarding/InvitationCodeVerification.tsx | 61 ++++++++++------------ 2 files changed, 30 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/constants/api.ts b/src/constants/api.ts index 86b941d0..fa8cd0b3 100644 --- a/src/constants/api.ts +++ b/src/constants/api.ts @@ -12,6 +12,4 @@ export const COVER_PHOTO_ENDPOINT: string = API_URL + 'large-profile-pic/'; export const AVATAR_PHOTO_ENDPOINT: string = API_URL + 'small-profile-pic/'; export const GET_IG_POSTS_ENDPOINT: string = API_URL + 'posts-ig/'; export const SEARCH_ENDPOINT: string = API_URL + 'search/'; - -//TODO add an endpoint to verify the invitation code, such as below -//export const VERIFY_INVITATION_CODE_ENDPOUNT: string = API_URL + 'verify_invitation_code/'; +export const VERIFY_INVITATION_CODE_ENDPOUNT: string = API_URL + 'verify-code/'; diff --git a/src/screens/onboarding/InvitationCodeVerification.tsx b/src/screens/onboarding/InvitationCodeVerification.tsx index ae1c282f..9af288b4 100644 --- a/src/screens/onboarding/InvitationCodeVerification.tsx +++ b/src/screens/onboarding/InvitationCodeVerification.tsx @@ -10,8 +10,7 @@ import { LoadingIndicator, } from '../../components'; -//TODO : -//import {VERIFY_INVITATION_CODE_ENDPOUNT} from "../../constants" +import {VERIFY_INVITATION_CODE_ENDPOUNT} from "../../constants" import {Text} from 'react-native-animatable'; import { @@ -54,35 +53,33 @@ const InvitationCodeVerification: React.FC = ({ }); const handleInvitationCodeVerification = async () => { - //TODO : Verify the code - //The code would look somewhat like below - // try { - // let verifyInviteCodeResponse = await fetch(VERIFY_INVITATION_CODE_ENDPOUNT, { - // method: 'POST', - // body: JSON.stringify({ - // otp: value, - // }), - // }); + if(value.length == 6){ + try { + let verifyInviteCodeResponse = await fetch(VERIFY_INVITATION_CODE_ENDPOUNT + value + '/', { + method: 'DELETE', + }); - // if (verifyInviteCodeResponse.status == 200) { - // navigation.navigate('RegistrationOne'); - // } else { - // Alert.alert( - // 'Invalid invitation code 🤔', - // ); - // } - // } catch (error) { - // Alert.alert( - // 'Verifiation failed 😓', - // 'Please double-check your network connection and retry.', - // ); - // return { - // name: 'Verification error', - // description: error, - // }; - // } - - navigation.navigate('RegistrationOne'); + if (verifyInviteCodeResponse.status == 200) { + navigation.navigate('RegistrationOne'); + } else { + Alert.alert( + 'Invalid invitation code 🤔', + ); + } + } catch (error) { + Alert.alert( + 'Verifiation failed 😓', + 'Please double-check your network connection and retry.', + ); + return { + name: 'Verification error', + description: error, + }; + } + } + else{ + Alert.alert("The code entered is not valid!"); + } }; const Footer = () => ( @@ -98,9 +95,9 @@ const InvitationCodeVerification: React.FC = ({ - Enter 6 digit code + Enter the code - Please enter the invitation code provided to you by us / your friend. + Please enter the invitation code provided to you by us / your friend. (Use all caps.)