1
1
import React from 'react' ;
2
2
import type { StyleProp , ViewStyle } from 'react-native' ;
3
- import { withOnyx } from 'react-native-onyx' ;
4
- import type { OnyxEntry } from 'react-native-onyx' ;
3
+ import { useOnyx } from 'react-native-onyx' ;
5
4
import RenderHTML from '@components/RenderHTML' ;
6
5
import useLocalize from '@hooks/useLocalize' ;
7
6
import useNetwork from '@hooks/useNetwork' ;
8
7
import useThemeStyles from '@hooks/useThemeStyles' ;
9
- import * as IOUUtils from '@libs/IOUUtils' ;
8
+ import { isIOUReportPendingCurrencyConversion } from '@libs/IOUUtils' ;
10
9
import Navigation from '@libs/Navigation/Navigation' ;
11
- import * as ReportActionsUtils from '@libs/ReportActionsUtils' ;
10
+ import { isDeletedParentAction , isReversedTransaction , isSplitBillAction , isTrackExpenseAction } from '@libs/ReportActionsUtils' ;
12
11
import type { ContextMenuAnchor } from '@pages/home/report/ContextMenu/ReportActionContextMenu' ;
13
12
import CONST from '@src/CONST' ;
14
13
import type { TranslationPaths } from '@src/languages/types' ;
@@ -18,18 +17,7 @@ import type * as OnyxTypes from '@src/types/onyx';
18
17
import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
19
18
import MoneyRequestPreview from './MoneyRequestPreview' ;
20
19
21
- type MoneyRequestActionOnyxProps = {
22
- /** Chat report associated with iouReport */
23
- chatReport : OnyxEntry < OnyxTypes . Report > ;
24
-
25
- /** IOU report data object */
26
- iouReport : OnyxEntry < OnyxTypes . Report > ;
27
-
28
- /** Report actions for this report */
29
- reportActions : OnyxEntry < OnyxTypes . ReportActions > ;
30
- } ;
31
-
32
- type MoneyRequestActionProps = MoneyRequestActionOnyxProps & {
20
+ type MoneyRequestActionProps = {
33
21
/** All the data of the action */
34
22
action : OnyxTypes . ReportAction ;
35
23
@@ -72,9 +60,6 @@ function MoneyRequestAction({
72
60
isMostRecentIOUReportAction,
73
61
contextMenuAnchor,
74
62
checkIfContextMenuActive = ( ) => { } ,
75
- chatReport,
76
- iouReport,
77
- reportActions,
78
63
isHovered = false ,
79
64
style,
80
65
isWhisper = false ,
@@ -83,23 +68,29 @@ function MoneyRequestAction({
83
68
const styles = useThemeStyles ( ) ;
84
69
const { translate} = useLocalize ( ) ;
85
70
const { isOffline} = useNetwork ( ) ;
86
- const isSplitBillAction = ReportActionsUtils . isSplitBillAction ( action ) ;
87
- const isTrackExpenseAction = ReportActionsUtils . isTrackExpenseAction ( action ) ;
71
+ const isActionSplitBill = isSplitBillAction ( action ) ;
72
+ const isActionTrackExpense = isTrackExpenseAction ( action ) ;
73
+ const [ reportActions ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ chatReportID || CONST . DEFAULT_NUMBER_ID } ` , { canEvict : false } ) ;
74
+ const [ chatReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReportID || CONST . DEFAULT_NUMBER_ID } ` ) ;
75
+ const [ iouReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ requestReportID } ` ) ;
88
76
89
77
const onMoneyRequestPreviewPressed = ( ) => {
90
- if ( isSplitBillAction ) {
91
- const reportActionID = action . reportActionID ?? '-1' ;
78
+ if ( isActionSplitBill ) {
79
+ const reportActionID = action . reportActionID ;
92
80
Navigation . navigate ( ROUTES . SPLIT_BILL_DETAILS . getRoute ( chatReportID , reportActionID , Navigation . getReportRHPActiveRoute ( ) ) ) ;
93
81
return ;
94
82
}
95
83
96
- const childReportID = action ?. childReportID ?? '-1' ;
84
+ const childReportID = action ?. childReportID ;
85
+ if ( ! childReportID ) {
86
+ return ;
87
+ }
97
88
Navigation . navigate ( ROUTES . REPORT_WITH_ID . getRoute ( childReportID ) ) ;
98
89
} ;
99
90
100
91
let shouldShowPendingConversionMessage = false ;
101
- const isDeletedParentAction = ReportActionsUtils . isDeletedParentAction ( action ) ;
102
- const isReversedTransaction = ReportActionsUtils . isReversedTransaction ( action ) ;
92
+ const isParentActionDeleted = isDeletedParentAction ( action ) ;
93
+ const isTransactionReveresed = isReversedTransaction ( action ) ;
103
94
if (
104
95
! isEmptyObject ( iouReport ) &&
105
96
! isEmptyObject ( reportActions ) &&
@@ -108,25 +99,25 @@ function MoneyRequestAction({
108
99
action . pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . ADD &&
109
100
isOffline
110
101
) {
111
- shouldShowPendingConversionMessage = IOUUtils . isIOUReportPendingCurrencyConversion ( iouReport ) ;
102
+ shouldShowPendingConversionMessage = isIOUReportPendingCurrencyConversion ( iouReport ) ;
112
103
}
113
104
114
- if ( isDeletedParentAction || isReversedTransaction ) {
105
+ if ( isParentActionDeleted || isTransactionReveresed ) {
115
106
let message : TranslationPaths ;
116
- if ( isReversedTransaction ) {
107
+ if ( isTransactionReveresed ) {
117
108
message = 'parentReportAction.reversedTransaction' ;
118
109
} else {
119
110
message = 'parentReportAction.deletedExpense' ;
120
111
}
121
- return < RenderHTML html = { `<comment >${ translate ( message ) } </comment >` } /> ;
112
+ return < RenderHTML html = { `<deleted-action ${ CONST . REVERSED_TRANSACTION_ATTRIBUTE } =" ${ isTransactionReveresed } " >${ translate ( message ) } </deleted-action >` } /> ;
122
113
}
123
114
return (
124
115
< MoneyRequestPreview
125
116
iouReportID = { requestReportID }
126
117
chatReportID = { chatReportID }
127
118
reportID = { reportID }
128
- isBillSplit = { isSplitBillAction }
129
- isTrackExpense = { isTrackExpenseAction }
119
+ isBillSplit = { isActionSplitBill }
120
+ isTrackExpense = { isActionTrackExpense }
130
121
action = { action }
131
122
contextMenuAnchor = { contextMenuAnchor }
132
123
checkIfContextMenuActive = { checkIfContextMenuActive }
@@ -142,15 +133,4 @@ function MoneyRequestAction({
142
133
143
134
MoneyRequestAction . displayName = 'MoneyRequestAction' ;
144
135
145
- export default withOnyx < MoneyRequestActionProps , MoneyRequestActionOnyxProps > ( {
146
- chatReport : {
147
- key : ( { chatReportID} ) => `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReportID } ` ,
148
- } ,
149
- iouReport : {
150
- key : ( { requestReportID} ) => `${ ONYXKEYS . COLLECTION . REPORT } ${ requestReportID } ` ,
151
- } ,
152
- reportActions : {
153
- key : ( { chatReportID} ) => `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ chatReportID } ` ,
154
- canEvict : false ,
155
- } ,
156
- } ) ( MoneyRequestAction ) ;
136
+ export default MoneyRequestAction ;
0 commit comments