diff --git a/src/pages/TransactionReceiptPage.tsx b/src/pages/TransactionReceiptPage.tsx index 495458c6b80f..d51f39b6c630 100644 --- a/src/pages/TransactionReceiptPage.tsx +++ b/src/pages/TransactionReceiptPage.tsx @@ -3,14 +3,16 @@ import React, {useEffect} from 'react'; import {useOnyx} from 'react-native-onyx'; import AttachmentModal from '@components/AttachmentModal'; import Navigation from '@libs/Navigation/Navigation'; -import type {AuthScreensParamList} from '@libs/Navigation/types'; +import type {AuthScreensParamList, RootStackParamList, State} from '@libs/Navigation/types'; import * as ReceiptUtils from '@libs/ReceiptUtils'; import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; +import navigationRef from '@navigation/navigationRef'; import * as ReportActions from '@userActions/Report'; import CONST from '@src/CONST'; +import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; @@ -41,6 +43,18 @@ function TransactionReceipt({route}: TransactionReceiptProps) { // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, []); + const onModalClose = () => { + // Receipt Page can be opened either from Reports or from Search RHP view + // We have to handle going back to correct screens, if it was opened from RHP just close the modal, otherwise go to Report Page + const rootState = navigationRef.getRootState() as State; + const secondToLastRoute = rootState.routes.at(-2); + if (secondToLastRoute?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR) { + Navigation.dismissModal(); + } else { + Navigation.dismissModal(report?.reportID ?? '-1'); + } + }; + const moneyRequestReportID = ReportUtils.isMoneyRequestReport(report) ? report?.reportID : report?.parentReportID; const isTrackExpenseReport = ReportUtils.isTrackExpenseReport(report); @@ -58,9 +72,7 @@ function TransactionReceipt({route}: TransactionReceiptProps) { isTrackExpenseAction={isTrackExpenseAction} originalFileName={receiptURIs?.filename} defaultOpen - onModalClose={() => { - Navigation.dismissModal(report?.reportID ?? '-1'); - }} + onModalClose={onModalClose} isLoading={!transaction && reportMetadata?.isLoadingInitialReportActions} shouldShowNotFoundPage={shouldShowNotFoundPage} />