Skip to content

Commit 2c5d44b

Browse files
committed
rewrite IOURequestStepTaxAmountPage to useOnyx
1 parent 2d5cfd3 commit 2c5d44b

1 file changed

Lines changed: 9 additions & 39 deletions

File tree

src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {useFocusEffect} from '@react-navigation/native';
22
import React, {useCallback, useRef} from 'react';
33
import type {OnyxEntry} from 'react-native-onyx';
4-
import {withOnyx} from 'react-native-onyx';
54
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
65
import useLocalize from '@hooks/useLocalize';
6+
import useOnyx from '@hooks/useOnyx';
77
import {setDraftSplitTransaction, setMoneyRequestCurrency, setMoneyRequestParticipantsFromReport, setMoneyRequestTaxAmount, updateMoneyRequestTaxAmount} from '@libs/actions/IOU';
88
import {convertToBackendAmount, isValidCurrencyCode} from '@libs/CurrencyUtils';
99
import Navigation from '@libs/Navigation/Navigation';
@@ -15,29 +15,17 @@ import CONST from '@src/CONST';
1515
import ONYXKEYS from '@src/ONYXKEYS';
1616
import ROUTES from '@src/ROUTES';
1717
import 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';
1919
import {isEmptyObject} from '@src/types/utils/EmptyObject';
2020
import StepScreenWrapper from './StepScreenWrapper';
2121
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
2222
import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';
2323
import 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-
4129
function 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

180168
IOURequestStepTaxAmountPage.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
203173
const IOURequestStepTaxAmountPageWithFullTransactionOrNotFound = withFullTransactionOrNotFound(IOURequestStepTaxAmountPageWithWritableReportOrNotFound);
204174

0 commit comments

Comments
 (0)