Skip to content

Commit

Permalink
Merge branch 'master' into fix/cgne2etests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vangaorth authored Jan 24, 2024
2 parents d61975d + 3eb1b82 commit 4f18017
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions ts/screens/profile/CduEmailInsertScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const CduEmailInsertScreen = (props: Props) => {
),
[areSameEmails, email]
);
const isContinueButtonDisabled = !isValidEmail() && !isLoading;

const continueOnPress = () => {
Keyboard.dismiss();
Expand All @@ -191,7 +192,7 @@ const CduEmailInsertScreen = (props: Props) => {

const renderFooterButtons = () => {
const continueButtonProps = {
disabled: !isValidEmail() && !isLoading,
disabled: isContinueButtonDisabled,
onPress: continueOnPress,
label: I18n.t("global.buttons.continue"),
accessibilityLabel: I18n.t("global.buttons.continue"),
Expand All @@ -211,7 +212,25 @@ const CduEmailInsertScreen = (props: Props) => {
};

const handleOnChangeEmailText = (value: string) => {
setAreSameEmails(areStringsEqual(O.some(value), optionEmail, true));
/**
* SCENARIOS:
* 1. first onboarding and email already taken => if the CIT writes
* the same email as the one he has to modify, he is blocked.
* 2. first onboarding and NOT email already taken => in this case,
* the CIT does not need his email to be compared with another one,
* so the areSameEmails will always be false.
* 3. Not first onboarding => if the CIT write the same email as the one
* he already has, he is blocked.
*/
if (isFirstOnBoarding) {
setAreSameEmails(
isProfileEmailAlreadyTaken
? areStringsEqual(O.some(value), optionEmail, true)
: false
);
} else {
setAreSameEmails(areStringsEqual(O.some(value), optionEmail, true));
}
setEmail(value !== EMPTY_EMAIL ? O.some(value) : O.none);
};

Expand All @@ -220,10 +239,12 @@ const CduEmailInsertScreen = (props: Props) => {
props.navigation.goBack();
}, [props.navigation]);

useEffect(() => {
setAreSameEmails(false);
setEmail(O.some(EMPTY_EMAIL));
}, []);
useOnFirstRender(() => {
if (!isFirstOnBoarding) {
setEmail(O.some(EMPTY_EMAIL));
setAreSameEmails(false);
}
});

// If we navigate to this screen with acknowledgeOnEmailValidated set to false,
// we show the modal to remind the user to validate the email.
Expand Down Expand Up @@ -367,7 +388,11 @@ const CduEmailInsertScreen = (props: Props) => {
}
inputProps={{
returnKeyType: "done",
onSubmitEditing: continueOnPress,
// continueOnPress is called by pressing the
// button on the keyboard only if the mail is valid
onSubmitEditing: isContinueButtonDisabled
? undefined
: continueOnPress,
autoCapitalize: "none",
keyboardType: "email-address",
defaultValue: pipe(
Expand Down

0 comments on commit 4f18017

Please sign in to comment.