11import { useRoute } from '@react-navigation/native' ;
2- import React , { useMemo } from 'react' ;
2+ import React , { useEffect , useMemo } from 'react' ;
33import { View } from 'react-native' ;
44import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView' ;
55import Button from '@components/Button' ;
6+ import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator' ;
67import HeaderWithBackButton from '@components/HeaderWithBackButton' ;
78import ScreenWrapper from '@components/ScreenWrapper' ;
89import Text from '@components/Text' ;
@@ -11,6 +12,7 @@ import useLocalize from '@hooks/useLocalize';
1112import useOnyx from '@hooks/useOnyx' ;
1213import useThemeStyles from '@hooks/useThemeStyles' ;
1314import useTransactionViolations from '@hooks/useTransactionViolations' ;
15+ import { openReport } from '@libs/actions/Report' ;
1416import { dismissDuplicateTransactionViolation } from '@libs/actions/Transaction' ;
1517import Navigation from '@libs/Navigation/Navigation' ;
1618import type { PlatformStackRouteProp } from '@libs/Navigation/PlatformStackNavigation/types' ;
@@ -20,6 +22,7 @@ import {isReportIDApproved, isSettled} from '@libs/ReportUtils';
2022import CONST from '@src/CONST' ;
2123import ONYXKEYS from '@src/ONYXKEYS' ;
2224import type SCREENS from '@src/SCREENS' ;
25+ import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
2326import DuplicateTransactionsList from './DuplicateTransactionsList' ;
2427
2528function TransactionDuplicateReview ( ) {
@@ -28,6 +31,7 @@ function TransactionDuplicateReview() {
2831 const route = useRoute < PlatformStackRouteProp < TransactionDuplicateNavigatorParamList , typeof SCREENS . TRANSACTION_DUPLICATE . REVIEW > > ( ) ;
2932 const currentPersonalDetails = useCurrentUserPersonalDetails ( ) ;
3033 const [ report ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ route . params . threadReportID } ` , { canBeMissing : true } ) ;
34+ const [ reportMetadata ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_METADATA } ${ route . params . threadReportID } ` , { canBeMissing : true } ) ;
3135 const reportAction = getReportAction ( report ?. parentReportID , report ?. parentReportActionID ) ;
3236 const transactionID = getLinkedTransactionID ( reportAction , report ?. reportID ) ?? undefined ;
3337 const transactionViolations = useTransactionViolations ( transactionID ) ;
@@ -56,9 +60,25 @@ function TransactionDuplicateReview() {
5660
5761 const hasSettledOrApprovedTransaction = transactions ?. some ( ( transaction ) => isSettled ( transaction ?. reportID ) || isReportIDApproved ( transaction ?. reportID ) ) ;
5862
63+ useEffect ( ( ) => {
64+ if ( ! isEmptyObject ( report ) || ! route . params . threadReportID ) {
65+ return ;
66+ }
67+ openReport ( route . params . threadReportID ) ;
68+ } , [ report , route . params . threadReportID ] ) ;
69+
70+ const isLoadingReport = isEmptyObject ( report ) && reportMetadata ?. isLoadingInitialReportActions !== false ;
71+
72+ // eslint-disable-next-line rulesdir/no-negated-variables
73+ const shouldShowNotFound = ! isLoadingReport && ! transactionID ;
74+
75+ if ( isLoadingReport ) {
76+ return < FullscreenLoadingIndicator /> ;
77+ }
78+
5979 return (
6080 < ScreenWrapper testID = { TransactionDuplicateReview . displayName } >
61- < FullPageNotFoundView shouldShow = { ! transactionID } >
81+ < FullPageNotFoundView shouldShow = { shouldShowNotFound } >
6282 < HeaderWithBackButton
6383 title = { translate ( 'iou.reviewDuplicates' ) }
6484 onBackButtonPress = { ( ) => Navigation . goBack ( route . params . backTo ) }
0 commit comments