Skip to content

Commit 8529261

Browse files
committed
Fix PR review comments: dedup modals, navigation back, eslint justification
1 parent fd58842 commit 8529261

4 files changed

Lines changed: 26 additions & 14 deletions

File tree

src/components/DecisionModal.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type DecisionModalProps = {
5050

5151
/** Whether modal is visible */
5252
isVisible: boolean;
53+
54+
/** Whether to handle browser navigation back to close the modal */
55+
shouldHandleNavigationBack?: boolean;
5356
};
5457

5558
function DecisionModal({
@@ -67,6 +70,7 @@ function DecisionModal({
6770
isFirstOptionSuccess = true,
6871
isSecondOptionSuccess = false,
6972
isSecondOptionDanger = false,
73+
shouldHandleNavigationBack,
7074
}: DecisionModalProps) {
7175
const styles = useThemeStyles();
7276

@@ -77,6 +81,7 @@ function DecisionModal({
7781
type={isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.CONFIRM}
7882
innerContainerStyle={styles.pv0}
7983
onModalHide={onModalHide}
84+
shouldHandleNavigationBack={shouldHandleNavigationBack}
8085
>
8186
<ScrollView contentContainerStyle={styles.m5}>
8287
<View>

src/components/Modal/Global/DecisionModalWrapper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function DecisionModalWrapper({closeModal, onModalHide, ...props}: DecisionModal
3434

3535
return (
3636
<DecisionModal
37+
// Spreading is needed to forward all modal configuration props from the wrapper to the underlying DecisionModal.
3738
// eslint-disable-next-line react/jsx-props-no-spreading
3839
{...props}
3940
isVisible={isVisible}

src/components/MoneyReportHeader.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,23 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa
384384
const [exportModalStatus, setExportModalStatus] = useState<ExportType | null>(null);
385385
const {showConfirmModal} = useConfirmModal();
386386
const {showDecisionModal} = useDecisionModal();
387+
388+
const showOfflineModal = () => {
389+
showDecisionModal({
390+
title: translate('common.youAppearToBeOffline'),
391+
prompt: translate('common.offlinePrompt'),
392+
secondOptionText: translate('common.buttonConfirm'),
393+
});
394+
};
395+
396+
const showDownloadErrorModal = () => {
397+
showDecisionModal({
398+
title: translate('common.downloadFailedTitle'),
399+
prompt: translate('common.downloadFailedDescription'),
400+
secondOptionText: translate('common.buttonConfirm'),
401+
});
402+
};
403+
387404
const {isPaidAnimationRunning, isApprovedAnimationRunning, isSubmittingAnimationRunning, startAnimation, stopAnimation, startApprovedAnimation, startSubmittingAnimation} =
388405
usePaymentAnimations();
389406
const styles = useThemeStyles();
@@ -585,20 +602,8 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa
585602
reportActions,
586603
allTransactionsLength: transactions.length,
587604
session,
588-
onExportFailed: () => {
589-
showDecisionModal({
590-
title: translate('common.downloadFailedTitle'),
591-
prompt: translate('common.downloadFailedDescription'),
592-
secondOptionText: translate('common.buttonConfirm'),
593-
});
594-
},
595-
onExportOffline: () => {
596-
showDecisionModal({
597-
title: translate('common.youAppearToBeOffline'),
598-
prompt: translate('common.offlinePrompt'),
599-
secondOptionText: translate('common.buttonConfirm'),
600-
});
601-
},
605+
onExportFailed: showDownloadErrorModal,
606+
onExportOffline: showOfflineModal,
602607
policy,
603608
beginExportWithTemplate: (templateName, templateType, transactionIDList, policyID) => beginExportWithTemplate(templateName, templateType, transactionIDList, policyID),
604609
isOnSearch,

src/hooks/useDecisionModal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const useDecisionModal = () => {
1111
return context.showModal({
1212
component: DecisionModalWrapper,
1313
props: {
14+
shouldHandleNavigationBack: true,
1415
...options,
1516
},
1617
});

0 commit comments

Comments
 (0)