Skip to content
Merged
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
23 changes: 20 additions & 3 deletions src/libs/actions/IOU/Split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
hasViolations as hasViolationsReportUtils,
isArchivedReport,
isPolicyExpenseChat as isPolicyExpenseChatReportUtil,
navigateBackOnDeleteTransaction,
shouldCreateNewMoneyRequestReport as shouldCreateNewMoneyRequestReportReportUtils,
updateReportPreview,
} from '@libs/ReportUtils';
Expand Down Expand Up @@ -1743,8 +1744,25 @@ function updateSplitTransactionsFromSplitExpensesFlow(params: UpdateSplitTransac
return;
}

// If the expense report was deleted by the reverse split, navigate to the parent chat instead
const targetReportID = isLastTransactionInReport && fallbackReportID ? fallbackReportID : (params.expenseReport?.reportID ?? String(CONST.DEFAULT_NUMBER_ID));
// When the reverse split deletes the expense report, use the backward navigation pattern
// (dismissToSuperWideRHP + goBack) instead of dismissModalWithReport. This naturally pops
// stale screens from the stack instead of leaving them behind.
if (isLastTransactionInReport && fallbackReportID) {
const backRoute = ROUTES.REPORT_WITH_ID.getRoute(fallbackReportID);
navigateBackOnDeleteTransaction(backRoute);

// Remove the transaction thread report screen to avoid navigating back to a removed report
requestAnimationFrame(() => {
if (!transactionThreadReportScreen?.key) {
return;
}
Navigation.removeScreenByKey(transactionThreadReportScreen.key);
});

return;
}

const targetReportID = params.expenseReport?.reportID ?? String(CONST.DEFAULT_NUMBER_ID);

if (getSpan(CONST.TELEMETRY.SPAN_SUBMIT_TO_DESTINATION_VISIBLE)) {
setPendingSubmitFollowUpAction(CONST.TELEMETRY.SUBMIT_FOLLOW_UP_ACTION.DISMISS_MODAL_AND_OPEN_REPORT, targetReportID);
Expand All @@ -1757,7 +1775,6 @@ function updateSplitTransactionsFromSplitExpensesFlow(params: UpdateSplitTransac
if (!transactionThreadReportScreen?.key) {
return;
}

Navigation.removeScreenByKey(transactionThreadReportScreen.key);
});
}
Expand Down
12 changes: 9 additions & 3 deletions tests/actions/IOUTest/SplitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2267,7 +2267,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => {
expect(isDeleted).toBe(true);
});

it('should set navigate-back URL and navigate to parent chat when reverse-split deletes the last transaction in expense report', async () => {
it('should set navigate-back URL and use backward navigation pattern when reverse-split deletes the last transaction in expense report', async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const Navigation = jest.requireMock('@src/libs/Navigation/Navigation');
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand All @@ -2285,6 +2285,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => {
chatReportID: chatReport.reportID,
parentReportID: chatReport.reportID,
};

const originalTransaction: Transaction = {
amount: 10000,
currency: 'USD',
Expand Down Expand Up @@ -2383,9 +2384,14 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(Report.setDeleteTransactionNavigateBackUrl).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(chatReport.reportID));

// Then navigation should go to the parent chat report instead of the deleted expense report
// Then navigateBackOnDeleteTransaction should be used (which calls dismissToSuperWideRHP + goBack)
// instead of dismissModalWithReport
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(Navigation.dismissToSuperWideRHP).toHaveBeenCalled();
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(Navigation.goBack).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(chatReport.reportID));
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(Navigation.dismissModalWithReport).toHaveBeenCalledWith({reportID: chatReport.reportID});
expect(Navigation.dismissModalWithReport).not.toHaveBeenCalled();
});

it('should navigate to expense report normally when reverse-split is not the last transaction', async () => {
Expand Down
Loading