Skip to content

Commit

Permalink
fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladirico committed Jan 23, 2024
1 parent 9634f37 commit 541d35d
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 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 isButtonDisabled = !isValidEmail() && !isLoading;

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

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

const handleOnChangeEmailText = (value: string) => {
setAreSameEmails(areStringsEqual(O.some(value), optionEmail, true));
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 +229,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 +378,9 @@ const CduEmailInsertScreen = (props: Props) => {
}
inputProps={{
returnKeyType: "done",
onSubmitEditing: continueOnPress,
onSubmitEditing: isButtonDisabled
? undefined
: continueOnPress,
autoCapitalize: "none",
keyboardType: "email-address",
defaultValue: pipe(
Expand Down

0 comments on commit 541d35d

Please sign in to comment.