Skip to content

Commit 2539139

Browse files
authored
Amina/email pop (#18008)
* fix: add addditional dropdown options for account opening reason * fix: email_pop * fix: type * fix: style * fix: style
1 parent 62c3bfc commit 2539139

File tree

3 files changed

+75
-17
lines changed

3 files changed

+75
-17
lines changed

packages/account/src/Sections/Security/Passwords/__tests__/deriv-email.spec.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,18 @@ describe('DerivEmail', () => {
5757
expect(el_button).not.toBeInTheDocument();
5858
});
5959

60-
it('should not display unlink account modal when not associated with social media', async () => {
61-
renderComponent({});
62-
const el_button = screen.getByRole('button', { name: /Change email/i });
63-
userEvent.click(el_button);
64-
let el_modal;
65-
await waitFor(() => {
66-
el_modal = screen.getByText('We’ve sent you an email');
67-
});
68-
expect(el_modal).toBeInTheDocument();
69-
});
70-
7160
it('should display unlink account modal when button is clicked', async () => {
7261
const store_config = mockStore({ client: { social_identity_provider: 'Google', is_social_signup: true } });
7362
renderComponent({ store_config });
7463
const el_button = screen.getByRole('button', { name: /Change email/i });
75-
userEvent.click(el_button);
64+
await userEvent.click(el_button);
7665
let el_modal;
7766
await waitFor(() => {
7867
el_modal = screen.getByText('Change your login email');
7968
expect(el_modal).toBeInTheDocument();
8069
});
8170
const el_unlink_btn = screen.getByRole('button', { name: /Unlink from Google/i });
82-
userEvent.click(el_unlink_btn);
71+
await userEvent.click(el_unlink_btn);
8372

8473
await waitFor(() => {
8574
el_modal = screen.getByText('We’ve sent you an email');

packages/account/src/Sections/Security/Passwords/deriv-email.tsx

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { Fragment, useState } from 'react';
2-
import { Text } from '@deriv/components';
1+
import { Fragment, useEffect, useState } from 'react';
2+
33
import { useVerifyEmail } from '@deriv/api';
4+
import { Button, Modal, Text } from '@deriv/components';
45
import { toTitleCase } from '@deriv/shared';
56
import { observer, useStore } from '@deriv/stores';
67
import { Localize, useTranslations } from '@deriv-com/translations';
8+
79
import SentEmailModal from '../../../Components/sent-email-modal';
810
import UnlinkAccountModal from '../../../Components/unlink-account-modal';
11+
912
import EmailPasswordSection from './email-password-section';
1013

1114
type TVerifyEmailPayload = Parameters<ReturnType<typeof useVerifyEmail>['mutate']>[0];
@@ -20,19 +23,29 @@ const DerivEmail = observer(() => {
2023
common: { is_from_derivgo },
2124
client: { social_identity_provider, is_social_signup, email },
2225
} = useStore();
23-
const { mutate } = useVerifyEmail();
26+
27+
const { mutate, isError, error, isSuccess } = useVerifyEmail();
2428
const { localize } = useTranslations();
2529
const [is_unlink_account_modal_open, setIsUnlinkAccountModalOpen] = useState(false);
2630
const [is_send_email_modal_open, setIsSendEmailModalOpen] = useState(false);
31+
const [is_error_modal_open, setIsErrorModalOpen] = useState(false);
2732

2833
const payload: TVerifyEmailPayload = { verify_email: email, type: 'request_email' };
2934

35+
useEffect(() => {
36+
if (isError) {
37+
setIsErrorModalOpen(true);
38+
setIsSendEmailModalOpen(false);
39+
} else if (isSuccess) {
40+
setIsSendEmailModalOpen(true);
41+
}
42+
}, [isError, isSuccess]);
43+
3044
const onClickChangeEmail = () => {
3145
if (is_social_signup) {
3246
setIsUnlinkAccountModalOpen(true);
3347
} else {
3448
mutate(payload);
35-
setIsSendEmailModalOpen(true);
3649
}
3750
};
3851

@@ -42,6 +55,15 @@ const DerivEmail = observer(() => {
4255
setIsSendEmailModalOpen(true);
4356
};
4457

58+
const onClose = () => {
59+
setIsErrorModalOpen(false);
60+
};
61+
62+
type VerifyEmailError = {
63+
code?: string;
64+
message?: string;
65+
};
66+
4567
return (
4668
<Fragment>
4769
<div className='account__passwords-wrapper'>
@@ -74,6 +96,31 @@ const DerivEmail = observer(() => {
7496
is_modal_when_mobile={true}
7597
/>
7698
</div>
99+
{is_error_modal_open && error && (
100+
<Modal
101+
is_open={is_error_modal_open}
102+
has_close_icon
103+
should_header_stick_body
104+
title={localize('Email change currently unavailable')}
105+
toggleModal={onClose}
106+
width='440px'
107+
height='200px'
108+
>
109+
<div className='account__email-unhandled-error'>
110+
<Text className='account__email-unhandled-error-error_text' as='p' size='xs'>
111+
{(error as VerifyEmailError)?.code === 'EmailChangeFailP2PActive' ? (
112+
<Localize i18n_default_text='Complete P2P orders and deactivate ads to proceed.' />
113+
) : (
114+
<Localize i18n_default_text={(error as VerifyEmailError)?.message || ''} />
115+
)}
116+
</Text>
117+
118+
<Button onClick={onClose} has_effect primary large>
119+
<Localize i18n_default_text='OK' />
120+
</Button>
121+
</div>
122+
</Modal>
123+
)}
77124
</Fragment>
78125
);
79126
});

packages/account/src/Styles/account.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,28 @@ $MIN_HEIGHT_FLOATING: calc(
726726
}
727727
}
728728
}
729+
730+
&-unhandled-error {
731+
display: flex;
732+
flex-direction: column;
733+
justify-content: center;
734+
align-items: center;
735+
padding: 0.8rem 0;
736+
.dc-btn {
737+
margin-top: 2.4rem;
738+
}
739+
&-error_text {
740+
align-self: flex-start;
741+
padding-inline-start: 2.4rem;
742+
}
743+
@include mobile {
744+
height: calc(100vh - 80px);
745+
padding: 0.4rem 0;
746+
.dc-btn {
747+
margin-top: 1.6rem;
748+
}
749+
}
750+
}
729751
}
730752

731753
&__password-wrapper {

0 commit comments

Comments
 (0)