Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Onboarding check if email exists (#354)
Browse files Browse the repository at this point in the history
* WIP : Add api road

* feat : check if emails exists on subscribe

* fix reviews

* Fix reviews
  • Loading branch information
AndreasCottet authored Dec 11, 2022
1 parent 1b7b879 commit 12346cf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/screens/Onboarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,37 @@ export default function Onboarding({ navigation }) {
}
};

const checkEmailAvailable = async () => {
setLoading(true);
try {
const response = await API.checkEmailAvailable(email);
setLoading(false);
if (!response.data)
emailInputRef.current?.setInvalid('An account already exists with this email');
return response.data;
} catch (error) {
setLoading(false);
console.error('Error while checking if an email is available', email, error);
}
};

const validationEmailAndPasswordRegister = async () => {
const emailValid = emailInputRef.current?.isValid() && await checkEmailAvailable(email);
const passwordValid = passwordInputRef.current?.isValid();
const passwordConfirmationValid = passwordConfirmationInputRef.current?.isValid();
const inputsValid = emailValid && passwordValid && passwordConfirmationValid;
const samePasswords = passwordInputRef.current?.getValue() === passwordConfirmationInputRef.current?.getValue();
if (inputsValid && !samePasswords) {
passwordInputRef.current?.setInvalid('Passwords does not match');
passwordConfirmationInputRef.current?.setInvalid('Passwords does not match');
}
const everythingValid = inputsValid && samePasswords;
everythingValid && viewSliderRef.current?.goToView(5);
everythingValid && Keyboard.dismiss();
};

const handleLogin = async () => {
const emailValid = loginEmailInputRef.current?.isValid();

if (!emailValid) {
console.log('email not valid');
return;
Expand Down Expand Up @@ -491,20 +519,7 @@ export default function Onboarding({ navigation }) {
</View>
<LoadingGlassButton
loading={loading}
onPress={() => {
const emailValid = emailInputRef.current?.isValid();
const passwordValid = passwordInputRef.current?.isValid();
const passwordConfirmationValid = passwordConfirmationInputRef.current?.isValid();
const inputsValid = emailValid && passwordValid && passwordConfirmationValid;
const samePasswords = passwordInputRef.current?.getValue() === passwordConfirmationInputRef.current?.getValue();
if (inputsValid && !samePasswords) {
passwordInputRef.current?.setInvalid('Passwords does not match');
passwordConfirmationInputRef.current?.setInvalid('Passwords does not match');
}
const everythingValid = inputsValid && samePasswords;
everythingValid && viewSliderRef.current?.goToView(5);
everythingValid && Keyboard.dismiss();
}}
onPress={validationEmailAndPasswordRegister}
disabled={email === '' || password === '' || passwordConfirmation === ''}
/>
</View>
Expand Down
6 changes: 6 additions & 0 deletions src/services/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ const postNotificationsSettings = async (notificationsSettings) => {
return response;
};

const checkEmailAvailable = async (email) => {
const response = await axios.get(`/emailAvailable/${email}`);
return response;
};

const API = {
getHeaders,
register,
Expand Down Expand Up @@ -240,6 +245,7 @@ const API = {
postNotificationsSettings,
init,
deleteAccount,
checkEmailAvailable,
};

export default API;

0 comments on commit 12346cf

Please sign in to comment.