@@ -7,6 +7,7 @@ import {useOnyx} from 'react-native-onyx';
7
7
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView' ;
8
8
import Button from '@components/Button' ;
9
9
import FixedFooter from '@components/FixedFooter' ;
10
+ import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator' ;
10
11
import HeaderWithBackButton from '@components/HeaderWithBackButton' ;
11
12
import MoneyRequestView from '@components/ReportActionItem/MoneyRequestView' ;
12
13
import ScreenWrapper from '@components/ScreenWrapper' ;
@@ -20,19 +21,22 @@ import type {TransactionDuplicateNavigatorParamList} from '@libs/Navigation/type
20
21
import variables from '@styles/variables' ;
21
22
import * as IOU from '@src/libs/actions/IOU' ;
22
23
import * as ReportActionsUtils from '@src/libs/ReportActionsUtils' ;
24
+ import * as ReportUtils from '@src/libs/ReportUtils' ;
23
25
import * as TransactionUtils from '@src/libs/TransactionUtils' ;
24
26
import ONYXKEYS from '@src/ONYXKEYS' ;
25
27
import ROUTES from '@src/ROUTES' ;
26
28
import type SCREENS from '@src/SCREENS' ;
27
29
import type { Transaction } from '@src/types/onyx' ;
30
+ import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
31
+ import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue' ;
28
32
29
33
function Confirmation ( ) {
30
34
const styles = useThemeStyles ( ) ;
31
35
const { translate} = useLocalize ( ) ;
32
36
const route = useRoute < RouteProp < TransactionDuplicateNavigatorParamList , typeof SCREENS . TRANSACTION_DUPLICATE . REVIEW > > ( ) ;
33
- const [ reviewDuplicates ] = useOnyx ( ONYXKEYS . REVIEW_DUPLICATES ) ;
37
+ const [ reviewDuplicates , reviewDuplicatesResult ] = useOnyx ( ONYXKEYS . REVIEW_DUPLICATES ) ;
34
38
const transaction = useMemo ( ( ) => TransactionUtils . buildNewTransactionAfterReviewingDuplicates ( reviewDuplicates ) , [ reviewDuplicates ] ) ;
35
- const [ report ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ route . params . threadReportID } ` ) ;
39
+ const [ report , reportResult ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ route . params . threadReportID } ` ) ;
36
40
const [ reportActions ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ transaction ?. reportID } ` ) ;
37
41
const reportAction = Object . values ( reportActions ?? { } ) . find (
38
42
( action ) => ReportActionsUtils . isMoneyRequestAction ( action ) && ReportActionsUtils . getOriginalMessage ( action ) ?. IOUTransactionID === reviewDuplicates ?. transactionID ,
@@ -56,13 +60,27 @@ function Confirmation() {
56
60
[ report , reportAction ] ,
57
61
) ;
58
62
63
+ const reportTransactionID = TransactionUtils . getTransactionID ( report ?. reportID ?? '' ) ;
64
+ const doesTransactionBelongToReport = reviewDuplicates ?. transactionID === reportTransactionID || reviewDuplicates ?. duplicates . includes ( reportTransactionID ) ;
65
+
66
+ // eslint-disable-next-line rulesdir/no-negated-variables
67
+ const shouldShowNotFoundPage =
68
+ isEmptyObject ( report ) ||
69
+ ! ReportUtils . isValidReport ( report ) ||
70
+ ReportUtils . isReportNotFound ( report ) ||
71
+ ( reviewDuplicatesResult . status === 'loaded' && ( ! transaction ?. transactionID || ! doesTransactionBelongToReport ) ) ;
72
+
73
+ if ( isLoadingOnyxValue ( reviewDuplicatesResult , reportResult ) ) {
74
+ return < FullScreenLoadingIndicator /> ;
75
+ }
76
+
59
77
return (
60
78
< ScreenWrapper
61
79
testID = { Confirmation . displayName }
62
80
shouldShowOfflineIndicator
63
81
>
64
82
{ ( { safeAreaPaddingBottomStyle} ) => (
65
- < FullPageNotFoundView shouldShow = { ! reviewDuplicates } >
83
+ < FullPageNotFoundView shouldShow = { shouldShowNotFoundPage } >
66
84
< View style = { [ styles . flex1 , safeAreaPaddingBottomStyle ] } >
67
85
< HeaderWithBackButton title = { translate ( 'iou.reviewDuplicates' ) } />
68
86
< ScrollView >
0 commit comments