Skip to content
Closed
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
55 changes: 24 additions & 31 deletions src/libs/actions/IOU/SplitTransactionUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,15 @@ function updateSplitTransactionsFromSplitExpensesFlow(params: UpdateSplitTransac
const transactionThreadReportID = params.firstIOU?.childReportID;
const transactionThreadReportScreen = Navigation.getReportRouteByID(transactionThreadReportID);

const removeTransactionThreadReportScreen = () => {
requestAnimationFrame(() => {
if (!transactionThreadReportScreen?.key) {
return;
}
Navigation.removeScreenByKey(transactionThreadReportScreen.key);
});
};

// Reset selected transactions in search after saving split expenses
const searchFullScreenRoutes = navigationRef.getRootState()?.routes.findLast((route) => route.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR);
const lastRoute = searchFullScreenRoutes?.state?.routes?.at(-1);
Expand All @@ -1893,38 +1902,30 @@ function updateSplitTransactionsFromSplitExpensesFlow(params: UpdateSplitTransac
params?.searchContext?.clearSelectedTransactions?.(true);
}

if (isSearchPageTopmostFullScreenRoute || !params.transactionReport?.parentReportID) {
if (!isSelfDMSplit) {
Navigation.navigateBackToLastSuperWideRHPScreen();
}

// After the modal is dismissed, remove the transaction thread report screen
// to avoid navigating back to a report removed by the split transaction.
requestAnimationFrame(() => {
if (!transactionThreadReportScreen?.key) {
return;
}

Navigation.removeScreenByKey(transactionThreadReportScreen.key);
});
if (isSearchPageTopmostFullScreenRoute) {
Navigation.navigateBackToLastSuperWideRHPScreen();
removeTransactionThreadReportScreen();

return;
}

// When the reverse split deletes the expense report, use the backward navigation pattern
// When the update deletes the expense report (reverse split or removing the last child after
// a sibling was moved to a submitted 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);
removeTransactionThreadReportScreen();

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

if (!params.transactionReport?.parentReportID) {
if (!isSelfDMSplit) {
Navigation.navigateBackToLastSuperWideRHPScreen();
}
removeTransactionThreadReportScreen();

return;
}
Expand All @@ -1935,15 +1936,7 @@ function updateSplitTransactionsFromSplitExpensesFlow(params: UpdateSplitTransac
setPendingSubmitFollowUpAction(CONST.TELEMETRY.SUBMIT_FOLLOW_UP_ACTION.DISMISS_MODAL_AND_OPEN_REPORT, targetReportID);
}
Navigation.dismissModalWithReport({reportID: targetReportID});

// After the modal is dismissed, remove the transaction thread report screen
// to avoid navigating back to a report removed by the split transaction.
requestAnimationFrame(() => {
if (!transactionThreadReportScreen?.key) {
return;
}
Navigation.removeScreenByKey(transactionThreadReportScreen.key);
});
removeTransactionThreadReportScreen();
}

export {updateSplitTransactions, updateSplitTransactionsFromSplitExpensesFlow};
4 changes: 2 additions & 2 deletions tests/actions/IOUTest/SplitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2701,7 +2701,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => {
transactionData: {
reportID: reportID1,
originalTransactionID: originalTransaction.transactionID,
splitExpenses: [{transactionID: childTransaction.transactionID, amount: 10000, created: DateUtils.getDBTime()}],
splitExpenses: [{transactionID: childTransaction.transactionID, amount: 10000, created: DateUtils.getDBTime(), reportID: reportID1}],
splitExpensesTotal: undefined,
},
searchContext: {
Expand Down Expand Up @@ -2836,7 +2836,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => {
transactionData: {
reportID: reportID2,
originalTransactionID: originalTransaction.transactionID,
splitExpenses: [{transactionID: childTransaction.transactionID, amount: 10000, created: DateUtils.getDBTime()}],
splitExpenses: [{transactionID: childTransaction.transactionID, amount: 10000, created: DateUtils.getDBTime(), reportID: reportID2}],
splitExpensesTotal: undefined,
},
searchContext: {
Expand Down
Loading