1
1
import { useFocusEffect } from '@react-navigation/native' ;
2
2
import React , { useCallback , useEffect , useMemo , useRef } from 'react' ;
3
3
import type { OnyxEntry } from 'react-native-onyx' ;
4
- import { useOnyx , withOnyx } from 'react-native-onyx' ;
4
+ import { useOnyx } from 'react-native-onyx' ;
5
5
import type { BaseTextInputRef } from '@components/TextInput/BaseTextInput/types' ;
6
6
import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails' ;
7
7
import type { WithCurrentUserPersonalDetailsProps } from '@components/withCurrentUserPersonalDetails' ;
@@ -32,25 +32,7 @@ type AmountParams = {
32
32
paymentMethod ?: PaymentMethodType ;
33
33
} ;
34
34
35
- type IOURequestStepAmountOnyxProps = {
36
- /** The draft transaction that holds data to be persisted on the current transaction */
37
- splitDraftTransaction : OnyxEntry < OnyxTypes . Transaction > ;
38
-
39
- /** Whether the confirmation step should be skipped */
40
- skipConfirmation : OnyxEntry < boolean > ;
41
-
42
- /** The draft transaction object being modified in Onyx */
43
- draftTransaction : OnyxEntry < OnyxTypes . Transaction > ;
44
-
45
- /** Personal details of all users */
46
- personalDetails : OnyxEntry < OnyxTypes . PersonalDetailsList > ;
47
-
48
- /** The policy which the user has access to and which the report is tied to */
49
- policy : OnyxEntry < OnyxTypes . Policy > ;
50
- } ;
51
-
52
- type IOURequestStepAmountProps = IOURequestStepAmountOnyxProps &
53
- WithCurrentUserPersonalDetailsProps &
35
+ type IOURequestStepAmountProps = WithCurrentUserPersonalDetailsProps &
54
36
WithWritableReportOrNotFoundProps < typeof SCREENS . MONEY_REQUEST . STEP_AMOUNT | typeof SCREENS . MONEY_REQUEST . CREATE > & {
55
37
/** The transaction object being modified in Onyx */
56
38
transaction : OnyxEntry < OnyxTypes . Transaction > ;
@@ -65,14 +47,15 @@ function IOURequestStepAmount({
65
47
params : { iouType, reportID, transactionID, backTo, pageIndex, action, currency : selectedCurrency = '' } ,
66
48
} ,
67
49
transaction,
68
- policy,
69
- personalDetails,
70
50
currentUserPersonalDetails,
71
- splitDraftTransaction,
72
- skipConfirmation,
73
- draftTransaction,
74
51
shouldKeepUserInput = false ,
75
52
} : IOURequestStepAmountProps ) {
53
+ const [ splitDraftTransaction ] = useOnyx ( `${ ONYXKEYS . COLLECTION . SPLIT_TRANSACTION_DRAFT } ${ transactionID ?? - 1 } ` ) ;
54
+ const [ draftTransaction ] = useOnyx ( `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID ?? - 1 } ` ) ;
55
+ const [ skipConfirmation ] = useOnyx ( `${ ONYXKEYS . COLLECTION . SKIP_CONFIRMATION } ${ transactionID ?? - 1 } ` ) ;
56
+ const [ personalDetails ] = useOnyx ( ONYXKEYS . PERSONAL_DETAILS_LIST ) ;
57
+ const [ policy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY } ${ report ? report . policyID : - 1 } ` ) ;
58
+
76
59
const { translate} = useLocalize ( ) ;
77
60
const textInput = useRef < BaseTextInputRef | null > ( null ) ;
78
61
const focusTimeoutRef = useRef < NodeJS . Timeout | null > ( null ) ;
@@ -85,7 +68,7 @@ function IOURequestStepAmount({
85
68
const isEditingSplitBill = isEditing && isSplitBill ;
86
69
const currentTransaction = isEditingSplitBill && ! isEmptyObject ( splitDraftTransaction ) ? splitDraftTransaction : transaction ;
87
70
const { amount : transactionAmount } = ReportUtils . getTransactionDetails ( currentTransaction ) ?? { amount : 0 } ;
88
- const { currency : originalCurrency } = ReportUtils . getTransactionDetails ( isEditing ? draftTransaction : transaction ) ?? { currency : CONST . CURRENCY . USD } ;
71
+ const { currency : originalCurrency } = ReportUtils . getTransactionDetails ( isEditing && ! isEmptyObject ( draftTransaction ) ? draftTransaction : transaction ) ?? { currency : CONST . CURRENCY . USD } ;
89
72
const currency = CurrencyUtils . isValidCurrencyCode ( selectedCurrency ) ? selectedCurrency : originalCurrency ;
90
73
91
74
// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace request, as
@@ -332,34 +315,7 @@ function IOURequestStepAmount({
332
315
333
316
IOURequestStepAmount . displayName = 'IOURequestStepAmount' ;
334
317
335
- const IOURequestStepAmountWithOnyx = withOnyx < IOURequestStepAmountProps , IOURequestStepAmountOnyxProps > ( {
336
- splitDraftTransaction : {
337
- key : ( { route} ) => {
338
- const transactionID = route . params . transactionID ?? - 1 ;
339
- return `${ ONYXKEYS . COLLECTION . SPLIT_TRANSACTION_DRAFT } ${ transactionID } ` ;
340
- } ,
341
- } ,
342
- draftTransaction : {
343
- key : ( { route} ) => {
344
- const transactionID = route . params . transactionID ?? 0 ;
345
- return `${ ONYXKEYS . COLLECTION . TRANSACTION_DRAFT } ${ transactionID } ` ;
346
- } ,
347
- } ,
348
- skipConfirmation : {
349
- key : ( { route} ) => {
350
- const transactionID = route . params . transactionID ?? - 1 ;
351
- return `${ ONYXKEYS . COLLECTION . SKIP_CONFIRMATION } ${ transactionID } ` ;
352
- } ,
353
- } ,
354
- personalDetails : {
355
- key : ONYXKEYS . PERSONAL_DETAILS_LIST ,
356
- } ,
357
- policy : {
358
- key : ( { report} ) => `${ ONYXKEYS . COLLECTION . POLICY } ${ report ? report . policyID : '-1' } ` ,
359
- } ,
360
- } ) ( IOURequestStepAmount ) ;
361
-
362
- const IOURequestStepAmountWithCurrentUserPersonalDetails = withCurrentUserPersonalDetails ( IOURequestStepAmountWithOnyx ) ;
318
+ const IOURequestStepAmountWithCurrentUserPersonalDetails = withCurrentUserPersonalDetails ( IOURequestStepAmount ) ;
363
319
// eslint-disable-next-line rulesdir/no-negated-variables
364
320
const IOURequestStepAmountWithWritableReportOrNotFound = withWritableReportOrNotFound ( IOURequestStepAmountWithCurrentUserPersonalDetails , true ) ;
365
321
// eslint-disable-next-line rulesdir/no-negated-variables
0 commit comments