Skip to content
Open
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
35 changes: 32 additions & 3 deletions src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {confirmReadyToOpenApp} from '@libs/actions/App';
import {setupMergeTransactionDataAndNavigate} from '@libs/actions/MergeTransaction';
import {moveIOUReportToPolicy, moveIOUReportToPolicyAndInviteSubmitter, searchInServer} from '@libs/actions/Report';
import {deleteAppReport, moveIOUReportToPolicy, moveIOUReportToPolicyAndInviteSubmitter, searchInServer} from '@libs/actions/Report';
import {
approveMoneyRequestOnSearch,
deleteMoneyRequestOnSearch,
Expand All @@ -61,6 +61,7 @@ import {
import {setTransactionReport} from '@libs/actions/Transaction';
import {setNameValuePair} from '@libs/actions/User';
import {navigateToParticipantPage} from '@libs/IOUUtils';
import Log from '@libs/Log';
import {getTransactionsAndReportsFromSearch} from '@libs/MergeTransactionUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
Expand Down Expand Up @@ -437,6 +438,8 @@ function SearchPage({route}: SearchPageProps) {
return;
}

const isExpenseReportType = queryJSON?.type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT;

// Use InteractionManager to ensure this runs after the dropdown modal closes
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(async () => {
Expand All @@ -452,13 +455,39 @@ function SearchPage({route}: SearchPageProps) {
}
// Translations copy for delete modal depends on amount of selected items,
// We need to wait for modal to fully disappear before clearing them to avoid translation flicker between singular vs plural
const validTransactions = Object.fromEntries(Object.entries(allTransactions ?? {}).filter((entry): entry is [string, Transaction] => entry[1] !== undefined));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const validTransactions = Object.fromEntries(Object.entries(allTransactions ?? {}).filter((entry): entry is [string, Transaction] => entry[1] !== undefined));
const validTransactions = Object.fromEntries(Object.entries(allTransactions ?? {}).filter(([, value]): value is Transaction => value != null));

Will this be better?

// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => {
deleteMoneyRequestOnSearch(hash, selectedTransactionsKeys);
if (isExpenseReportType) {
// For expense reports, call deleteAppReport which properly un-reports the expenses
for (const reportID of selectedReportIDs) {
try {
deleteAppReport(reportID, currentUserPersonalDetails?.login ?? '', validTransactions, allTransactionViolations, bankAccountList);
} catch (error) {
Log.warn('[SearchPage] Failed to delete expense report', {error});
}
}
} else {
// For individual expenses, delete the transactions
deleteMoneyRequestOnSearch(hash, selectedTransactionsKeys);
}
clearSelectedTransactions();
});
});
}, [isOffline, showConfirmModal, translate, selectedTransactionsKeys, hash, clearSelectedTransactions]);
}, [
isOffline,
showConfirmModal,
translate,
selectedTransactionsKeys,
hash,
clearSelectedTransactions,
queryJSON?.type,
selectedReportIDs,
currentUserPersonalDetails?.login,
allTransactions,
allTransactionViolations,
bankAccountList,
]);

const onBulkPaySelected = useCallback(
(paymentMethod?: PaymentMethodType, additionalData?: Record<string, unknown>) => {
Expand Down
Loading