Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,12 @@ function dismissModal({ref = navigationRef, afterTransition, waitForTransition}:
* For detailed information about dismissing modals,
* see the NAVIGATION.md documentation.
* @param options.onBeforeNavigate - Called before performing navigation with whether the report will be opened (true) or we only dismiss because already on that report (false).
* @param options.forceReplace - If true, the report is opened by replacing the topmost report screen instead of pushing on top of it. Use this when the screen we dismiss back onto has been deleted (e.g. after merging its only expense away), so it is removed from the stack instead of lingering underneath and flashing a "not found" page when the user taps back.
*/
const dismissModalWithReport = (
{reportID, reportActionID, referrer, backTo}: ReportsSplitNavigatorParamList[typeof SCREENS.REPORT],
ref = navigationRef,
options?: {onBeforeNavigate?: (willOpenReport: boolean) => void; afterTransition?: () => void},
options?: {onBeforeNavigate?: (willOpenReport: boolean) => void; afterTransition?: () => void; forceReplace?: boolean},
) => {
const dismissAndOpenReport = () => {
const topmostSuperWideRHPReportID = getTopmostSuperWideRHPReportID();
Expand All @@ -921,7 +922,7 @@ const dismissModalWithReport = (
const reportRoute = ROUTES.REPORT_WITH_ID.getRoute(reportID, reportActionID, referrer, backTo);
dismissModal({
afterTransition: () => {
navigate(reportRoute, {afterTransition: options?.afterTransition});
navigate(reportRoute, {afterTransition: options?.afterTransition, forceReplace: options?.forceReplace});
},
});
};
Expand Down
10 changes: 8 additions & 2 deletions src/pages/TransactionMerge/DynamicConfirmationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTop
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {MergeTransactionNavigatorParamList} from '@libs/Navigation/types';
import {findSelfDMReportID} from '@libs/ReportUtils';
import {findSelfDMReportID, getReportTransactions} from '@libs/ReportUtils';
import type {SkeletonSpanReasonAttributes} from '@libs/telemetry/useSkeletonSpan';

import CONST from '@src/CONST';
Expand Down Expand Up @@ -87,6 +87,12 @@ function DynamicConfirmationPage({route}: DynamicConfirmationPageProps) {
}
const reportID = mergeTransaction.reportID === CONST.REPORT.UNREPORTED_REPORT_ID ? (findSelfDMReportID() ?? CONST.REPORT.UNREPORTED_REPORT_ID) : mergeTransaction.reportID;

// When the surviving expense is moved off its original report and that report held only this one expense,
// mergeTransactionRequest optimistically deletes the report. Capture that here (before the optimistic update runs)
// so we can replace the now-deleted report screen instead of pushing on top of it — otherwise the stale screen
// lingers in the stack and briefly flashes the "not found" page when the user taps back. Must be read pre-merge.
const willDeleteTargetTransactionReport = getReportTransactions(targetTransaction.reportID).length === 1;

setIsMergingExpenses(true);

mergeTransactionRequest({
Expand Down Expand Up @@ -126,7 +132,7 @@ function DynamicConfirmationPage({route}: DynamicConfirmationPageProps) {
}

if (reportIDToDismiss && reportID !== targetTransaction.reportID) {
Navigation.dismissModalWithReport({reportID: reportIDToDismiss});
Navigation.dismissModalWithReport({reportID: reportIDToDismiss}, undefined, {forceReplace: willDeleteTargetTransactionReport});
return;
}

Expand Down
Loading