11import { useFocusEffect } from '@react-navigation/native' ;
22import React , { useCallback , useRef } from 'react' ;
33import type { OnyxEntry } from 'react-native-onyx' ;
4- import { withOnyx } from 'react-native-onyx' ;
54import type { BaseTextInputRef } from '@components/TextInput/BaseTextInput/types' ;
65import useLocalize from '@hooks/useLocalize' ;
6+ import useOnyx from '@hooks/useOnyx' ;
77import { setDraftSplitTransaction , setMoneyRequestCurrency , setMoneyRequestParticipantsFromReport , setMoneyRequestTaxAmount , updateMoneyRequestTaxAmount } from '@libs/actions/IOU' ;
88import { convertToBackendAmount , isValidCurrencyCode } from '@libs/CurrencyUtils' ;
99import Navigation from '@libs/Navigation/Navigation' ;
@@ -15,29 +15,17 @@ import CONST from '@src/CONST';
1515import ONYXKEYS from '@src/ONYXKEYS' ;
1616import ROUTES from '@src/ROUTES' ;
1717import type SCREENS from '@src/SCREENS' ;
18- import type { Policy , PolicyCategories , PolicyTagLists , Transaction } from '@src/types/onyx' ;
18+ import type { Policy , Transaction } from '@src/types/onyx' ;
1919import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
2020import StepScreenWrapper from './StepScreenWrapper' ;
2121import withFullTransactionOrNotFound from './withFullTransactionOrNotFound' ;
2222import type { WithWritableReportOrNotFoundProps } from './withWritableReportOrNotFound' ;
2323import withWritableReportOrNotFound from './withWritableReportOrNotFound' ;
2424
25- type IOURequestStepTaxAmountPageOnyxProps = {
26- policy : OnyxEntry < Policy > ;
27- policyCategories : OnyxEntry < PolicyCategories > ;
28-
29- /** Collection of tag list on a policy */
30- policyTags : OnyxEntry < PolicyTagLists > ;
31-
32- /** The draft transaction that holds data to be persisted on the current transaction */
33- splitDraftTransaction : OnyxEntry < Transaction > ;
25+ type IOURequestStepTaxAmountPageProps = WithWritableReportOrNotFoundProps < typeof SCREENS . MONEY_REQUEST . STEP_TAX_AMOUNT > & {
26+ transaction : OnyxEntry < Transaction > ;
3427} ;
3528
36- type IOURequestStepTaxAmountPageProps = IOURequestStepTaxAmountPageOnyxProps &
37- WithWritableReportOrNotFoundProps < typeof SCREENS . MONEY_REQUEST . STEP_TAX_AMOUNT > & {
38- transaction : OnyxEntry < Transaction > ;
39- } ;
40-
4129function getTaxAmount ( transaction : OnyxEntry < Transaction > , policy : OnyxEntry < Policy > , currency : string | undefined , isEditing : boolean ) : number | undefined {
4230 if ( ! transaction ?. amount && ! transaction ?. modifiedAmount ) {
4331 return ;
@@ -59,11 +47,11 @@ function IOURequestStepTaxAmountPage({
5947 } ,
6048 transaction,
6149 report,
62- policy,
63- policyTags,
64- policyCategories,
65- splitDraftTransaction,
6650} : IOURequestStepTaxAmountPageProps ) {
51+ const [ policy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY } ${ report ?. policyID } ` , { canBeMissing : true } ) ;
52+ const [ policyCategories ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY_CATEGORIES } ${ report ?. policyID } ` , { canBeMissing : true } ) ;
53+ const [ policyTags ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY_TAGS } ${ report ?. policyID } ` , { canBeMissing : true } ) ;
54+ const [ splitDraftTransaction ] = useOnyx ( `${ ONYXKEYS . COLLECTION . SPLIT_TRANSACTION_DRAFT } ${ transactionID } ` , { canBeMissing : true } ) ;
6755 const { translate} = useLocalize ( ) ;
6856 const textInput = useRef < BaseTextInputRef | null > ( null ) ;
6957 const isEditing = action === CONST . IOU . ACTION . EDIT ;
@@ -179,26 +167,8 @@ function IOURequestStepTaxAmountPage({
179167
180168IOURequestStepTaxAmountPage . displayName = 'IOURequestStepTaxAmountPage' ;
181169
182- const IOURequestStepTaxAmountPageWithOnyx = withOnyx < IOURequestStepTaxAmountPageProps , IOURequestStepTaxAmountPageOnyxProps > ( {
183- splitDraftTransaction : {
184- key : ( { route} ) => {
185- const transactionID = route ?. params . transactionID ?? CONST . DEFAULT_NUMBER_ID ;
186- return `${ ONYXKEYS . COLLECTION . SPLIT_TRANSACTION_DRAFT } ${ transactionID } ` ;
187- } ,
188- } ,
189- policy : {
190- key : ( { report} ) => `${ ONYXKEYS . COLLECTION . POLICY } ${ report ?. policyID } ` ,
191- } ,
192- policyCategories : {
193- key : ( { report} ) => `${ ONYXKEYS . COLLECTION . POLICY_CATEGORIES } ${ report ?. policyID } ` ,
194- } ,
195- policyTags : {
196- key : ( { report} ) => `${ ONYXKEYS . COLLECTION . POLICY_TAGS } ${ report ?. policyID } ` ,
197- } ,
198- } ) ( IOURequestStepTaxAmountPage ) ;
199-
200170// eslint-disable-next-line rulesdir/no-negated-variables
201- const IOURequestStepTaxAmountPageWithWritableReportOrNotFound = withWritableReportOrNotFound ( IOURequestStepTaxAmountPageWithOnyx ) ;
171+ const IOURequestStepTaxAmountPageWithWritableReportOrNotFound = withWritableReportOrNotFound ( IOURequestStepTaxAmountPage ) ;
202172// eslint-disable-next-line rulesdir/no-negated-variables
203173const IOURequestStepTaxAmountPageWithFullTransactionOrNotFound = withFullTransactionOrNotFound ( IOURequestStepTaxAmountPageWithWritableReportOrNotFound ) ;
204174
0 commit comments