From 369f8406a59262c79b34302b7cd46d4d9fd03213 Mon Sep 17 00:00:00 2001 From: "Yauheni Horbach (via MelvinBot)" Date: Fri, 9 Oct 2026 07:02:12 +0000 Subject: [PATCH 1/3] Use useDecisionModal for Search bulk actions and SelectionToolbar alerts Co-authored-by: Yauheni Horbach --- .../SelectionToolbar/index.tsx | 45 +++---- .../Search/SearchBulkActionsButton.tsx | 39 +----- src/hooks/useSearchBulkActions.ts | 122 ++++++++++-------- .../Search/SearchBulkActionsButtonTest.tsx | 2 - .../useSearchBulkActionsDownloadPDFTest.ts | 16 ++- ...seSearchBulkActionsDownloadReceiptsTest.ts | 10 +- .../hooks/useSearchBulkActionsExportTest.ts | 32 ++++- .../unit/hooks/useSearchBulkActionsPayTest.ts | 8 +- 8 files changed, 150 insertions(+), 124 deletions(-) diff --git a/src/components/MoneyRequestReportView/SelectionToolbar/index.tsx b/src/components/MoneyRequestReportView/SelectionToolbar/index.tsx index 326535b4fdac..78bcf1fdfca0 100644 --- a/src/components/MoneyRequestReportView/SelectionToolbar/index.tsx +++ b/src/components/MoneyRequestReportView/SelectionToolbar/index.tsx @@ -1,4 +1,3 @@ -import DecisionModal from '@components/DecisionModal'; import {useDelegateNoAccessActions, useDelegateNoAccessState} from '@components/DelegateNoAccessModalProvider'; import HoldOrRejectEducationalModal from '@components/HoldOrRejectEducationalModal'; import {ModalActions} from '@components/Modal/Global/ModalContext'; @@ -10,6 +9,7 @@ import BulkDuplicateHandler from '@components/Search/BulkDuplicateHandler'; import {useSearchSelectionActions, useSearchSelectionContext} from '@components/Search/SearchContext'; import useConfirmModal from '@hooks/useConfirmModal'; +import useDecisionModal from '@hooks/useDecisionModal'; import useFilterSelectedTransactions from '@hooks/useFilterSelectedTransactions'; import useLocalize from '@hooks/useLocalize'; import useMobileSelectionMode from '@hooks/useMobileSelectionMode'; @@ -91,9 +91,24 @@ function SelectionToolbar({reportID, transactions, reportActions}: SelectionTool const isMobileSelectionModeEnabled = useMobileSelectionMode(); const {showConfirmModal} = useConfirmModal(); + const {showDecisionModal} = useDecisionModal(); + + const showOfflineModal = () => { + showDecisionModal({ + title: translate('common.youAppearToBeOffline'), + prompt: translate('common.offlinePrompt'), + secondOptionText: translate('common.buttonConfirm'), + }); + }; + + const showDownloadErrorModal = () => { + showDecisionModal({ + title: translate('common.downloadFailedTitle'), + prompt: translate('common.downloadFailedDescription'), + secondOptionText: translate('common.buttonConfirm'), + }); + }; - const [offlineModalVisible, setOfflineModalVisible] = useState(false); - const [isDownloadErrorModalVisible, setIsDownloadErrorModalVisible] = useState(false); const [rejectModalAction, setRejectModalAction] = useState | null>(null); const transactionsWithoutPendingDelete = transactions.filter((t) => !isTransactionPendingDelete(t)); @@ -102,7 +117,7 @@ function SelectionToolbar({reportID, transactions, reportActions}: SelectionTool const beginExportWithTemplate = (templateName: string, templateType: string, transactionIDList: string[], exportName: string) => { if (isOffline) { - setOfflineModalVisible(true); + showOfflineModal(); return; } @@ -164,8 +179,8 @@ function SelectionToolbar({reportID, transactions, reportActions}: SelectionTool reportActions, allTransactionsLength: transactions.length, session, - onExportFailed: () => setIsDownloadErrorModalVisible(true), - onExportOffline: () => setOfflineModalVisible(true), + onExportFailed: showDownloadErrorModal, + onExportOffline: showOfflineModal, policy, beginExportWithTemplate: (templateName, templateType, transactionIDList, exportName) => beginExportWithTemplate(templateName, templateType, transactionIDList, exportName), onDeleteSelected, @@ -306,24 +321,6 @@ function SelectionToolbar({reportID, transactions, reportActions}: SelectionTool onClearSelection={() => clearSelectedTransactions(true)} /> )} - setIsDownloadErrorModalVisible(false)} - secondOptionText={translate('common.buttonConfirm')} - isVisible={isDownloadErrorModalVisible} - onClose={() => setIsDownloadErrorModalVisible(false)} - /> - setOfflineModalVisible(false)} - secondOptionText={translate('common.buttonConfirm')} - isVisible={offlineModalVisible} - onClose={() => setOfflineModalVisible(false)} - /> {!!rejectModalAction && ( (), selectedReports, areAllMatchingItemsSelected} = useSearchSelectionContext(); const {clearSelectedTransactions} = useSearchSelectionActions(); const {currentSearchResults} = useSearchResultsContext(); @@ -80,20 +77,13 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) { selectedReportIDs, businessBankAccountOptions, confirmPayment, - isOfflineModalVisible, - isDownloadErrorModalVisible, isHoldEducationalModalVisible, areAllTransactionsFromDMReports, rejectModalAction, - emptyReportsCount, - handleOfflineModalClose, - handleDownloadErrorModalClose, isExpensifyCardStatementPDFModalVisible, setIsExpensifyCardStatementPDFModalVisible, expensifyCardStatementPDFParams, handleExpensifyCardStatementPDFModalHide, - isExpensifyCardStatementMultiFeedAlertVisible, - handleExpensifyCardStatementMultiFeedAlertClose, dismissModalAndUpdateUseHold, dismissRejectModalBasedOnAction, isDuplicateOptionVisible, @@ -271,24 +261,6 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) { ) } - - {!!expensifyCardStatementPDFParams && ( )} - {!!rejectModalAction && ( (undefined); - const [isExpensifyCardStatementMultiFeedAlertVisible, setIsExpensifyCardStatementMultiFeedAlertVisible] = useState(false); const {showConfirmModal} = useConfirmModal(); + const {showDecisionModal} = useDecisionModal(); + + const showOfflineModal = useCallback(() => { + showDecisionModal({ + title: translate('common.youAppearToBeOffline'), + prompt: translate('common.offlinePrompt'), + secondOptionText: translate('common.buttonConfirm'), + }); + }, [showDecisionModal, translate]); + + const showDownloadErrorModal = useCallback(() => { + showDecisionModal({ + title: translate('common.downloadFailedTitle'), + prompt: translate('common.downloadFailedDescription'), + secondOptionText: translate('common.buttonConfirm'), + }); + }, [showDecisionModal, translate]); + + const showEmptyReportsDownloadErrorModal = useCallback( + (count: number) => { + showDecisionModal({ + title: translate('common.downloadFailedTitle'), + prompt: translate('common.downloadFailedEmptyReportDescription', {count}), + secondOptionText: translate('common.buttonConfirm'), + }); + }, + [showDecisionModal, translate], + ); + + const showExpensifyCardStatementMultiFeedAlert = useCallback(() => { + showDecisionModal({ + title: translate('search.expensifyCardStatementPDF.title'), + prompt: translate('search.expensifyCardStatementPDF.oneFeedAtATime'), + secondOptionText: translate('common.buttonConfirm'), + }); + }, [showDecisionModal, translate]); const openSearchReportSubmitToPopover = useOpenSearchReportSubmitToPopover(); const {showReportPDFDownloadModal} = useReportPDFDownloadModal(); const [isHoldEducationalModalVisible, setIsHoldEducationalModalVisible] = useState(false); @@ -678,8 +712,6 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { typeof CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.HOLD | typeof CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.REJECT > | null>(null); - const [emptyReportsCount, setEmptyReportsCount] = useState(0); - const [dismissedRejectUseExplanation] = useOnyx(ONYXKEYS.NVP_DISMISSED_REJECT_USE_EXPLANATION); const [dismissedHoldUseExplanation] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION); const [isTrackIntentUser] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {selector: isTrackIntentUserSelector}); @@ -929,7 +961,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const exportExpensifyCardStatementPDF = useCallback(() => { if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } @@ -939,7 +971,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { } if (selection.hasMultipleFeeds) { - setIsExpensifyCardStatementMultiFeedAlertVisible(true); + showExpensifyCardStatementMultiFeedAlert(); return; } @@ -959,7 +991,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { } setIsExpensifyCardStatementPDFModalVisible(false); setExpensifyCardStatementPDFParams(undefined); - setIsDownloadErrorModalVisible(true); + showDownloadErrorModal(); }; setExpensifyCardStatementPDFParams(statementParams); @@ -983,7 +1015,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { setExpensifyCardStatementPDFParams((currentParams) => (currentParams ? {...currentParams, statementKey} : currentParams)); }) .catch(showStatementError); - }, [isOffline]); + }, [isOffline, showOfflineModal, showExpensifyCardStatementMultiFeedAlert, showDownloadErrorModal]); const firstTransactionID = selectedTransactionsKeys.at(0); const firstTransaction = (firstTransactionID ? currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${firstTransactionID}`] : undefined) ?? @@ -1031,18 +1063,17 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const beginExportWithTemplate = useCallback( (templateName: string, templateType: string, policyID: string | undefined, exportName: string) => { if (hasOnlyEmptyReports) { - setEmptyReportsCount(emptyReports.length); - setIsDownloadErrorModalVisible(true); + showEmptyReportsDownloadErrorModal(emptyReports.length); return; } if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } if (areAllMatchingItemsSelected) { const allMatchingQueryJSON = queryJSON ? getUngroupedTemplateExportQuery(queryJSON) : undefined; if (queryJSON && !allMatchingQueryJSON) { - setIsDownloadErrorModalVisible(true); + showDownloadErrorModal(); return; } queueExportSearchWithTemplate( @@ -1063,7 +1094,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const {isGroupExport, transactionIDList} = getGroupExportScope(queryJSON, selectedTransactions); const groupExportQueryJSON = isGroupExport && queryJSON ? getTemplateGroupExportQuery(queryJSON, selectedTransactions, currentSearchResults?.data) : undefined; if (isGroupExport && !groupExportQueryJSON) { - setIsDownloadErrorModalVisible(true); + showDownloadErrorModal(); return; } queueExportSearchWithTemplate( @@ -1093,6 +1124,9 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { emptyReports.length, selectedTransactions, isOffline, + showOfflineModal, + showDownloadErrorModal, + showEmptyReportsDownloadErrorModal, areAllMatchingItemsSelected, currentSearchResults?.data, currentSearchKey, @@ -1194,12 +1228,11 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const handleCSVExport = useCallback( async (isBasicExport: boolean) => { if (hasOnlyEmptyReports) { - setEmptyReportsCount(emptyReports.length); - setIsDownloadErrorModalVisible(true); + showEmptyReportsDownloadErrorModal(emptyReports.length); return; } if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } @@ -1213,7 +1246,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const allMatchingExportData = isExpenseType && queryJSON ? getAllMatchingExportQueryAndExclusions(queryJSON, excludedTransactions, currentSearchResults?.data) : undefined; const allMatchingReportExportQuery = isExpenseReportType && queryJSON ? getAllMatchingReportQuery(queryJSON, excludedTransactions) : undefined; if ((isExpenseType && !allMatchingExportData) || (isExpenseReportType && !allMatchingReportExportQuery)) { - setIsDownloadErrorModalVisible(true); + showDownloadErrorModal(); return; } const reportIDList = selectedReports?.map((report) => report?.reportID).filter((reportID) => reportID !== undefined) ?? []; @@ -1252,8 +1285,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { }, () => { didFail = true; - setEmptyReportsCount(0); - setIsDownloadErrorModalVisible(true); + showDownloadErrorModal(); }, translate, allReportsTransactionsAndViolations, @@ -1266,6 +1298,9 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { hasOnlyEmptyReports, emptyReports.length, isOffline, + showOfflineModal, + showDownloadErrorModal, + showEmptyReportsDownloadErrorModal, areAllMatchingItemsSelected, queryJSON, selectedReports, @@ -1291,7 +1326,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const handleApproveWithDEWCheck = useCallback(async () => { if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } @@ -1370,6 +1405,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { } }, [ isOffline, + showOfflineModal, isDelegateAccessRestricted, showDelegateNoAccessModal, selectedReports, @@ -1558,7 +1594,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { if (isOffline) { // On iOS, presenting the offline modal while the payment popover is still dismissing freezes the app, // so defer it until the popover transition completes (matching the delegate/locked-account guards). - deferModalPresentationAfterPopoverDismiss(() => setIsOfflineModalVisible(true)); + deferModalPresentationAfterPopoverDismiss(() => showOfflineModal()); return; } @@ -1835,6 +1871,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { }, [ hash, + showOfflineModal, areAllMatchingItemsSelected, queryJSON, excludedTransactions, @@ -2346,7 +2383,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { return; } if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } clearSelectedTransactions(); @@ -2526,7 +2563,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { onSelected: () => { // A queued all-matching move would send a stale query, so ask the user to reconnect like export does if (areAllMatchingItemsSelected && isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } Navigation.navigate(ROUTES.MOVE_TRANSACTIONS_SEARCH_RHP.getRoute()); @@ -2558,7 +2595,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { shouldCloseModalOnSelect: true, onSelected: async () => { if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } // In "Select all" mode the matching reports aren't enumerated on the client (results are paged), @@ -2567,7 +2604,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { if (areAllMatchingItemsSelected) { const allMatchingReportQuery = queryJSON ? getAllMatchingReportQuery(queryJSON, excludedTransactions) : undefined; if (!allMatchingReportQuery) { - setIsDownloadErrorModalVisible(true); + showDownloadErrorModal(); return; } const serializedQuery = serializeQueryJSONForBackend({...allMatchingReportQuery, searchKey: currentSearchKey}); @@ -2720,7 +2757,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { shouldCloseModalOnSelect: true, onSelected: () => { if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } @@ -2780,7 +2817,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { shouldCloseModalOnSelect: true, onSelected: () => { if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } @@ -2951,7 +2988,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { shouldCloseModalOnSelect: true, onSelected: () => { if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } exportReceiptsToZip({reportIDs: selectedReportIDs}); @@ -2981,7 +3018,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { shouldCloseModalOnSelect: true, onSelected: () => { if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } exportReceiptsToZip({transactionIDs}); @@ -3016,7 +3053,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { shouldCloseModalOnSelect: true, onSelected: () => { if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } @@ -3049,7 +3086,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { shouldCloseModalOnSelect: true, onSelected: () => { if (isOffline) { - setIsOfflineModalVisible(true); + showOfflineModal(); return; } @@ -3217,6 +3254,8 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { return buildResult(options); }, [ selectedTransactionsKeys, + showOfflineModal, + showDownloadErrorModal, cardList, hash, selectedTransactions, @@ -3320,14 +3359,6 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { dropdownButtonsOptions.length > 0 && dropdownButtonsOptions.every((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT && !option.subMenuItems); const bulkActionsMenuHeaderText = isShowingExportOptionsDirectly ? translate('common.export') : undefined; - const handleOfflineModalClose = useCallback(() => { - setIsOfflineModalVisible(false); - }, [setIsOfflineModalVisible]); - - const handleDownloadErrorModalClose = useCallback(() => { - setIsDownloadErrorModalVisible(false); - }, [setIsDownloadErrorModalVisible]); - const handleExpensifyCardStatementPDFModalHide = useCallback(() => { setExpensifyCardStatementPDFParams(undefined); // Clear the selection when the statement modal closes (after download or failure), like the other bulk @@ -3336,10 +3367,6 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { clearSelectedTransactions(); }, [clearSelectedTransactions]); - const handleExpensifyCardStatementMultiFeedAlertClose = useCallback(() => { - setIsExpensifyCardStatementMultiFeedAlertVisible(false); - }, []); - const dismissModalAndUpdateUseHold = useCallback(() => { setIsHoldEducationalModalVisible(false); setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !isOffline); @@ -3370,20 +3397,13 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { selectedReportIDs, businessBankAccountOptions, confirmPayment: stableOnBulkPaySelected, - isOfflineModalVisible, - isDownloadErrorModalVisible, isHoldEducationalModalVisible, areAllTransactionsFromDMReports, rejectModalAction, - emptyReportsCount, - handleOfflineModalClose, - handleDownloadErrorModalClose, isExpensifyCardStatementPDFModalVisible, setIsExpensifyCardStatementPDFModalVisible, expensifyCardStatementPDFParams, handleExpensifyCardStatementPDFModalHide, - isExpensifyCardStatementMultiFeedAlertVisible, - handleExpensifyCardStatementMultiFeedAlertClose, dismissModalAndUpdateUseHold, dismissRejectModalBasedOnAction, isDuplicateOptionVisible, diff --git a/tests/unit/Search/SearchBulkActionsButtonTest.tsx b/tests/unit/Search/SearchBulkActionsButtonTest.tsx index 5a9f10fe5efd..39d8a09c1776 100644 --- a/tests/unit/Search/SearchBulkActionsButtonTest.tsx +++ b/tests/unit/Search/SearchBulkActionsButtonTest.tsx @@ -38,7 +38,6 @@ jest.mock('@components/ButtonWithDropdownMenu', () => ({ __esModule: true, default: (props: MockButtonProps) => mockButtonWithDropdownMenu(props), })); -jest.mock('@components/DecisionModal', () => () => null); jest.mock('@components/HoldOrRejectEducationalModal', () => () => null); jest.mock('@components/HoldSubmitterEducationalModal', () => () => null); jest.mock('@components/ReportPDFDownloadModal', () => () => null); @@ -77,7 +76,6 @@ jest.mock('@hooks/useSearchBulkActions', () => ({ selectedTransactionReportIDs: [], selectedReportIDs: [], businessBankAccountOptions: [], - emptyReportsCount: 0, isDuplicateOptionVisible: false, isDuplicateReportOptionVisible: false, allTransactions: {}, diff --git a/tests/unit/hooks/useSearchBulkActionsDownloadPDFTest.ts b/tests/unit/hooks/useSearchBulkActionsDownloadPDFTest.ts index 1b59af832309..24ead3724068 100644 --- a/tests/unit/hooks/useSearchBulkActionsDownloadPDFTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsDownloadPDFTest.ts @@ -40,6 +40,12 @@ jest.mock('@hooks/useNetwork', () => ({ default: () => ({isOffline: mockIsOffline}), })); +const mockShowDecisionModal = jest.fn(); +jest.mock('@hooks/useDecisionModal', () => ({ + __esModule: true, + default: () => ({showDecisionModal: mockShowDecisionModal}), +})); + jest.mock('@hooks/useEnvironment', () => ({ __esModule: true, default: () => ({isProduction: false, isDevelopment: true, environment: 'development'}), @@ -587,7 +593,7 @@ describe('useSearchBulkActions - Download report', () => { // Then no incomplete export is started and the existing download error is shown expect(exportReportsToPDF).not.toHaveBeenCalled(); - expect(result.current.isDownloadErrorModalVisible).toBe(true); + expect(mockShowDecisionModal).toHaveBeenCalledWith(expect.objectContaining({title: 'common.downloadFailedTitle', prompt: 'common.downloadFailedDescription'})); }); it('should show Export as PDF for selected Expensify Card settlement groups', async () => { @@ -666,7 +672,7 @@ describe('useSearchBulkActions - Download report', () => { // The loading modal is dismissed and the download-error modal is shown instead of hanging on "waiting". await waitFor(() => { - expect(result.current.isDownloadErrorModalVisible).toBe(true); + expect(mockShowDecisionModal).toHaveBeenCalledWith(expect.objectContaining({title: 'common.downloadFailedTitle', prompt: 'common.downloadFailedDescription'})); }); expect(result.current.isExpensifyCardStatementPDFModalVisible).toBe(false); expect(result.current.expensifyCardStatementPDFParams).toBeUndefined(); @@ -718,7 +724,7 @@ describe('useSearchBulkActions - Download report', () => { await Promise.resolve(); }); - expect(result.current.isDownloadErrorModalVisible).toBe(false); + expect(mockShowDecisionModal).not.toHaveBeenCalled(); expect(result.current.isExpensifyCardStatementPDFModalVisible).toBe(true); expect(result.current.expensifyCardStatementPDFParams?.entryIDs).toEqual([456]); }); @@ -748,7 +754,9 @@ describe('useSearchBulkActions - Download report', () => { }); expect(getExpensifyCardStatementPDF).not.toHaveBeenCalled(); - expect(result.current.isExpensifyCardStatementMultiFeedAlertVisible).toBe(true); + expect(mockShowDecisionModal).toHaveBeenCalledWith( + expect.objectContaining({title: 'search.expensifyCardStatementPDF.title', prompt: 'search.expensifyCardStatementPDF.oneFeedAtATime'}), + ); }); it('should export a cross-workspace settlement as the whole settlement (no policyID)', async () => { diff --git a/tests/unit/hooks/useSearchBulkActionsDownloadReceiptsTest.ts b/tests/unit/hooks/useSearchBulkActionsDownloadReceiptsTest.ts index e7559784eb1a..06b4f72d9263 100644 --- a/tests/unit/hooks/useSearchBulkActionsDownloadReceiptsTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsDownloadReceiptsTest.ts @@ -31,6 +31,12 @@ jest.mock('@hooks/useNetwork', () => ({ default: () => ({isOffline: mockIsOffline}), })); +const mockShowDecisionModal = jest.fn(); +jest.mock('@hooks/useDecisionModal', () => ({ + __esModule: true, + default: () => ({showDecisionModal: mockShowDecisionModal}), +})); + jest.mock('@hooks/useEnvironment', () => ({ __esModule: true, default: () => ({isProduction: false, isDevelopment: true, environment: 'development'}), @@ -344,7 +350,7 @@ describe('useSearchBulkActions - Download receipts', () => { }); expect(exportReceiptsToZip).not.toHaveBeenCalled(); - expect(result.current.isOfflineModalVisible).toBe(true); + expect(mockShowDecisionModal).toHaveBeenCalledWith(expect.objectContaining({title: 'common.youAppearToBeOffline', prompt: 'common.offlinePrompt'})); }); }); @@ -451,7 +457,7 @@ describe('useSearchBulkActions - Download receipts', () => { }); expect(exportReceiptsToZip).not.toHaveBeenCalled(); - expect(result.current.isOfflineModalVisible).toBe(true); + expect(mockShowDecisionModal).toHaveBeenCalledWith(expect.objectContaining({title: 'common.youAppearToBeOffline', prompt: 'common.offlinePrompt'})); }); }); }); diff --git a/tests/unit/hooks/useSearchBulkActionsExportTest.ts b/tests/unit/hooks/useSearchBulkActionsExportTest.ts index d3b6991c18d5..0e948567ee1e 100644 --- a/tests/unit/hooks/useSearchBulkActionsExportTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsExportTest.ts @@ -151,6 +151,12 @@ jest.mock('@hooks/useNetwork', () => ({ default: () => ({isOffline: mockIsOffline}), })); +const mockShowDecisionModal = jest.fn(); +jest.mock('@hooks/useDecisionModal', () => ({ + __esModule: true, + default: () => ({showDecisionModal: mockShowDecisionModal}), +})); + jest.mock('@hooks/useEnvironment', () => ({ __esModule: true, default: () => ({isProduction: true, isDevelopment: false, environment: 'production'}), @@ -1379,12 +1385,34 @@ describe('useSearchBulkActions - export options', () => { // Then: the offline modal opens and nothing is queued, matching bulk pay's offline behavior. await waitFor(() => { - expect(result.current.isOfflineModalVisible).toBe(true); + expect(mockShowDecisionModal).toHaveBeenCalledWith(expect.objectContaining({title: 'common.youAppearToBeOffline', prompt: 'common.offlinePrompt'})); }); expect(queueBulkMarkAsExported).not.toHaveBeenCalled(); expect(mockClearSelectedTransactions).not.toHaveBeenCalled(); }); + it('shows the empty-report download error with the empty report count when every selected report has no expenses', async () => { + // Given a selected report that the search snapshot says has no expenses, so there is nothing to export + mockCurrentSearchResults = makeSearchResults([{...makeSnapshotReport(), transactionCount: 0}]); + mockSelectedReports = [makeSelectedReport()]; + mockSelectedTransactions = {tx1: makeSelectedTransaction()}; + + const {result} = renderHook(() => useSearchBulkActions({queryJSON: expenseReportQueryJSON}), {wrapper: OnyxListItemProvider}); + + await waitFor(() => { + expect(getExportOptionByText(result.current.headerButtonsOptions, 'export.currentView')).toBeDefined(); + }); + + // When the user runs the Current view CSV export + getExportOptionByText(result.current.headerButtonsOptions, 'export.currentView')?.onSelected?.(); + + // Then the download error explains the reports are empty, because the prompt is passed when the modal is shown rather than read from shared state + await waitFor(() => { + expect(mockShowDecisionModal).toHaveBeenCalledWith(expect.objectContaining({title: 'common.downloadFailedTitle', prompt: 'common.downloadFailedEmptyReportDescription'})); + }); + expect(exportSearchItemsToCSV).not.toHaveBeenCalled(); + }); + it('marks the specific selected report IDs, not the search query, for a limited (non-select-all) selection', async () => { // Given: a finite selection of specific reports ("Select all" is NOT checked). mockAreAllMatchingItemsSelected = false; @@ -1701,7 +1729,7 @@ describe('useSearchBulkActions - export options', () => { // Then nothing is exported, because dropping groupBy without a cardID filter would export every card in the search await waitFor(() => { - expect(result.current.isDownloadErrorModalVisible).toBe(true); + expect(mockShowDecisionModal).toHaveBeenCalledWith(expect.objectContaining({title: 'common.downloadFailedTitle', prompt: 'common.downloadFailedDescription'})); }); expect(queueExportSearchWithTemplate).not.toHaveBeenCalled(); }); diff --git a/tests/unit/hooks/useSearchBulkActionsPayTest.ts b/tests/unit/hooks/useSearchBulkActionsPayTest.ts index 01a6d3bf7cc6..42039125021b 100644 --- a/tests/unit/hooks/useSearchBulkActionsPayTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsPayTest.ts @@ -124,6 +124,12 @@ jest.mock('@hooks/useNetwork', () => ({ default: () => ({isOffline: mockIsOffline}), })); +const mockShowDecisionModal = jest.fn(); +jest.mock('@hooks/useDecisionModal', () => ({ + __esModule: true, + default: () => ({showDecisionModal: mockShowDecisionModal}), +})); + jest.mock('@hooks/useEnvironment', () => ({ __esModule: true, default: () => ({isProduction: false, isDevelopment: true, environment: 'development'}), @@ -338,7 +344,7 @@ describe('useSearchBulkActions - Pay option', () => { }); // Then the offline modal should open and no payment should be triggered because payments must not be queued while offline - expect(result.current.isOfflineModalVisible).toBe(true); + expect(mockShowDecisionModal).toHaveBeenCalledWith(expect.objectContaining({title: 'common.youAppearToBeOffline', prompt: 'common.offlinePrompt'})); expect(payMoneyRequest).not.toHaveBeenCalled(); }); From 0a22005d0adb4bd9040335a2f80342c75921cfb5 Mon Sep 17 00:00:00 2001 From: "Yauheni Horbach (via MelvinBot)" Date: Fri, 9 Oct 2026 07:04:42 +0000 Subject: [PATCH 2/3] Separate decision modal helpers from the hooks below them Co-authored-by: Yauheni Horbach --- src/hooks/useSearchBulkActions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index 2a63602efbac..4aee583983c2 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -705,6 +705,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { secondOptionText: translate('common.buttonConfirm'), }); }, [showDecisionModal, translate]); + const openSearchReportSubmitToPopover = useOpenSearchReportSubmitToPopover(); const {showReportPDFDownloadModal} = useReportPDFDownloadModal(); const [isHoldEducationalModalVisible, setIsHoldEducationalModalVisible] = useState(false); From 931c484e75146a0addd6d35a5222851db7e6dd5f Mon Sep 17 00:00:00 2001 From: "Yauheni Horbach (via MelvinBot)" Date: Wed, 14 Oct 2026 10:09:08 +0000 Subject: [PATCH 3/3] Run export template actions after the popover menu hides Co-authored-by: Yauheni Horbach --- src/hooks/useSelectedTransactionsActions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hooks/useSelectedTransactionsActions.ts b/src/hooks/useSelectedTransactionsActions.ts index bd88e40df03f..904ab27f5107 100644 --- a/src/hooks/useSelectedTransactionsActions.ts +++ b/src/hooks/useSelectedTransactionsActions.ts @@ -466,6 +466,7 @@ function useSelectedTransactionsActions({ clearSelectedTransactions(true); } : () => beginExportWithTemplate(template.templateName, template.type, selectedTransactionIDs, template.name, template.policyID), + shouldCallAfterModalHide: true, addSeparatorBefore, }; };