1- import React , { useCallback , useMemo , useState } from 'react' ;
1+ import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
22import { View } from 'react-native' ;
33import type { OnyxEntry } from 'react-native-onyx' ;
44import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView' ;
@@ -19,6 +19,7 @@ import {buildMergedTransactionData, getSourceTransactionFromMergeTransaction, ge
1919import Navigation from '@libs/Navigation/Navigation' ;
2020import type { PlatformStackScreenProps } from '@libs/Navigation/PlatformStackNavigation/types' ;
2121import type { MergeTransactionNavigatorParamList } from '@libs/Navigation/types' ;
22+ import { openReport } from '@userActions/Report' ;
2223import ONYXKEYS from '@src/ONYXKEYS' ;
2324import type SCREENS from '@src/SCREENS' ;
2425import type { Transaction } from '@src/types/onyx' ;
@@ -42,9 +43,24 @@ function ConfirmationPage({route}: ConfirmationPageProps) {
4243 canBeMissing : true ,
4344 } ) ;
4445
45- const targetTransactionThreadReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ getTransactionThreadReportID ( targetTransaction ) } ` ] ;
46+ const targetTransactionThreadReportID = getTransactionThreadReportID ( targetTransaction ) ;
47+ const targetTransactionThreadReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ targetTransactionThreadReportID } ` ] ;
4648 const [ policy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY } ${ targetTransactionThreadReport ?. policyID } ` , { canBeMissing : true } ) ;
4749
50+ // When user selects a card transaction to merge, that card transaction becomes the target transaction.
51+ // The App may not have the transaction thread report loaded for card transactions, so we need to trigger
52+ // OpenReport to ensure the transaction thread report is available.
53+ useEffect ( ( ) => {
54+ if ( ! targetTransactionThreadReportID && targetTransaction ?. reportID ) {
55+ openReport ( targetTransaction . reportID ) ;
56+ return ;
57+ }
58+
59+ if ( targetTransactionThreadReportID && ! targetTransactionThreadReport ) {
60+ openReport ( targetTransactionThreadReportID ) ;
61+ }
62+ } , [ targetTransactionThreadReportID , targetTransaction , targetTransactionThreadReport ] ) ;
63+
4864 // Build the merged transaction data for display
4965 const mergedTransactionData = useMemo ( ( ) => buildMergedTransactionData ( targetTransaction , mergeTransaction ) , [ targetTransaction , mergeTransaction ] ) ;
5066
@@ -72,7 +88,7 @@ function ConfirmationPage({route}: ConfirmationPageProps) {
7288 Navigation . dismissModal ( ) ;
7389 } , [ targetTransaction , mergeTransaction , sourceTransaction , transactionID ] ) ;
7490
75- if ( isLoadingOnyxValue ( mergeTransactionMetadata ) ) {
91+ if ( isLoadingOnyxValue ( mergeTransactionMetadata ) || ! targetTransactionThreadReport ?. reportID ) {
7692 return < FullScreenLoadingIndicator /> ;
7793 }
7894
0 commit comments