-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3826ca2
commit 4c6ff3e
Showing
4 changed files
with
191 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 55 additions & 44 deletions
99
...nents/PaymentMethodForm/PaymentMethodFormModalRenderer/PaymentMethodFormModalRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,81 @@ | ||
import { useEffect } from 'react'; | ||
import { TFormState, TSocketError } from 'types'; | ||
import { PaymentMethodErrorModal, PaymentMethodModal } from '@/components/Modals'; | ||
import { useModalManager } from '@/hooks'; | ||
|
||
type TPaymentMethodFormModalRendererProps = { | ||
actionType: TFormState['actionType']; | ||
createError: TSocketError<'p2p_advertiser_payment_methods'> | null; | ||
isCreateSuccessful: boolean; | ||
isModalOpen: boolean; | ||
isUpdateSuccessful: boolean; | ||
onRequestClose: () => void; | ||
onResetFormState: () => void; | ||
setIsError: (isError: boolean) => void; | ||
updateError: TSocketError<'p2p_advertiser_payment_methods'> | null; | ||
}; | ||
|
||
const PaymentMethodFormModalRenderer = ({ | ||
actionType, | ||
createError, | ||
isCreateSuccessful, | ||
isModalOpen, | ||
isUpdateSuccessful, | ||
onRequestClose, | ||
onResetFormState, | ||
setIsError, | ||
updateError, | ||
}: TPaymentMethodFormModalRendererProps) => { | ||
if (actionType === 'ADD' && (!isCreateSuccessful || !createError) && isModalOpen) { | ||
return ( | ||
<PaymentMethodModal | ||
description='If you choose to cancel, the changes you’ve made will be lost.' | ||
isModalOpen={isModalOpen} | ||
onConfirm={onResetFormState} | ||
onReject={onRequestClose} | ||
primaryButtonLabel='Go back' | ||
secondaryButtonLabel='Cancel' | ||
title='Cancel adding this payment method?' | ||
/> | ||
); | ||
} | ||
const { hideModal, isModalOpenFor, showModal } = useModalManager(); | ||
|
||
if (actionType === 'EDIT' && (!isUpdateSuccessful || !updateError) && isModalOpen) { | ||
return ( | ||
<PaymentMethodModal | ||
description='If you choose to cancel, the details you’ve entered will be lost.' | ||
isModalOpen={isModalOpen} | ||
onConfirm={onResetFormState} | ||
onReject={onRequestClose} | ||
primaryButtonLabel="Don't cancel" | ||
secondaryButtonLabel='Cancel' | ||
title='Cancel your edits?' | ||
/> | ||
); | ||
} | ||
useEffect(() => { | ||
if ( | ||
(actionType === 'ADD' && (!isCreateSuccessful || !createError)) || | ||
(actionType === 'EDIT' && (!isUpdateSuccessful || !updateError)) | ||
) { | ||
showModal('PaymentMethodModal'); | ||
} | ||
|
||
// TODO: Remember to translate these strings | ||
if (createError || updateError) { | ||
return ( | ||
<PaymentMethodErrorModal | ||
errorMessage={String(createError?.error?.message || updateError?.error?.message)} | ||
isModalOpen={true} | ||
onConfirm={() => { | ||
onResetFormState(); | ||
}} | ||
title='Something’s not right' | ||
/> | ||
); | ||
} | ||
// TODO: Remember to translate these strings | ||
if (createError || updateError) { | ||
showModal('PaymentMethodErrorModal'); | ||
} | ||
}, [actionType, createError, isCreateSuccessful, isUpdateSuccessful, updateError]); | ||
Check warning on line 39 in src/components/PaymentMethodForm/PaymentMethodFormModalRenderer/PaymentMethodFormModalRenderer.tsx GitHub Actions / build_to_cloudflare_pages
|
||
|
||
return null; | ||
return ( | ||
<> | ||
{!!isModalOpenFor('PaymentMethodErrorModal') && ( | ||
<PaymentMethodErrorModal | ||
errorMessage={String(createError?.error?.message || updateError?.error?.message)} | ||
isModalOpen={!!isModalOpenFor('PaymentMethodErrorModal')} | ||
onConfirm={() => { | ||
onResetFormState(); | ||
setIsError(false); | ||
hideModal({ shouldHideAllModals: true }); | ||
}} | ||
title='Something’s not right' | ||
/> | ||
)} | ||
{!!isModalOpenFor('PaymentMethodModal') && ( | ||
<PaymentMethodModal | ||
description={ | ||
actionType === 'ADD' | ||
? 'If you choose to cancel, the changes you’ve made will be lost.' | ||
: 'If you choose to cancel, the details you’ve entered will be lost.' | ||
} | ||
isModalOpen={!!isModalOpenFor('PaymentMethodModal')} | ||
onConfirm={() => { | ||
onResetFormState(); | ||
setIsError(false); | ||
hideModal({ shouldHideAllModals: true }); | ||
}} | ||
onReject={() => { | ||
hideModal(); | ||
setIsError(false); | ||
}} | ||
primaryButtonLabel={actionType === 'ADD' ? 'Go back' : "Don't cancel"} | ||
secondaryButtonLabel='Cancel' | ||
title={actionType === 'ADD' ? 'Cancel adding this payment method?' : 'Cancel your edits?'} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default PaymentMethodFormModalRenderer; |
Oops, something went wrong.