aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Rusu <george@tagg.id>2021-05-10 16:06:41 -0700
committerGeorge Rusu <george@tagg.id>2021-05-10 16:06:41 -0700
commit4859c58b1d6bebc7f8a1b4e7345393a1dfdc33d8 (patch)
treee0f85498283984305082051d6f6e14482d6346ec /src
parent51d940e5d90d1f3ef0e94eeeb065a681d68d4973 (diff)
updating state to check taken email/usernames
Diffstat (limited to 'src')
-rw-r--r--src/constants/api.ts1
-rw-r--r--src/screens/onboarding/BasicInfoOnboarding.tsx29
-rw-r--r--src/services/UserProfileService.ts27
3 files changed, 54 insertions, 3 deletions
diff --git a/src/constants/api.ts b/src/constants/api.ts
index 45b6e8ae..53392fb5 100644
--- a/src/constants/api.ts
+++ b/src/constants/api.ts
@@ -12,6 +12,7 @@ const API_URL: string = BASE_URL + 'api/';
export const LOGIN_ENDPOINT: string = API_URL + 'login/';
export const VERSION_ENDPOINT: string = API_URL + 'version/v2/';
export const REGISTER_ENDPOINT: string = API_URL + 'register/';
+export const REGISTER_VALIDATE_ENDPOINT: string = API_URL + 'register/validate/';
export const EDIT_PROFILE_ENDPOINT: string = API_URL + 'edit-profile/';
export const SEND_OTP_ENDPOINT: string = API_URL + 'send-otp/';
export const VERIFY_OTP_ENDPOINT: string = API_URL + 'verify-otp/';
diff --git a/src/screens/onboarding/BasicInfoOnboarding.tsx b/src/screens/onboarding/BasicInfoOnboarding.tsx
index 8ddb74e1..2bfe449c 100644
--- a/src/screens/onboarding/BasicInfoOnboarding.tsx
+++ b/src/screens/onboarding/BasicInfoOnboarding.tsx
@@ -2,6 +2,7 @@ import AsyncStorage from '@react-native-community/async-storage';
import {useNavigation} from '@react-navigation/core';
import {RouteProp} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
+import { invalid } from 'moment';
import React, {useEffect, useState} from 'react';
import {
Alert,
@@ -38,7 +39,7 @@ import {
ERROR_T_AND_C_NOT_ACCEPTED,
} from '../../constants/strings';
import {OnboardingStackParams} from '../../routes';
-import {sendOtpStatusCode, sendRegister} from '../../services';
+import {sendOtpStatusCode, sendRegister, verifyExistingInformation} from '../../services';
import {BackgroundGradientType} from '../../types';
import {HeaderHeight, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils';
@@ -63,12 +64,18 @@ const BasicInfoOnboarding: React.FC<BasicInfoOnboardingProps> = ({route}) => {
const [currentStep, setCurrentStep] = useState(0);
const [tcAccepted, setTCAccepted] = useState(false);
const [passVisibility, setPassVisibility] = useState(false);
+ const [invalidWithError, setInvalidWithError] = useState("Please enter a valid ")
const [autoCapitalize, setAutoCap] = useState<
'none' | 'sentences' | 'words' | 'characters' | undefined
>('none');
const [fadeValue, setFadeValue] = useState<Animated.Value<number>>(
new Animated.Value(0),
);
+ useEffect(() => {
+ console.log(invalidWithError)
+ setValid(false);
+ }, [invalidWithError])
+
const fadeButtonValue = useValue<number>(0);
const [form, setForm] = useState({
fname: '',
@@ -91,6 +98,7 @@ const BasicInfoOnboarding: React.FC<BasicInfoOnboardingProps> = ({route}) => {
}).start();
};
+
useEffect(() => {
const fade = async () => {
Animated.timing(fadeValue, {
@@ -284,9 +292,24 @@ const BasicInfoOnboarding: React.FC<BasicInfoOnboardingProps> = ({route}) => {
}
};
const step = formSteps[currentStep];
- const advance = () => {
+ useEffect(() => {
+ if(step.placeholder!== 'School Email') {
+ setInvalidWithError("Please enter a valid " + step.placeholder.toLowerCase())
+ }
+ }, [step])
+ const advance = async() => {
setAttemptedSubmit(true);
if (valid) {
+ if (step.placeholder === 'School Email') {
+ const verifiedInfo = await verifyExistingInformation(form.email, undefined);
+ if(!verifiedInfo) {
+ console.log("here");
+ setInvalidWithError("Email is taken")
+ return;
+ }
+ }
+ console.log('shouldnt happen')
+ console.log("stepL: " + step.placeholder)
setCurrentStep(currentStep + 1);
setAttemptedSubmit(false);
setValid(false);
@@ -436,7 +459,7 @@ const BasicInfoOnboarding: React.FC<BasicInfoOnboardingProps> = ({route}) => {
warning: styles.passWarning,
}}
valid={valid}
- invalidWarning={`Please enter a valid ${step.placeholder.toLowerCase()}`}
+ invalidWarning={invalidWithError}
attemptedSubmit={attemptedSubmit}
/>
<Animated.View style={{opacity: fadeButtonValue}}>
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts
index c11d874f..8b7b78e1 100644
--- a/src/services/UserProfileService.ts
+++ b/src/services/UserProfileService.ts
@@ -11,6 +11,7 @@ import {
PROFILE_INFO_ENDPOINT,
PROFILE_PHOTO_ENDPOINT,
REGISTER_ENDPOINT,
+ REGISTER_VALIDATE_ENDPOINT,
SEND_OTP_ENDPOINT,
TAGG_CUSTOMER_SUPPORT,
USER_PROFILE_ENDPOINT,
@@ -432,3 +433,29 @@ export const visitedUserProfile = async (userId: string) => {
return undefined;
}
};
+
+export const verifyExistingInformation = async (
+ email: string | undefined,
+ username: string | undefined,
+) => {
+ try {
+ const form = new FormData();
+ if (email) {
+ form.append('email', email);
+ }
+ if (username) {
+ form.append('username', username);
+ }
+ const response = await fetch(REGISTER_VALIDATE_ENDPOINT, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'multipart/form-data',
+ },
+ body: form,
+ });
+ return response.status===200;
+ } catch (error) {
+ console.log(error);
+ return false;
+ }
+};