Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

farrah/78916/refactor InvalidVerificationLinkModal #7017

Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,36 @@ import React from 'react';
import PropTypes from 'prop-types';
import { Button, Icon, Modal, Text } from '@deriv/components';
import { Localize } from 'Components/i18next';
import { useStores } from 'Stores';
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context';

const InvalidVerificationLinkModal = ({
invalid_verification_link_error_message,
is_invalid_verification_link_modal_open,
onClickGetNewLinkButton,
setIsInvalidVerificationLinkModalOpen,
error_message,
order_id,
// TODO: Uncomment when time is available in BE response
// verification_link_expiry_time,
}) => {
const { order_store } = useStores();
const { hideModal, is_modal_open } = useModalManagerContext();

return (
<Modal
has_close_icon
is_open={is_invalid_verification_link_modal_open}
renderTitle={() => <></>}
toggleModal={() => setIsInvalidVerificationLinkModalOpen(false)}
width='440px'
>
<Modal has_close_icon is_open={is_modal_open} renderTitle={() => <></>} toggleModal={hideModal} width='440px'>
<Modal.Body className='invalid-verification-link-modal'>
<Icon icon='IcEmailVerificationLinkInvalid' size='128' />
<Text className='invalid-verification-link-modal--text' color='prominent' size='s' weight='bold'>
<Localize i18n_default_text='Invalid verification link' />
</Text>
<Text align='center' color='prominent' size='s'>
{invalid_verification_link_error_message}
{error_message}
</Text>
</Modal.Body>
<Modal.Footer className='invalid-verification-link-modal--footer'>
<Button
large
primary
onClick={() => {
setIsInvalidVerificationLinkModalOpen(false);
onClickGetNewLinkButton();
hideModal();
order_store.confirmOrderRequest(order_id);
}}
>
<Localize i18n_default_text='Get new link' />
Expand All @@ -45,10 +42,8 @@ const InvalidVerificationLinkModal = ({
};

InvalidVerificationLinkModal.propTypes = {
invalid_verification_link_error_message: PropTypes.string,
is_invalid_verification_link_modal_open: PropTypes.bool,
onClickGetNewLinkButton: PropTypes.func,
setIsInvalidVerificationLinkModalOpen: PropTypes.func,
error_message: PropTypes.string,
order_id: PropTypes.string,
// TODO: Uncomment when time is available in BE response
// verification_link_expiry_time: PropTypes.number,
};
Expand Down
7 changes: 0 additions & 7 deletions packages/p2p/src/components/order-details/order-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import MyProfileSeparatorContainer from '../my-profile/my-profile-separator-cont
import { setDecimalPlaces, removeTrailingZeros, roundOffDecimal } from 'Utils/format-value';
import 'Components/order-details/order-details.scss';
import LoadingModal from '../loading-modal';
import InvalidVerificationLinkModal from '../invalid-verification-link-modal';
import EmailLinkBlockedModal from '../email-link-blocked-modal';
import { getDateAfterHours } from 'Utils/date-time';
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context';
Expand Down Expand Up @@ -167,12 +166,6 @@ const OrderDetails = observer(() => {
)}
{!is_buy_order_for_user && (
<React.Fragment>
<InvalidVerificationLinkModal
invalid_verification_link_error_message={order_store.verification_link_error_message}
is_invalid_verification_link_modal_open={order_store.is_invalid_verification_link_modal_open}
setIsInvalidVerificationLinkModalOpen={order_store.setIsInvalidVerificationLinkModalOpen}
onClickGetNewLinkButton={() => order_store.confirmOrderRequest(id)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as this, should we refactor out modal props that receive handlers? Since it might affect reusability if other pages has different ways to handle the onClick events

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. But i think for now we can since this modal is specific to orders only.

/>
<EmailLinkBlockedModal
email_link_blocked_modal_error_message={order_store.verification_link_error_message}
is_email_link_blocked_modal_open={order_store.is_email_link_blocked_modal_open}
Expand Down
5 changes: 5 additions & 0 deletions packages/p2p/src/constants/modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export const modals = {
FilterModal: React.lazy(() =>
import(/* webpackChunkName: "filter-modal" */ 'Components/modal-manager/modals/filter-modal')
),
InvalidVerificationLinkModal: React.lazy(() =>
import(
/* webpackChunkName: "invalid-verification-link-modal" */ 'Components/modal-manager/modals/invalid-verification-link-modal'
)
),
MyAdsDeleteModal: React.lazy(() =>
import(/* webpackChunkName: "my-ads-delete-modal" */ 'Components/modal-manager/modals/my-ads-delete-modal')
),
Expand Down
28 changes: 11 additions & 17 deletions packages/p2p/src/stores/order-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export default class OrderStore {
setErrorMessage: action.bound,
setHasMoreItemsToLoad: action.bound,
setIsEmailLinkBlockedModalOpen: action.bound,
setIsInvalidVerificationLinkModalOpen: action.bound,
setIsLoading: action.bound,
setIsLoadingModalOpen: action.bound,
setIsRatingModalOpen: action.bound,
Expand Down Expand Up @@ -140,15 +139,14 @@ export default class OrderStore {
response?.error.code === api_error_codes.INVALID_VERIFICATION_TOKEN ||
response?.error.code === api_error_codes.EXCESSIVE_VERIFICATION_REQUESTS
) {
clearTimeout(wait);
// TODO: remove this once refactoring of EmailLinkVerifiedModal is done
this.root_store.general_store.hideModal();
this.setVerificationLinkErrorMessage(response.error.message);
const wait = setTimeout(() => this.setIsInvalidVerificationLinkModalOpen(true), 230);
this.root_store.general_store.showModal({
key: 'InvalidVerificationLinkModal',
props: { error_message: response.error.message, order_id: id },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
props: { error_message: response.error.message, order_id: id },
props: { error_message: response?.error.message, order_id: id },

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are already checking response on line 138

});
} else if (response?.error.code === api_error_codes.EXCESSIVE_VERIFICATION_FAILURES) {
if (this.is_invalid_verification_link_modal_open) {
this.setIsInvalidVerificationLinkModalOpen(false);
}
clearTimeout(wait);
this.setVerificationLinkErrorMessage(response.error.message);
const wait = setTimeout(() => this.setIsEmailLinkBlockedModalOpen(true), 230);
Expand Down Expand Up @@ -466,10 +464,12 @@ export default class OrderStore {
}

verifyEmailVerificationCode(verification_action, verification_code) {
const order_id = this.order_id;

if (verification_action === 'p2p_order_confirm' && verification_code) {
requestWS({
p2p_order_confirm: 1,
id: this.order_id,
id: order_id,
verification_code,
dry_run: 1,
}).then(response => {
Expand All @@ -485,13 +485,11 @@ export default class OrderStore {
response.error.code === api_error_codes.INVALID_VERIFICATION_TOKEN ||
response.error.code === api_error_codes.EXCESSIVE_VERIFICATION_REQUESTS
) {
clearTimeout(wait);
this.setVerificationLinkErrorMessage(response.error.message);
const wait = setTimeout(() => this.setIsInvalidVerificationLinkModalOpen(true), 750);
this.root_store.general_store.showModal({
key: 'InvalidVerificationLinkModal',
props: { error_message: response.error.message, order_id },
});
} else if (response.error.code === api_error_codes.EXCESSIVE_VERIFICATION_FAILURES) {
if (this.is_invalid_verification_link_modal_open) {
this.setIsInvalidVerificationLinkModalOpen(false);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to handle this by getting the modal key from modal manager, checking against it and only hiding the modal if it is the InvalidVerificationLinkModal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there's no need to pass the modal key when hiding since we are showing and hiding modals one at a time.

clearTimeout(wait);
this.setVerificationLinkErrorMessage(response.error.message);
const wait = setTimeout(() => this.setIsEmailLinkBlockedModalOpen(true), 600);
Expand Down Expand Up @@ -538,10 +536,6 @@ export default class OrderStore {
this.is_email_link_blocked_modal_open = is_email_link_blocked_modal_open;
}

setIsInvalidVerificationLinkModalOpen(is_invalid_verification_link_modal_open) {
this.is_invalid_verification_link_modal_open = is_invalid_verification_link_modal_open;
}

setIsLoading(is_loading) {
this.is_loading = is_loading;
}
Expand Down