From c95e5e9225b48e110357406a601a8881153693ed Mon Sep 17 00:00:00 2001 From: I Nyoman Jyotisa Date: Thu, 3 Oct 2024 18:37:07 +0800 Subject: [PATCH 1/7] [P2P Distance] Rate currency doesn't match expense currency --- src/components/ReportActionItem/MoneyRequestView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 66c773ab9534..332b9d214de8 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -213,7 +213,7 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals const hasRoute = TransactionUtils.hasRoute(transactionBackup ?? transaction, isDistanceRequest); const rateID = TransactionUtils.getRateID(transaction) ?? '-1'; - const currency = policy ? policy.outputCurrency : PolicyUtils.getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD; + const currency = transactionCurrency ?? CONST.CURRENCY.USD; const mileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(currency) : distanceRates[rateID] ?? {}; const {unit} = mileageRate; From 9136e8a0b1f765feaae603135be1a417534e16e5 Mon Sep 17 00:00:00 2001 From: I Nyoman Jyotisa Date: Tue, 8 Oct 2024 20:17:03 +0800 Subject: [PATCH 2/7] set the selected rates to the transaction currency and make prompt text agnostic --- src/languages/en.ts | 3 +-- src/languages/es.ts | 3 +-- src/languages/params.ts | 3 --- .../iou/request/step/IOURequestStepDistanceRate.tsx | 10 +++++++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 18dcbe35c9f6..b0fbf03298f0 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -109,7 +109,6 @@ import type { PayerSettledParams, PaySomeoneParams, ReconciliationWorksParams, - ReimbursementRateParams, RemovedFromApprovalWorkflowParams, RemovedTheRequestParams, RemoveMemberPromptParams, @@ -1009,7 +1008,7 @@ const translations = { changed: 'changed', removed: 'removed', transactionPending: 'Transaction pending.', - chooseARate: ({unit}: ReimbursementRateParams) => `Select a workspace reimbursement rate per ${unit}`, + chooseARate: `Select a workspace reimbursement rate per mile or kilometer`, unapprove: 'Unapprove', unapproveReport: 'Unapprove report', headsUp: 'Heads up!', diff --git a/src/languages/es.ts b/src/languages/es.ts index 8e16c03a91d3..aad4b3967866 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -107,7 +107,6 @@ import type { PayerSettledParams, PaySomeoneParams, ReconciliationWorksParams, - ReimbursementRateParams, RemovedFromApprovalWorkflowParams, RemovedTheRequestParams, RemoveMemberPromptParams, @@ -1003,7 +1002,7 @@ const translations = { changed: 'cambió', removed: 'eliminó', transactionPending: 'Transacción pendiente.', - chooseARate: ({unit}: ReimbursementRateParams) => `Selecciona una tasa de reembolso por ${unit} del espacio de trabajo`, + chooseARate: `Selecciona una tasa de reembolso por milla o kilómetro para el espacio de trabajo`, unapprove: 'Desaprobar', unapproveReport: 'Anular la aprobación del informe', headsUp: 'Atención!', diff --git a/src/languages/params.ts b/src/languages/params.ts index 5560316d2ddd..893b02e97591 100644 --- a/src/languages/params.ts +++ b/src/languages/params.ts @@ -279,8 +279,6 @@ type LogSizeAndDateParams = {size: number; date: string}; type HeldRequestParams = {comment: string}; -type ReimbursementRateParams = {unit: Unit}; - type ChangeFieldParams = {oldValue?: string; newValue: string; fieldName: string}; type ChangePolicyParams = {fromPolicy: string; toPolicy: string}; @@ -648,7 +646,6 @@ export type { PayerPaidAmountParams, PayerPaidParams, PayerSettledParams, - ReimbursementRateParams, RemovedTheRequestParams, RenamedRoomActionParams, ReportArchiveReasonsClosedParams, diff --git a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx index 59e1591a23ff..096651089cab 100644 --- a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx @@ -64,6 +64,8 @@ function IOURequestStepDistanceRate({ const currentRateID = TransactionUtils.getRateID(transaction) ?? '-1'; + const transactionCurrency = TransactionUtils.getCurrency(transaction); + const rates = DistanceRequestUtils.getMileageRates(policy, false, currentRateID); const navigateBack = () => { @@ -71,7 +73,9 @@ function IOURequestStepDistanceRate({ }; const sections = Object.values(rates).map((rate) => { - const rateForDisplay = DistanceRequestUtils.getRateForDisplay(rate.unit, rate.rate, rate.currency, translate, toLocaleDigit); + const isSelected = currentRateID ? currentRateID === rate.customUnitRateID : rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE; + + const rateForDisplay = DistanceRequestUtils.getRateForDisplay(rate.unit, rate.rate, isSelected ? transactionCurrency : rate.currency, translate, toLocaleDigit); return { text: rate.name ?? rateForDisplay, @@ -79,7 +83,7 @@ function IOURequestStepDistanceRate({ keyForList: rate.customUnitRateID, value: rate.customUnitRateID, isDisabled: !rate.enabled, - isSelected: currentRateID ? currentRateID === rate.customUnitRateID : rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE, + isSelected, }; }); @@ -118,7 +122,7 @@ function IOURequestStepDistanceRate({ shouldShowWrapper testID={IOURequestStepDistanceRate.displayName} > - {translate('iou.chooseARate', {unit})} + {translate('iou.chooseARate')} Date: Tue, 8 Oct 2024 20:19:49 +0800 Subject: [PATCH 3/7] lint fix --- src/languages/params.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/params.ts b/src/languages/params.ts index 893b02e97591..e4a52f5150fd 100644 --- a/src/languages/params.ts +++ b/src/languages/params.ts @@ -1,6 +1,6 @@ import type {OnyxInputOrEntry, ReportAction} from '@src/types/onyx'; import type {DelegateRole} from '@src/types/onyx/Account'; -import type {AllConnectionName, ConnectionName, PolicyConnectionSyncStage, SageIntacctMappingName, Unit} from '@src/types/onyx/Policy'; +import type {AllConnectionName, ConnectionName, PolicyConnectionSyncStage, SageIntacctMappingName} from '@src/types/onyx/Policy'; import type {ViolationDataType} from '@src/types/onyx/TransactionViolation'; type AddressLineParams = { From 5a7ada0c7df68a7c9370e03ce1a30398e1075e1b Mon Sep 17 00:00:00 2001 From: I Nyoman Jyotisa Date: Tue, 8 Oct 2024 21:14:38 +0800 Subject: [PATCH 4/7] migrate 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 096651089cab..b2d633a9b880 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 ? report.policyID : '-1'}`); + const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`); + const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`); const policy = policyReal ?? policyDraft; @@ -137,20 +125,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 36a4e27d7637d710b24a53aa1992c8ec606d954d Mon Sep 17 00:00:00 2001 From: I Nyoman Jyotisa Date: Tue, 8 Oct 2024 21:27:01 +0800 Subject: [PATCH 5/7] minor fix --- src/languages/en.ts | 2 +- src/languages/es.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index b0fbf03298f0..f4faade51600 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1008,7 +1008,7 @@ const translations = { changed: 'changed', removed: 'removed', transactionPending: 'Transaction pending.', - chooseARate: `Select a workspace reimbursement rate per mile or kilometer`, + chooseARate: 'Select a workspace reimbursement rate per mile or kilometer', unapprove: 'Unapprove', unapproveReport: 'Unapprove report', headsUp: 'Heads up!', diff --git a/src/languages/es.ts b/src/languages/es.ts index aad4b3967866..99d240c2372c 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1002,7 +1002,7 @@ const translations = { changed: 'cambió', removed: 'eliminó', transactionPending: 'Transacción pendiente.', - chooseARate: `Selecciona una tasa de reembolso por milla o kilómetro para el espacio de trabajo`, + chooseARate: 'Selecciona una tasa de reembolso por milla o kilómetro para el espacio de trabajo', unapprove: 'Desaprobar', unapproveReport: 'Anular la aprobación del informe', headsUp: 'Atención!', From 7f557e0a0b225fda6979efaa3cae6ac2189bfa85 Mon Sep 17 00:00:00 2001 From: I Nyoman Jyotisa Date: Fri, 11 Oct 2024 08:31:41 +0800 Subject: [PATCH 6/7] update the selected currency on rate modal when workspace currency changes --- src/components/MoneyRequestConfirmationList.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 1faef0c6b44c..635a31e06623 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -292,7 +292,9 @@ function MoneyRequestConfirmationList({ const distance = TransactionUtils.getDistanceInMeters(transaction, unit); const prevDistance = usePrevious(distance); - const shouldCalculateDistanceAmount = isDistanceRequest && (iouAmount === 0 || prevRate !== rate || prevDistance !== distance); + const prevCurrency = usePrevious(currency); + + const shouldCalculateDistanceAmount = isDistanceRequest && (iouAmount === 0 || prevRate !== rate || prevDistance !== distance || prevCurrency !== currency); const hasRoute = TransactionUtils.hasRoute(transaction, isDistanceRequest); const isDistanceRequestWithPendingRoute = isDistanceRequest && (!hasRoute || !rate) && !isMovingTransactionFromTrackExpense; From 3a08cffff41e06b0ee3dddc813d995ab604b6c81 Mon Sep 17 00:00:00 2001 From: I Nyoman Jyotisa Date: Fri, 11 Oct 2024 21:29:02 +0800 Subject: [PATCH 7/7] minor fix --- src/components/MoneyRequestConfirmationList.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 635a31e06623..f14ee940e329 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -256,6 +256,7 @@ function MoneyRequestConfirmationList({ const prevRate = usePrevious(rate); const currency = (mileageRate as MileageRate)?.currency ?? policyCurrency; + const prevCurrency = usePrevious(currency); // A flag for showing the categories field const shouldShowCategories = (isPolicyExpenseChat || isTypeInvoice) && (!!iouCategory || OptionsListUtils.hasEnabledOptions(Object.values(policyCategories ?? {}))); @@ -292,8 +293,6 @@ function MoneyRequestConfirmationList({ const distance = TransactionUtils.getDistanceInMeters(transaction, unit); const prevDistance = usePrevious(distance); - const prevCurrency = usePrevious(currency); - const shouldCalculateDistanceAmount = isDistanceRequest && (iouAmount === 0 || prevRate !== rate || prevDistance !== distance || prevCurrency !== currency); const hasRoute = TransactionUtils.hasRoute(transaction, isDistanceRequest);