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

Adrienne / Quick Add Modal and integrating new payment method dropdown component for buy ads in the modal #7308

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 @@ -23,27 +23,27 @@ const ModalManagerContextProvider = props => {
* @param {Object|Object[]} modals - list of object modals to set props, each modal object must contain a 'key' attribute and 'props' attribute
*/
const useRegisterModalProps = modals => {
const registered_modals = [];
const registered_modals = React.useRef([]);

const registerModals = React.useCallback(() => {
if (Array.isArray(modals)) {
modals.forEach(modal => {
registered_modals.push(modal);
registered_modals.current.push(modal);
setModalProps(modal_props.set(modal.key, modal.props));
});
} else {
registered_modals.push(modals);
registered_modals.current.push(modals);
setModalProps(modal_props.set(modals.key, modals.props));
}
}, [modals]);

React.useEffect(() => {
registerModals();
return () => {
registered_modals.forEach(registered_modal => {
registered_modals.current.forEach(registered_modal => {
modal_props.delete(registered_modal.key);
});
registered_modals.current = []
registered_modals.current = [];
};
}, [modals]);
};
Expand Down Expand Up @@ -72,16 +72,15 @@ const ModalManagerContextProvider = props => {
*/
const hideModal = (options = {}) => {
const { should_save_form_history = false, should_hide_all_modals = false } = options;

modal_props.delete(active_modal.key);
if (isDesktop()) {
if (should_save_form_history) {
general_store.saveFormState();
} else {
general_store.setSavedFormState(null);
general_store.setFormikRef(null);
}

if (should_save_form_history) {
general_store.saveFormState();
} else {
general_store.setSavedFormState(null);
general_store.setFormikRef(null);
}

if (isDesktop()) {
if (should_hide_all_modals) {
setPreviousModal({});
setActiveModal({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useStores } from 'Stores';
import { Localize } from 'Components/i18next';
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context';

const CancelAddPaymentMethodModal = () => {
const CancelAddPaymentMethodModal = ({ onCancel, should_hide_all_modals_on_cancel }) => {
const { my_ads_store, my_profile_store } = useStores();
const { hideModal, is_modal_open } = useModalManagerContext();

Expand All @@ -30,10 +30,12 @@ const CancelAddPaymentMethodModal = () => {
large
onClick={() => {
my_profile_store.hideAddPaymentMethodForm();
my_profile_store.setIsCancelEditPaymentMethodModalOpen(false);
my_profile_store.setSelectedPaymentMethod('');
my_ads_store.setShouldShowAddPaymentMethod(false);
onCancel?.();
adrienne-deriv marked this conversation as resolved.
Show resolved Hide resolved
hideModal({
should_hide_all_modals: my_ads_store.show_ad_form || my_ads_store.show_edit_ad_form,
should_save_form_history: false,
should_hide_all_modals: should_hide_all_modals_on_cancel ?? false,
});
}}
secondary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const CreateAdAddPaymentMethodModal = () => {
if (my_profile_store.selected_payment_method.length > 0 || general_store.is_form_modified) {
showModal({
key: 'CancelAddPaymentMethodModal',
props: {
should_hide_all_modals_on_cancel: true,
},
});
} else {
hideModal({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Button, Modal } from '@deriv/components';
import { Localize } from 'Components/i18next';
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context';

const ErrorModal = ({ error_message, error_modal_title, has_close_icon, setIsErrorModalOpen, width }) => {
const { is_modal_open } = useModalManagerContext();
const ErrorModal = ({ error_message, error_modal_title, has_close_icon, width }) => {
const { hideModal, is_modal_open } = useModalManagerContext();

return (
<Modal
Expand All @@ -18,7 +18,7 @@ const ErrorModal = ({ error_message, error_modal_title, has_close_icon, setIsErr
>
<Modal.Body className='error-modal__body'>{error_message}</Modal.Body>
<Modal.Footer>
<Button large primary onClick={() => setIsErrorModalOpen(false)}>
<Button large primary onClick={hideModal}>
<Localize i18n_default_text='Ok' />
</Button>
</Modal.Footer>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import QuickAddModal from './quick-add-modal.jsx';
import './quick-add-modal.scss';

export default QuickAddModal;
Loading