@@ -24,6 +24,7 @@ import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTop
2424import Navigation from '@libs/Navigation/Navigation' ;
2525import type { PlatformStackScreenProps } from '@libs/Navigation/PlatformStackNavigation/types' ;
2626import type { MergeTransactionNavigatorParamList } from '@libs/Navigation/types' ;
27+ import { findSelfDMReportID } from '@libs/ReportUtils' ;
2728import CONST from '@src/CONST' ;
2829import ONYXKEYS from '@src/ONYXKEYS' ;
2930import ROUTES from '@src/ROUTES' ;
@@ -72,7 +73,7 @@ function ConfirmationPage({route}: ConfirmationPageProps) {
7273 if ( ! targetTransaction || ! mergeTransaction || ! sourceTransaction ) {
7374 return ;
7475 }
75- const reportID = mergeTransaction . reportID ;
76+ const reportID = mergeTransaction . reportID === CONST . REPORT . UNREPORTED_REPORT_ID ? ( findSelfDMReportID ( ) ?? CONST . REPORT . UNREPORTED_REPORT_ID ) : mergeTransaction . reportID ;
7677
7778 setIsMergingExpenses ( true ) ;
7879 mergeTransactionRequest ( {
@@ -95,23 +96,23 @@ function ConfirmationPage({route}: ConfirmationPageProps) {
9596
9697 const reportIDToDismiss = reportID !== CONST . REPORT . UNREPORTED_REPORT_ID ? reportID : undefined ;
9798
98- // If we're on search, dismiss the modal and stay on search
99- if ( ! isOnSearch && reportIDToDismiss && reportID !== targetTransaction . reportID ) {
100- // Navigate to search money report screen if we're on Reports
101- if ( isSearchTopmostFullScreenRoute ( ) ) {
102- // Close the current modal screen
103- Navigation . dismissModal ( ) ;
104- // Ensure the dismiss completes first
105- Navigation . setNavigationActionToMicrotaskQueue ( ( ) => {
106- // Navigate to the money request report in search results
107- Navigation . navigate ( ROUTES . SEARCH_MONEY_REQUEST_REPORT . getRoute ( { reportID : reportIDToDismiss } ) ) ;
108- } ) ;
109- } else {
110- Navigation . dismissModalWithReport ( { reportID : reportIDToDismiss } ) ;
111- }
112- } else {
113- Navigation . dismissToSuperWideRHP ( ) ;
99+ const searchReportIDToOpen = targetTransactionThreadReportID ?? reportIDToDismiss ;
100+
101+ // If we're in search (or the topmost route is search), dismiss the modal and open the expense in the RHP
102+ if ( ( isOnSearch || isSearchTopmostFullScreenRoute ( ) ) && searchReportIDToOpen ) {
103+ Navigation . dismissModal ( ) ;
104+ Navigation . setNavigationActionToMicrotaskQueue ( ( ) => {
105+ Navigation . navigate ( ROUTES . SEARCH_REPORT . getRoute ( { reportID : searchReportIDToOpen } ) ) ;
106+ } ) ;
107+ return ;
108+ }
109+
110+ if ( reportIDToDismiss && reportID !== targetTransaction . reportID ) {
111+ Navigation . dismissModalWithReport ( { reportID : reportIDToDismiss } ) ;
112+ return ;
114113 }
114+
115+ Navigation . dismissToSuperWideRHP ( ) ;
115116 } ;
116117
117118 if ( isLoadingOnyxValue ( mergeTransactionMetadata ) ) {
0 commit comments