Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix closing TransactionReceipt modal when opened from Search RHP view #49915

Merged
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
20 changes: 16 additions & 4 deletions src/pages/TransactionReceiptPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<RootStackParamList>;
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);

Expand All @@ -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}
/>
Expand Down
Loading