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/78925/refactor CreateAdErrorModal #7052

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const ModalManager = () => {
const { key, props } = modal;
const Modal = modals[key];
const StackedModal = modals[stacked_modal?.key];

if (Modal)
return (
<React.Suspense fallback={null}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { observer } from 'mobx-react-lite';
import { localize, Localize } from 'Components/i18next';
import { api_error_codes } from 'Constants/api-error-codes';
import { useStores } from 'Stores';
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context';

const CreateAdErrorModal = () => {
const { my_ads_store } = useStores();
const { hideModal, is_modal_open } = useModalManagerContext();

if (my_ads_store.error_code === api_error_codes.DUPLICATE_ADVERT) {
return (
<Modal
className='p2p-my-ads__modal-error'
is_open={my_ads_store.is_api_error_modal_visible}
is_open={is_modal_open}
small
has_close_icon={false}
title={localize('You already have an ad with this rate')}
Expand All @@ -23,21 +25,15 @@ const CreateAdErrorModal = () => {
</Text>
</Modal.Body>
<Modal.Footer>
<Button
has_effect
text={localize('Update ad')}
onClick={() => my_ads_store.setIsApiErrorModalVisible(false)}
primary
large
/>
<Button has_effect text={localize('Update ad')} onClick={() => hideModal()} primary large />
</Modal.Footer>
</Modal>
);
} else if (my_ads_store.error_code === api_error_codes.ADVERT_SAME_LIMITS) {
return (
<Modal
className='p2p-my-ads__modal-error'
is_open={my_ads_store.is_api_error_modal_visible}
is_open={is_modal_open}
small
has_close_icon={false}
title={localize('You already have an ad with this range')}
Expand All @@ -48,21 +44,15 @@ const CreateAdErrorModal = () => {
</Text>
</Modal.Body>
<Modal.Footer>
<Button
has_effect
text={localize('Update ad')}
onClick={() => my_ads_store.setIsApiErrorModalVisible(false)}
primary
large
/>
<Button has_effect text={localize('Update ad')} onClick={() => hideModal()} primary large />
</Modal.Footer>
</Modal>
);
}
return (
<Modal
className='p2p-my-ads__modal-error'
is_open={my_ads_store.is_api_error_modal_visible}
is_open={is_modal_open}
small
has_close_icon={false}
title={localize("Something's not right")}
Expand All @@ -73,13 +63,7 @@ const CreateAdErrorModal = () => {
</Text>
</Modal.Body>
<Modal.Footer>
<Button
has_effect
text={localize('Ok')}
onClick={() => my_ads_store.setIsApiErrorModalVisible(false)}
primary
large
/>
<Button has_effect text={localize('Ok')} onClick={() => hideModal()} primary large />
</Modal.Footer>
</Modal>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CreateAdErrorModal from './create-ad-error-modal.jsx';

export default CreateAdErrorModal;
6 changes: 3 additions & 3 deletions packages/p2p/src/components/my-ads/create-ad-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { buy_sell } from 'Constants/buy-sell';
import { ad_type } from 'Constants/floating-rate';
import { useStores } from 'Stores';
import CreateAdSummary from './create-ad-summary.jsx';
import CreateAdErrorModal from './create-ad-error-modal.jsx';
import CreateAdFormPaymentMethods from './create-ad-form-payment-methods.jsx';

const CreateAdFormWrapper = ({ children }) => {
Expand Down Expand Up @@ -63,7 +62,9 @@ const CreateAdForm = () => {
my_profile_store.getAdvertiserPaymentMethods();
const disposeApiErrorReaction = reaction(
() => my_ads_store.api_error_message,
() => my_ads_store.setIsApiErrorModalVisible(!!my_ads_store.api_error_message)
() => {
if (my_ads_store.api_error_message) general_store.showModal({ key: 'CreateAdErrorModal', props: {} });
}
);
// P2P configuration is not subscribable. Hence need to fetch it on demand
general_store.setP2PConfig();
Expand Down Expand Up @@ -417,7 +418,6 @@ const CreateAdForm = () => {
);
}}
</Formik>
<CreateAdErrorModal />
<Modal
className='p2p-my-ads__ad-created'
has_close_icon={false}
Expand Down
3 changes: 3 additions & 0 deletions packages/p2p/src/constants/modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const modals = {
/* webpackChunkName: "cancel-add-payment-method-modal" */ 'Components/modal-manager/modals/cancel-add-payment-method-modal'
)
),
CreateAdErrorModal: React.lazy(() =>
import(/* webpackChunkName: "create-ad-error-modal" */ 'Components/modal-manager/modals/create-ad-error-modal')
),
CreateAdAddPaymentMethodModal: React.lazy(() =>
import(
/* webpackChunkName: "create-ad-add-payment-method-modal" */ 'Components/modal-manager/modals/create-ad-add-payment-method-modal'
Expand Down
8 changes: 2 additions & 6 deletions packages/p2p/src/stores/my-ads-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,8 @@ export default class MyAdsStore extends BaseStore {
setSubmitting(false);
} else if (should_not_show_auto_archive_message !== 'true' && this.adverts_archive_period) {
this.setAdvertDetails(response.p2p_advert_create);
setTimeout(() => {
if (!this.is_api_error_modal_visible) {
this.setIsAdCreatedModalVisible(true);
}
}, 200);
} else if (!this.is_api_error_modal_visible && !this.is_ad_created_modal_visible) {
this.setIsAdCreatedModalVisible(true);
} else if (!this.is_ad_created_modal_visible) {
if (!response.p2p_advert_create.is_visible) {
this.setAdvertDetails(response.p2p_advert_create);
}
Expand Down