From ce0b3268b834af6dd3e0b1857a3b9e462d6236ad Mon Sep 17 00:00:00 2001 From: Maruf Sharifi Date: Mon, 13 Apr 2026 22:20:29 +0430 Subject: [PATCH 1/3] fix: correct Audit Reports navigation and prioritize report routes --- .../ReportActionItem/MoneyRequestAction.tsx | 5 +++-- .../ReportActionItem/TaskPreview.tsx | 4 ++-- .../getReportRouteForCurrentContext.ts | 22 +++++++++++++++++++ src/libs/actions/Report/index.ts | 16 +++++++++++--- src/libs/actions/Task.ts | 7 +++++- src/pages/ReportDetailsPage.tsx | 7 +++--- src/pages/inbox/ReportNavigateAwayHandler.tsx | 5 +++++ src/pages/tasks/TaskAssigneeSelectorModal.tsx | 9 ++++++++ src/pages/tasks/TaskDescriptionPage.tsx | 10 +++++++++ src/pages/tasks/TaskTitlePage.tsx | 10 +++++++++ 10 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 src/libs/Navigation/helpers/getReportRouteForCurrentContext.ts diff --git a/src/components/ReportActionItem/MoneyRequestAction.tsx b/src/components/ReportActionItem/MoneyRequestAction.tsx index 41d5249a7fbb..be2756832a87 100644 --- a/src/components/ReportActionItem/MoneyRequestAction.tsx +++ b/src/components/ReportActionItem/MoneyRequestAction.tsx @@ -10,6 +10,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; import {createTransactionThreadReport} from '@libs/actions/Report'; +import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {TransactionDuplicateNavigatorParamList} from '@libs/Navigation/types'; @@ -124,7 +125,7 @@ function MoneyRequestAction({ Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: transactionThreadReport?.reportID, backTo: Navigation.getActiveRoute()})); return; } - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(transactionThreadReport?.reportID, undefined, undefined, Navigation.getActiveRoute())); + Navigation.navigate(getReportRouteForCurrentContext({reportID: transactionThreadReport?.reportID})); return; } @@ -133,7 +134,7 @@ function MoneyRequestAction({ return; } - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(action?.childReportID, undefined, undefined, Navigation.getActiveRoute())); + Navigation.navigate(getReportRouteForCurrentContext({reportID: action?.childReportID})); }; const isDeletedParentAction = isDeletedParentActionReportActionsUtils(action); diff --git a/src/components/ReportActionItem/TaskPreview.tsx b/src/components/ReportActionItem/TaskPreview.tsx index bea2c312ac95..20ef4123b6b7 100644 --- a/src/components/ReportActionItem/TaskPreview.tsx +++ b/src/components/ReportActionItem/TaskPreview.tsx @@ -26,12 +26,12 @@ import {canActionTask, completeTask, getTaskAssigneeAccountID, reopenTask} from import ControlSelection from '@libs/ControlSelection'; import {canUseTouchScreen} from '@libs/DeviceCapabilities'; import getButtonState from '@libs/getButtonState'; +import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext'; import Navigation from '@libs/Navigation/Navigation'; import Parser from '@libs/Parser'; import {isCanceledTaskReport, isOpenTaskReport, isReportManager} from '@libs/ReportUtils'; import type {ContextMenuAnchor} from '@pages/inbox/report/ContextMenu/ReportActionContextMenu'; import CONST from '@src/CONST'; -import ROUTES from '@src/ROUTES'; import type {Report, ReportAction} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; @@ -138,7 +138,7 @@ function TaskPreview({ return ( Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(taskReportID, undefined, undefined, Navigation.getActiveRoute()))} + onPress={() => Navigation.navigate(getReportRouteForCurrentContext({reportID: taskReportID}))} onPressIn={() => canUseTouchScreen() && ControlSelection.block()} onPressOut={() => ControlSelection.unblock()} onLongPress={(event) => diff --git a/src/libs/Navigation/helpers/getReportRouteForCurrentContext.ts b/src/libs/Navigation/helpers/getReportRouteForCurrentContext.ts new file mode 100644 index 000000000000..5b91b981db24 --- /dev/null +++ b/src/libs/Navigation/helpers/getReportRouteForCurrentContext.ts @@ -0,0 +1,22 @@ +import Navigation from '@libs/Navigation/Navigation'; +import ROUTES from '@src/ROUTES'; +import type {Route} from '@src/ROUTES'; +import isSearchTopmostFullScreenRoute from './isSearchTopmostFullScreenRoute'; + +type GetReportRouteForCurrentContextParams = { + reportID: string | undefined; + reportActionID?: string; + backTo?: Route; +}; + +function getReportRouteForCurrentContext({reportID, reportActionID, backTo}: GetReportRouteForCurrentContextParams): Route { + const currentRoute = backTo ?? (Navigation.getActiveRoute() as Route); + + if (isSearchTopmostFullScreenRoute()) { + return ROUTES.SEARCH_REPORT.getRoute({reportID, reportActionID, backTo: currentRoute}); + } + + return ROUTES.REPORT_WITH_ID.getRoute(reportID, reportActionID, undefined, currentRoute); +} + +export default getReportRouteForCurrentContext; diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index da6c106c15aa..f9455e94d3b0 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -77,6 +77,7 @@ import HttpUtils from '@libs/HttpUtils'; import Log from '@libs/Log'; import {isEmailPublicDomain} from '@libs/LoginUtils'; import {getMovedReportID} from '@libs/ModifiedExpenseMessage'; +import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext'; import type {LinkToOptions} from '@libs/Navigation/helpers/linkTo/types'; import Navigation from '@libs/Navigation/Navigation'; import enhanceParameters from '@libs/Network/enhanceParameters'; @@ -195,6 +196,7 @@ import type {OnboardingAccounting} from '@src/CONST'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import type {Route} from '@src/ROUTES'; import INPUT_IDS from '@src/types/form/NewRoomForm'; import type { AnyRequest, @@ -2073,7 +2075,7 @@ function navigateToAndOpenChildReport( ) { const report = childReport ?? createChildReport(childReport, parentReportAction, parentReport, currentUserAccountID, introSelected, betas); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID, undefined, undefined, Navigation.getActiveRoute())); + Navigation.navigate(getReportRouteForCurrentContext({reportID: report.reportID})); } /** @@ -4297,7 +4299,13 @@ function navigateToMostRecentReport( currentUserAccountID: number, introSelected: OnyxEntry, betas: OnyxEntry, + backTo?: Route, ) { + if (backTo) { + Navigation.goBack(backTo); + return; + } + const lastAccessedReportID = findLastAccessedReport(false, false, currentReport?.reportID)?.reportID; if (lastAccessedReportID) { @@ -4349,6 +4357,7 @@ function leaveGroupChat( conciergeReportID: string | undefined, introSelected: OnyxEntry, betas: OnyxEntry, + backTo?: Route, ) { const reportID = report.reportID; // Use merge instead of set to avoid deleting the report too quickly, which could cause a brief "not found" page to appear. @@ -4396,7 +4405,7 @@ function leaveGroupChat( }, ]; - navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID, introSelected, betas); + navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID, introSelected, betas, backTo); API.write(WRITE_COMMANDS.LEAVE_GROUP_CHAT, {reportID}, {optimisticData, successData, failureData}); } @@ -4408,6 +4417,7 @@ function leaveRoom( introSelected: OnyxEntry, betas: OnyxEntry, isWorkspaceMemberLeavingWorkspaceRoom = false, + backTo?: Route, ) { const reportID = report.reportID; const isChatThread = isChatThreadReportUtils(report); @@ -4512,7 +4522,7 @@ function leaveRoom( return; } // In other cases, the report is deleted and we should move the user to another report. - navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID, introSelected, betas); + navigateToMostRecentReport(report, conciergeReportID, currentUserAccountID, introSelected, betas, backTo); } function buildInviteToRoomOnyxData(report: Report, inviteeEmailsToAccountIDs: InvitedEmailsToAccountIDs, formatPhoneNumber: LocaleContextProps['formatPhoneNumber']) { diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index c4443ca09185..b86c5d07d069 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -9,6 +9,7 @@ import {WRITE_COMMANDS} from '@libs/API/types'; import DateUtils from '@libs/DateUtils'; import * as ErrorUtils from '@libs/ErrorUtils'; import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import NetworkConnection from '@libs/NetworkConnection'; import * as OptionsListUtils from '@libs/OptionsListUtils'; @@ -375,7 +376,11 @@ function createTaskAndNavigate(params: CreateTaskAndNavigateParams) { InteractionManager.runAfterInteractions(() => { clearOutTaskInfo(); }); - Navigation.dismissModalWithReport({reportID: parentReportID}); + if (isSearchTopmostFullScreenRoute()) { + Navigation.dismissModal(); + } else { + Navigation.dismissModalWithReport({reportID: parentReportID}); + } } notifyNewAction(parentReportID, optimisticAddCommentReport.reportAction, true); } diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index cda278b983ad..381812df118e 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -332,13 +332,13 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail const leaveChat = useCallback(() => { if (isRootGroupChat) { - leaveGroupChat(report, quickAction?.chatReportID?.toString() === report.reportID, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas); + leaveGroupChat(report, quickAction?.chatReportID?.toString() === report.reportID, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas, backTo); return; } const isWorkspaceMemberLeavingWorkspaceRoom = isWorkspaceMemberLeavingWorkspaceRoomUtil(report, isPolicyEmployee, isPolicyAdmin); - leaveRoom(report, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas, isWorkspaceMemberLeavingWorkspaceRoom); - }, [isRootGroupChat, isPolicyEmployee, isPolicyAdmin, quickAction?.chatReportID, report, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas]); + leaveRoom(report, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas, isWorkspaceMemberLeavingWorkspaceRoom, backTo); + }, [isRootGroupChat, isPolicyEmployee, isPolicyAdmin, quickAction?.chatReportID, report, currentUserPersonalDetails.accountID, conciergeReportID, introSelected, betas, backTo]); const showLastMemberLeavingModal = useCallback(async () => { const {action} = await showConfirmModal({ @@ -632,6 +632,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail iouTransactionID, moneyRequestReport?.reportID, currentUserPersonalDetails.accountID, + currentUserPersonalDetails.email, isTaskActionable, isRootGroupChat, leaveChat, diff --git a/src/pages/inbox/ReportNavigateAwayHandler.tsx b/src/pages/inbox/ReportNavigateAwayHandler.tsx index 1022dcab9fe9..696658039ca3 100644 --- a/src/pages/inbox/ReportNavigateAwayHandler.tsx +++ b/src/pages/inbox/ReportNavigateAwayHandler.tsx @@ -8,6 +8,7 @@ import useParentReportAction from '@hooks/useParentReportAction'; import usePrevious from '@hooks/usePrevious'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import {isDeletedParentAction} from '@libs/ReportActionsUtils'; @@ -204,6 +205,10 @@ function ReportNavigateAwayHandler() { // Fallback to Concierge Navigation.isNavigationReady().then(() => { + if (isSearchTopmostFullScreenRoute()) { + Navigation.dismissModal(); + return; + } navigateToConciergeChat(conciergeReportID, introSelected, currentUserAccountID, isSelfTourViewed, betas); }); }, [reportWasDeleted, isFocused, deletedReportParentID, conciergeReportID, introSelected, currentUserAccountID, isSelfTourViewed, betas]); diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index 3ca48090f11a..1f902538adc9 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -24,6 +24,7 @@ import {searchUserInServer} from '@libs/actions/Report'; import {canModifyTask, editTaskAssignee, setAssigneeValue} from '@libs/actions/Task'; import {READ_COMMANDS} from '@libs/API/types'; import HttpUtils from '@libs/HttpUtils'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import {getHeaderMessage, isCurrentUser} from '@libs/OptionsListUtils'; @@ -88,6 +89,10 @@ function TaskAssigneeSelectorModal() { const reportOnyx = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${route.params?.reportID}`]; if (reportOnyx && !isTaskReport(reportOnyx)) { Navigation.isNavigationReady().then(() => { + if (isSearchTopmostFullScreenRoute()) { + Navigation.dismissModal(); + return; + } Navigation.dismissModalWithReport({reportID: reportOnyx.reportID}); }); } @@ -184,6 +189,10 @@ function TaskAssigneeSelectorModal() { } // eslint-disable-next-line @typescript-eslint/no-deprecated InteractionManager.runAfterInteractions(() => { + if (isSearchTopmostFullScreenRoute()) { + Navigation.dismissModal(); + return; + } Navigation.dismissModalWithReport({reportID: report?.reportID}); }); // If there's no report, we're creating a new task diff --git a/src/pages/tasks/TaskDescriptionPage.tsx b/src/pages/tasks/TaskDescriptionPage.tsx index 7c15678b12f4..f0f70ff757bc 100644 --- a/src/pages/tasks/TaskDescriptionPage.tsx +++ b/src/pages/tasks/TaskDescriptionPage.tsx @@ -17,6 +17,7 @@ import useOnyx from '@hooks/useOnyx'; import useReportIsArchived from '@hooks/useReportIsArchived'; import useThemeStyles from '@hooks/useThemeStyles'; import {addErrorMessage} from '@libs/ErrorUtils'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {ReportDescriptionNavigatorParamList} from '@libs/Navigation/types'; @@ -62,6 +63,11 @@ function TaskDescriptionPage({report, currentUserPersonalDetails}: TaskDescripti editTask(report, {description: values.description}, delegateEmail); } + if (isSearchTopmostFullScreenRoute()) { + Navigation.dismissModal(); + return; + } + Navigation.dismissModalWithReport({reportID: report?.reportID}); }, [report, delegateEmail], @@ -69,6 +75,10 @@ function TaskDescriptionPage({report, currentUserPersonalDetails}: TaskDescripti if (!isTaskReport(report)) { Navigation.isNavigationReady().then(() => { + if (isSearchTopmostFullScreenRoute()) { + Navigation.dismissModal(); + return; + } Navigation.dismissModalWithReport({reportID: report?.reportID}); }); } diff --git a/src/pages/tasks/TaskTitlePage.tsx b/src/pages/tasks/TaskTitlePage.tsx index 0dd7c78efcc3..3e549e4d2e69 100644 --- a/src/pages/tasks/TaskTitlePage.tsx +++ b/src/pages/tasks/TaskTitlePage.tsx @@ -17,6 +17,7 @@ import useOnyx from '@hooks/useOnyx'; import useReportIsArchived from '@hooks/useReportIsArchived'; import useThemeStyles from '@hooks/useThemeStyles'; import {addErrorMessage} from '@libs/ErrorUtils'; +import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {TaskDetailsNavigatorParamList} from '@libs/Navigation/types'; @@ -67,6 +68,11 @@ function TaskTitlePage({report, currentUserPersonalDetails}: TaskTitlePageProps) editTask(report, {title: values.title}, delegateEmail); } + if (isSearchTopmostFullScreenRoute()) { + Navigation.dismissModal(); + return; + } + Navigation.dismissModalWithReport({reportID: report?.reportID}); }, [report, delegateEmail], @@ -74,6 +80,10 @@ function TaskTitlePage({report, currentUserPersonalDetails}: TaskTitlePageProps) if (!isTaskReport(report)) { Navigation.isNavigationReady().then(() => { + if (isSearchTopmostFullScreenRoute()) { + Navigation.dismissModal(); + return; + } Navigation.dismissModalWithReport({reportID: report?.reportID}); }); } From 28cc6569609ac13053abe3dfd12ae5fdf00f43d1 Mon Sep 17 00:00:00 2001 From: marufsharifi Date: Tue, 14 Apr 2026 14:24:19 +0430 Subject: [PATCH 2/3] Refactor task modal dismiss logic into shared helper --- .../helpers/dismissModalForCurrentContext.ts | 18 ++++++++++++++++++ src/libs/actions/Task.ts | 8 ++------ src/pages/tasks/TaskAssigneeSelectorModal.tsx | 14 +++----------- src/pages/tasks/TaskDescriptionPage.tsx | 15 +++------------ src/pages/tasks/TaskTitlePage.tsx | 15 +++------------ 5 files changed, 29 insertions(+), 41 deletions(-) create mode 100644 src/libs/Navigation/helpers/dismissModalForCurrentContext.ts diff --git a/src/libs/Navigation/helpers/dismissModalForCurrentContext.ts b/src/libs/Navigation/helpers/dismissModalForCurrentContext.ts new file mode 100644 index 000000000000..13251710862b --- /dev/null +++ b/src/libs/Navigation/helpers/dismissModalForCurrentContext.ts @@ -0,0 +1,18 @@ +import Navigation from '@libs/Navigation/Navigation'; +import isSearchTopmostFullScreenRoute from './isSearchTopmostFullScreenRoute'; + +function dismissModalForCurrentContext(reportID?: string) { + if (isSearchTopmostFullScreenRoute()) { + Navigation.dismissModal(); + return; + } + + if (!reportID) { + Navigation.dismissModal(); + return; + } + + Navigation.dismissModalWithReport({reportID}); +} + +export default dismissModalForCurrentContext; diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 02c3fef94988..d9828633a184 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -9,7 +9,7 @@ import {WRITE_COMMANDS} from '@libs/API/types'; import DateUtils from '@libs/DateUtils'; import * as ErrorUtils from '@libs/ErrorUtils'; import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; -import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; +import dismissModalForCurrentContext from '@libs/Navigation/helpers/dismissModalForCurrentContext'; import Navigation from '@libs/Navigation/Navigation'; import NetworkConnection from '@libs/NetworkConnection'; import * as OptionsListUtils from '@libs/OptionsListUtils'; @@ -376,11 +376,7 @@ function createTaskAndNavigate(params: CreateTaskAndNavigateParams) { InteractionManager.runAfterInteractions(() => { clearOutTaskInfo(); }); - if (isSearchTopmostFullScreenRoute()) { - Navigation.dismissModal(); - } else { - Navigation.dismissModalWithReport({reportID: parentReportID}); - } + dismissModalForCurrentContext(parentReportID); } notifyNewAction(parentReportID, optimisticAddCommentReport.reportAction, true); } diff --git a/src/pages/tasks/TaskAssigneeSelectorModal.tsx b/src/pages/tasks/TaskAssigneeSelectorModal.tsx index 1f902538adc9..e07f6ecef94f 100644 --- a/src/pages/tasks/TaskAssigneeSelectorModal.tsx +++ b/src/pages/tasks/TaskAssigneeSelectorModal.tsx @@ -24,7 +24,7 @@ import {searchUserInServer} from '@libs/actions/Report'; import {canModifyTask, editTaskAssignee, setAssigneeValue} from '@libs/actions/Task'; import {READ_COMMANDS} from '@libs/API/types'; import HttpUtils from '@libs/HttpUtils'; -import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; +import dismissModalForCurrentContext from '@libs/Navigation/helpers/dismissModalForCurrentContext'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import {getHeaderMessage, isCurrentUser} from '@libs/OptionsListUtils'; @@ -89,11 +89,7 @@ function TaskAssigneeSelectorModal() { const reportOnyx = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${route.params?.reportID}`]; if (reportOnyx && !isTaskReport(reportOnyx)) { Navigation.isNavigationReady().then(() => { - if (isSearchTopmostFullScreenRoute()) { - Navigation.dismissModal(); - return; - } - Navigation.dismissModalWithReport({reportID: reportOnyx.reportID}); + dismissModalForCurrentContext(reportOnyx.reportID); }); } return reports?.[`${ONYXKEYS.COLLECTION.REPORT}${route.params?.reportID}`]; @@ -189,11 +185,7 @@ function TaskAssigneeSelectorModal() { } // eslint-disable-next-line @typescript-eslint/no-deprecated InteractionManager.runAfterInteractions(() => { - if (isSearchTopmostFullScreenRoute()) { - Navigation.dismissModal(); - return; - } - Navigation.dismissModalWithReport({reportID: report?.reportID}); + dismissModalForCurrentContext(report?.reportID); }); // If there's no report, we're creating a new task } else if (option.accountID) { diff --git a/src/pages/tasks/TaskDescriptionPage.tsx b/src/pages/tasks/TaskDescriptionPage.tsx index f0f70ff757bc..f9394260b9b4 100644 --- a/src/pages/tasks/TaskDescriptionPage.tsx +++ b/src/pages/tasks/TaskDescriptionPage.tsx @@ -17,7 +17,7 @@ import useOnyx from '@hooks/useOnyx'; import useReportIsArchived from '@hooks/useReportIsArchived'; import useThemeStyles from '@hooks/useThemeStyles'; import {addErrorMessage} from '@libs/ErrorUtils'; -import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; +import dismissModalForCurrentContext from '@libs/Navigation/helpers/dismissModalForCurrentContext'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {ReportDescriptionNavigatorParamList} from '@libs/Navigation/types'; @@ -63,23 +63,14 @@ function TaskDescriptionPage({report, currentUserPersonalDetails}: TaskDescripti editTask(report, {description: values.description}, delegateEmail); } - if (isSearchTopmostFullScreenRoute()) { - Navigation.dismissModal(); - return; - } - - Navigation.dismissModalWithReport({reportID: report?.reportID}); + dismissModalForCurrentContext(report?.reportID); }, [report, delegateEmail], ); if (!isTaskReport(report)) { Navigation.isNavigationReady().then(() => { - if (isSearchTopmostFullScreenRoute()) { - Navigation.dismissModal(); - return; - } - Navigation.dismissModalWithReport({reportID: report?.reportID}); + dismissModalForCurrentContext(report?.reportID); }); } const inputRef = useRef(null); diff --git a/src/pages/tasks/TaskTitlePage.tsx b/src/pages/tasks/TaskTitlePage.tsx index 3e549e4d2e69..bea3dab188b4 100644 --- a/src/pages/tasks/TaskTitlePage.tsx +++ b/src/pages/tasks/TaskTitlePage.tsx @@ -17,7 +17,7 @@ import useOnyx from '@hooks/useOnyx'; import useReportIsArchived from '@hooks/useReportIsArchived'; import useThemeStyles from '@hooks/useThemeStyles'; import {addErrorMessage} from '@libs/ErrorUtils'; -import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; +import dismissModalForCurrentContext from '@libs/Navigation/helpers/dismissModalForCurrentContext'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {TaskDetailsNavigatorParamList} from '@libs/Navigation/types'; @@ -68,23 +68,14 @@ function TaskTitlePage({report, currentUserPersonalDetails}: TaskTitlePageProps) editTask(report, {title: values.title}, delegateEmail); } - if (isSearchTopmostFullScreenRoute()) { - Navigation.dismissModal(); - return; - } - - Navigation.dismissModalWithReport({reportID: report?.reportID}); + dismissModalForCurrentContext(report?.reportID); }, [report, delegateEmail], ); if (!isTaskReport(report)) { Navigation.isNavigationReady().then(() => { - if (isSearchTopmostFullScreenRoute()) { - Navigation.dismissModal(); - return; - } - Navigation.dismissModalWithReport({reportID: report?.reportID}); + dismissModalForCurrentContext(report?.reportID); }); } From 225c9c2ee45bf5fc42133b5a4706a2b201c8c2dd Mon Sep 17 00:00:00 2001 From: marufsharifi Date: Tue, 14 Apr 2026 15:13:34 +0430 Subject: [PATCH 3/3] Guard leave flow backTo against current report --- .../helpers/shouldUseBackToOnLeaveReport.ts | 35 +++++++++++++++++++ src/libs/actions/Report/index.ts | 3 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/libs/Navigation/helpers/shouldUseBackToOnLeaveReport.ts diff --git a/src/libs/Navigation/helpers/shouldUseBackToOnLeaveReport.ts b/src/libs/Navigation/helpers/shouldUseBackToOnLeaveReport.ts new file mode 100644 index 000000000000..9f8881978985 --- /dev/null +++ b/src/libs/Navigation/helpers/shouldUseBackToOnLeaveReport.ts @@ -0,0 +1,35 @@ +import ROUTES from '@src/ROUTES'; +import type {Route} from '@src/ROUTES'; + +function normalizeRoute(route: string): string { + return route + .replaceAll(/\?.*/g, '') + .replaceAll(/^\/+|\/+$/g, '') + .replaceAll(/\/+/g, '/'); +} + +function doesRouteTargetCurrentReport(route: string, reportID: string): boolean { + const normalizedRoute = normalizeRoute(route); + const currentReportRoutes = [ + ROUTES.REPORT_WITH_ID.getRoute(reportID), + ROUTES.SEARCH_REPORT.getRoute({reportID}), + ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID}), + ROUTES.EXPENSE_REPORT_RHP.getRoute({reportID}), + ].map(normalizeRoute); + + return currentReportRoutes.some((currentReportRoute) => normalizedRoute === currentReportRoute || normalizedRoute.startsWith(`${currentReportRoute}/`)); +} + +function shouldUseBackToOnLeaveReport(reportID: string | undefined, backTo?: Route): boolean { + if (!backTo) { + return false; + } + + if (!reportID) { + return true; + } + + return !doesRouteTargetCurrentReport(backTo, reportID); +} + +export default shouldUseBackToOnLeaveReport; diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index f9455e94d3b0..3a047255d21d 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -79,6 +79,7 @@ import {isEmailPublicDomain} from '@libs/LoginUtils'; import {getMovedReportID} from '@libs/ModifiedExpenseMessage'; import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext'; import type {LinkToOptions} from '@libs/Navigation/helpers/linkTo/types'; +import shouldUseBackToOnLeaveReport from '@libs/Navigation/helpers/shouldUseBackToOnLeaveReport'; import Navigation from '@libs/Navigation/Navigation'; import enhanceParameters from '@libs/Network/enhanceParameters'; import * as NetworkStore from '@libs/Network/NetworkStore'; @@ -4301,7 +4302,7 @@ function navigateToMostRecentReport( betas: OnyxEntry, backTo?: Route, ) { - if (backTo) { + if (shouldUseBackToOnLeaveReport(currentReport?.reportID, backTo)) { Navigation.goBack(backTo); return; }