Skip to content

Commit

Permalink
Merge pull request #49915 from software-mansion-labs/kicu/49887-fix-r…
Browse files Browse the repository at this point in the history
…eceipt-modal

Fix closing TransactionReceipt modal when opened from Search RHP view
  • Loading branch information
luacmartins authored Oct 1, 2024
2 parents 2c07b39 + 2f9de07 commit d46f218
Showing 1 changed file with 16 additions and 4 deletions.
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

0 comments on commit d46f218

Please sign in to comment.