Skip to content

Commit 8fc023f

Browse files
authored
Merge pull request #51935 from jayeshmangwani/fix_for_edit_amout_page_flickering
Fix for edit amount page flickering
2 parents b8acd4a + 9fa9db4 commit 8fc023f

File tree

1 file changed

+10
-54
lines changed

1 file changed

+10
-54
lines changed

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

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {useFocusEffect} from '@react-navigation/native';
22
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
33
import type {OnyxEntry} from 'react-native-onyx';
4-
import {useOnyx, withOnyx} from 'react-native-onyx';
4+
import {useOnyx} from 'react-native-onyx';
55
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
66
import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails';
77
import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails';
@@ -32,25 +32,7 @@ type AmountParams = {
3232
paymentMethod?: PaymentMethodType;
3333
};
3434

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 &
5436
WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_AMOUNT | typeof SCREENS.MONEY_REQUEST.CREATE> & {
5537
/** The transaction object being modified in Onyx */
5638
transaction: OnyxEntry<OnyxTypes.Transaction>;
@@ -65,14 +47,15 @@ function IOURequestStepAmount({
6547
params: {iouType, reportID, transactionID, backTo, pageIndex, action, currency: selectedCurrency = ''},
6648
},
6749
transaction,
68-
policy,
69-
personalDetails,
7050
currentUserPersonalDetails,
71-
splitDraftTransaction,
72-
skipConfirmation,
73-
draftTransaction,
7451
shouldKeepUserInput = false,
7552
}: 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+
7659
const {translate} = useLocalize();
7760
const textInput = useRef<BaseTextInputRef | null>(null);
7861
const focusTimeoutRef = useRef<NodeJS.Timeout | null>(null);
@@ -85,7 +68,7 @@ function IOURequestStepAmount({
8568
const isEditingSplitBill = isEditing && isSplitBill;
8669
const currentTransaction = isEditingSplitBill && !isEmptyObject(splitDraftTransaction) ? splitDraftTransaction : transaction;
8770
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};
8972
const currency = CurrencyUtils.isValidCurrencyCode(selectedCurrency) ? selectedCurrency : originalCurrency;
9073

9174
// 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({
332315

333316
IOURequestStepAmount.displayName = 'IOURequestStepAmount';
334317

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);
363319
// eslint-disable-next-line rulesdir/no-negated-variables
364320
const IOURequestStepAmountWithWritableReportOrNotFound = withWritableReportOrNotFound(IOURequestStepAmountWithCurrentUserPersonalDetails, true);
365321
// eslint-disable-next-line rulesdir/no-negated-variables

0 commit comments

Comments
 (0)