From 2d320765edd9bbf87542dfdb6d22f2235a6a279f Mon Sep 17 00:00:00 2001 From: Yauheni Horbach <68128028+ZhenjaHorbach@users.noreply.github.com> Date: Fri, 24 Oct 2025 05:34:51 +0000 Subject: [PATCH 1/3] Revert "[CP Staging] Partially revert PR related to expense flow" --- src/pages/ReportDetailsPage.tsx | 37 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 13365796ef6e..5b4257e2d187 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -23,6 +23,7 @@ import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import {useSearchContext} from '@components/Search/SearchContext'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; +import useDeleteTransactions from '@hooks/useDeleteTransactions'; import useDuplicateTransactionsAndViolations from '@hooks/useDuplicateTransactionsAndViolations'; import useGetIOUReportFromReportAction from '@hooks/useGetIOUReportFromReportAction'; import useLocalize from '@hooks/useLocalize'; @@ -98,7 +99,7 @@ import { } from '@libs/ReportUtils'; import StringUtils from '@libs/StringUtils'; import {isDemoTransaction} from '@libs/TransactionUtils'; -import {deleteMoneyRequest, deleteTrackExpense, getNavigationUrlAfterTrackExpenseDelete, getNavigationUrlOnMoneyRequestDelete} from '@userActions/IOU'; +import {deleteTrackExpense, getNavigationUrlAfterTrackExpenseDelete, getNavigationUrlOnMoneyRequestDelete} from '@userActions/IOU'; import { clearAvatarErrors, clearPolicyRoomNameErrors, @@ -285,6 +286,12 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail const iouTransactionID = isMoneyRequestAction(requestParentReportAction) ? getOriginalMessage(requestParentReportAction)?.IOUTransactionID : undefined; const [iouTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${iouTransactionID}`, {canBeMissing: true}); const {duplicateTransactions, duplicateTransactionViolations} = useDuplicateTransactionsAndViolations(iouTransactionID ? [iouTransactionID] : []); + const {deleteTransactions} = useDeleteTransactions({ + report: parentReport, + reportActions: requestParentReportAction ? [requestParentReportAction] : [], + policy, + }); + const {currentSearchHash} = useSearchContext(); const isCardTransactionCanBeDeleted = canDeleteCardTransactionByLiabilityType(iouTransaction); const shouldShowDeleteButton = shouldShowTaskDeleteButton || (canDeleteRequest && isCardTransactionCanBeDeleted) || isDemoTransaction(iouTransaction); const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportsSelector}); @@ -805,35 +812,27 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail isChatReportArchived: isMoneyRequestReportArchived, isChatIOUReportArchived, }); - } else { - deleteMoneyRequest( - iouTransactionID, - requestParentReportAction, - duplicateTransactions, - duplicateTransactionViolations, - iouReport, - chatIOUReport, - isChatIOUReportArchived, - isSingleTransactionView, - undefined, - undefined, - ); + } else if (iouTransactionID) { + deleteTransactions([iouTransactionID], duplicateTransactions, duplicateTransactionViolations, currentSearchHash, isSingleTransactionView); removeTransaction(iouTransactionID); } }, [ - duplicateTransactions, - duplicateTransactionViolations, caseID, + requestParentReportAction, + report, + isReportArchived, + currentUserPersonalDetails.accountID, iouTransactionID, + duplicateTransactions, + duplicateTransactionViolations, isSingleTransactionView, moneyRequestReport, removeTransaction, - report, - requestParentReportAction, - isReportArchived, isMoneyRequestReportArchived, iouReport, chatIOUReport, + deleteTransactions, + currentSearchHash, isChatIOUReportArchived, ]); From aa9d6ff8b506901adf6db6fbc4adeca26418d960 Mon Sep 17 00:00:00 2001 From: Yauheni Horbach Date: Fri, 24 Oct 2025 08:18:20 +0200 Subject: [PATCH 2/3] Fix issue with broken navigation --- src/pages/ReportDetailsPage.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 5b4257e2d187..a285aac6fa95 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -36,6 +36,7 @@ import useReportIsArchived from '@hooks/useReportIsArchived'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import getBase62ReportID from '@libs/getBase62ReportID'; +import setNavigationActionToMicrotaskQueue from '@libs/Navigation/helpers/setNavigationActionToMicrotaskQueue'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {ReportDetailsNavigatorParamList} from '@libs/Navigation/types'; @@ -852,12 +853,6 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail // Where to navigate back to after deleting the transaction and its report. const navigateToTargetUrl = useCallback(() => { - // If transaction was not deleted (i.e. Cancel was clicked), do nothing - // which only dismiss the delete confirmation modal - if (!isTransactionDeleted.current) { - return; - } - let urlToNavigateBack: string | undefined; // Only proceed with navigation logic if transaction was actually deleted @@ -892,7 +887,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail setDeleteTransactionNavigateBackUrl(urlToNavigateBack); navigateBackOnDeleteTransaction(urlToNavigateBack as Route, true); } - }, [iouTransactionID, requestParentReportAction, isSingleTransactionView, isTransactionDeleted, moneyRequestReport, isChatIOUReportArchived, iouReport, chatIOUReport]); + }, [iouTransactionID, requestParentReportAction, isSingleTransactionView, moneyRequestReport, isChatIOUReportArchived, iouReport, chatIOUReport]); const mentionReportContextValue = useMemo(() => ({currentReportID: report.reportID, exactlyMatch: true}), [report.reportID]); @@ -998,6 +993,9 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail onConfirm={() => { setIsDeleteModalVisible(false); isTransactionDeleted.current = true; + setNavigationActionToMicrotaskQueue(() => { + navigateToTargetUrl(); + }); }} onCancel={() => setIsDeleteModalVisible(false)} prompt={caseID === CASES.DEFAULT ? translate('task.deleteConfirmation') : translate('iou.deleteConfirmation', {count: 1})} @@ -1005,7 +1003,6 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail cancelText={translate('common.cancel')} danger shouldEnableNewFocusManagement - onModalHide={navigateToTargetUrl} /> From 134d41911e01de874e4fa832e33a8974d6cb1dc9 Mon Sep 17 00:00:00 2001 From: Yauheni Horbach Date: Fri, 24 Oct 2025 08:43:36 +0200 Subject: [PATCH 3/3] Improve fix --- src/pages/ReportDetailsPage.tsx | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index a285aac6fa95..d84ff052ee21 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -36,7 +36,6 @@ import useReportIsArchived from '@hooks/useReportIsArchived'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import getBase62ReportID from '@libs/getBase62ReportID'; -import setNavigationActionToMicrotaskQueue from '@libs/Navigation/helpers/setNavigationActionToMicrotaskQueue'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {ReportDetailsNavigatorParamList} from '@libs/Navigation/types'; @@ -837,20 +836,6 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail isChatIOUReportArchived, ]); - // A flag to indicate whether the user chose to delete the transaction or not - const isTransactionDeleted = useRef(false); - - useEffect(() => { - return () => { - // Perform the actual deletion after the details page is unmounted. This prevents the [Deleted ...] text from briefly appearing when dismissing the modal. - if (!isTransactionDeleted.current) { - return; - } - isTransactionDeleted.current = false; - deleteTransaction(); - }; - }, [deleteTransaction]); - // Where to navigate back to after deleting the transaction and its report. const navigateToTargetUrl = useCallback(() => { let urlToNavigateBack: string | undefined; @@ -889,6 +874,21 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail } }, [iouTransactionID, requestParentReportAction, isSingleTransactionView, moneyRequestReport, isChatIOUReportArchived, iouReport, chatIOUReport]); + // A flag to indicate whether the user chose to delete the transaction or not + const isTransactionDeleted = useRef(false); + + useEffect(() => { + return () => { + // Perform the actual deletion after the details page is unmounted. This prevents the [Deleted ...] text from briefly appearing when dismissing the modal. + if (!isTransactionDeleted.current) { + return; + } + isTransactionDeleted.current = false; + navigateToTargetUrl(); + deleteTransaction(); + }; + }, [deleteTransaction, navigateToTargetUrl]); + const mentionReportContextValue = useMemo(() => ({currentReportID: report.reportID, exactlyMatch: true}), [report.reportID]); return ( @@ -993,9 +993,6 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail onConfirm={() => { setIsDeleteModalVisible(false); isTransactionDeleted.current = true; - setNavigationActionToMicrotaskQueue(() => { - navigateToTargetUrl(); - }); }} onCancel={() => setIsDeleteModalVisible(false)} prompt={caseID === CASES.DEFAULT ? translate('task.deleteConfirmation') : translate('iou.deleteConfirmation', {count: 1})}