From 2881a4954c584cd701503b3ef146921c4a665d81 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 10 Oct 2024 07:45:31 +0700 Subject: [PATCH 1/4] migrate IOURequestStepDistanceRate to useOnyx --- .../step/IOURequestStepDistanceRate.tsx | 40 ++++--------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx index 59e1591a23ff..144add6d5795 100644 --- a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx @@ -1,6 +1,6 @@ import React from 'react'; import type {OnyxEntry} from 'react-native-onyx'; -import {useOnyx, withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import SelectionList from '@components/SelectionList'; import RadioListItem from '@components/SelectionList/RadioListItem'; import Text from '@components/Text'; @@ -23,35 +23,23 @@ import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; import withWritableReportOrNotFound from './withWritableReportOrNotFound'; -type IOURequestStepDistanceRateOnyxProps = { - /** Policy details */ - policy: OnyxEntry; - - /** Collection of categories attached to the policy */ - policyCategories: OnyxEntry; - - /** Collection of tags attached to the policy */ - policyTags: OnyxEntry; +type IOURequestStepDistanceRateProps = WithWritableReportOrNotFoundProps & { + /** Holds data related to Money Request view state, rather than the underlying Money Request data. */ + transaction: OnyxEntry; }; -type IOURequestStepDistanceRateProps = IOURequestStepDistanceRateOnyxProps & - WithWritableReportOrNotFoundProps & { - /** Holds data related to Money Request view state, rather than the underlying Money Request data. */ - transaction: OnyxEntry; - }; - function IOURequestStepDistanceRate({ - policy: policyReal, report, reportDraft, route: { params: {action, reportID, backTo, transactionID}, }, transaction, - policyTags, - policyCategories, }: IOURequestStepDistanceRateProps) { const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${IOU.getIOURequestPolicyID(transaction, reportDraft) ?? '-1'}`); + const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID || '-1'}`); + const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID || '-1'}`); + const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID || '-1'}`); const policy = policyReal ?? policyDraft; @@ -133,20 +121,8 @@ function IOURequestStepDistanceRate({ IOURequestStepDistanceRate.displayName = 'IOURequestStepDistanceRate'; -const IOURequestStepDistanceRateWithOnyx = withOnyx({ - policy: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '-1'}`, - }, - policyCategories: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`, - }, - policyTags: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`, - }, -})(IOURequestStepDistanceRate); - // eslint-disable-next-line rulesdir/no-negated-variables -const IOURequestStepDistanceRateWithWritableReportOrNotFound = withWritableReportOrNotFound(IOURequestStepDistanceRateWithOnyx); +const IOURequestStepDistanceRateWithWritableReportOrNotFound = withWritableReportOrNotFound(IOURequestStepDistanceRate); // eslint-disable-next-line rulesdir/no-negated-variables const IOURequestStepDistanceRateWithFullTransactionOrNotFound = withFullTransactionOrNotFound(IOURequestStepDistanceRateWithWritableReportOrNotFound); From 62acf3bfa11135b1a13ec45d0cf5d07071053ff6 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 10 Oct 2024 07:54:25 +0700 Subject: [PATCH 2/4] fix typescript and lint errors --- src/pages/iou/request/step/IOURequestStepDistanceRate.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx index 144add6d5795..0e26306778e9 100644 --- a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx @@ -37,9 +37,11 @@ function IOURequestStepDistanceRate({ transaction, }: IOURequestStepDistanceRateProps) { const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${IOU.getIOURequestPolicyID(transaction, reportDraft) ?? '-1'}`); + /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID || '-1'}`); const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID || '-1'}`); - const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID || '-1'}`); + const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID || '-1'}`); + /* eslint-enable @typescript-eslint/prefer-nullish-coalescing */ const policy = policyReal ?? policyDraft; From 6aed040f608bfe097d3a15b7c9f9bc300fac14d1 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 10 Oct 2024 08:10:30 +0700 Subject: [PATCH 3/4] update onyx key --- src/libs/Permissions.ts | 2 +- .../iou/request/MoneyRequestParticipantsSelector.tsx | 8 ++++---- src/pages/iou/request/step/IOURequestStepDistanceRate.tsx | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 9fd94dcb86b8..1315e1ee3425 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -5,7 +5,7 @@ import type Beta from '@src/types/onyx/Beta'; import * as Environment from './Environment/Environment'; function canUseAllBetas(betas: OnyxEntry): boolean { - return !!betas?.includes(CONST.BETAS.ALL); + return true; } function canUseDefaultRooms(betas: OnyxEntry): boolean { diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index a2652b8693ee..12d7f1741b7a 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -455,10 +455,10 @@ function MoneyRequestParticipantsSelector({ const onSelectRow = useCallback( (option: Participant) => { - if (option.isPolicyExpenseChat && option.policyID && SubscriptionUtils.shouldRestrictUserBillableActions(option.policyID)) { - Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(option.policyID)); - return; - } + // if (option.isPolicyExpenseChat && option.policyID && SubscriptionUtils.shouldRestrictUserBillableActions(option.policyID)) { + // Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(option.policyID)); + // return; + // } if (isIOUSplit) { addParticipantToSelection(option); diff --git a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx index 0e26306778e9..de13ff6cf620 100644 --- a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx @@ -39,7 +39,7 @@ function IOURequestStepDistanceRate({ const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${IOU.getIOURequestPolicyID(transaction, reportDraft) ?? '-1'}`); /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID || '-1'}`); - const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID || '-1'}`); + const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report?.policyID || '-1'}`); const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID || '-1'}`); /* eslint-enable @typescript-eslint/prefer-nullish-coalescing */ From 46e5519e1ad7d8ee29f4cc976effb23518b1460a Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 10 Oct 2024 08:18:47 +0700 Subject: [PATCH 4/4] revert unnesscary changes --- src/libs/Permissions.ts | 2 +- .../iou/request/MoneyRequestParticipantsSelector.tsx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 1315e1ee3425..9fd94dcb86b8 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -5,7 +5,7 @@ import type Beta from '@src/types/onyx/Beta'; import * as Environment from './Environment/Environment'; function canUseAllBetas(betas: OnyxEntry): boolean { - return true; + return !!betas?.includes(CONST.BETAS.ALL); } function canUseDefaultRooms(betas: OnyxEntry): boolean { diff --git a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx index 12d7f1741b7a..a2652b8693ee 100644 --- a/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx +++ b/src/pages/iou/request/MoneyRequestParticipantsSelector.tsx @@ -455,10 +455,10 @@ function MoneyRequestParticipantsSelector({ const onSelectRow = useCallback( (option: Participant) => { - // if (option.isPolicyExpenseChat && option.policyID && SubscriptionUtils.shouldRestrictUserBillableActions(option.policyID)) { - // Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(option.policyID)); - // return; - // } + if (option.isPolicyExpenseChat && option.policyID && SubscriptionUtils.shouldRestrictUserBillableActions(option.policyID)) { + Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(option.policyID)); + return; + } if (isIOUSplit) { addParticipantToSelection(option);