From 5111487e2f299148b7a09fcaf673ee6849cfc671 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 22 Apr 2024 16:08:55 +0200 Subject: [PATCH 01/10] fix: NAB comments from pull 38543 --- .../MoneyRequestConfirmationList.tsx | 5 +---- .../ReportActionItem/MoneyRequestView.tsx | 10 +++++----- src/libs/DistanceRequestUtils.ts | 19 +++++++++++-------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 1848196bf6ac..4fa57ff4b082 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -749,7 +749,6 @@ function MoneyRequestConfirmationList({ style={[styles.moneyRequestMenuItem]} titleStyle={styles.flex1} onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()))} - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing disabled={didConfirm} // todo: handle edit for transaction while moving from track expense interactive={!isReadOnly && !isMovingTransactionFromTrackExpense} @@ -767,9 +766,7 @@ function MoneyRequestConfirmationList({ description={translate('common.distance')} style={[styles.moneyRequestMenuItem]} titleStyle={styles.flex1} - onPress={() => - Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(CONST.IOU.ACTION.CREATE, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams())) - } + onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()))} disabled={didConfirm} interactive={!isReadOnly} /> diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 10d7b85afc64..09ced8ac4eab 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -67,8 +67,8 @@ type MoneyRequestViewOnyxPropsWithoutTransaction = { /** The actions from the parent report */ parentReportActions: OnyxEntry; - /** The rates for the policy */ - rates: Record; + /** The distance rates from the policy */ + distanceRates: Record; }; type MoneyRequestViewPropsWithoutTransaction = MoneyRequestViewOnyxPropsWithoutTransaction & { @@ -95,7 +95,7 @@ function MoneyRequestView({ policy, transactionViolations, shouldShowAnimatedBackground, - rates, + distanceRates, }: MoneyRequestViewProps) { const theme = useTheme(); const styles = useThemeStyles(); @@ -183,7 +183,7 @@ function MoneyRequestView({ const currency = policy ? policy.outputCurrency : PolicyUtils.getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD; - const mileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(currency) : rates[rateID as string] ?? {}; + const mileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(currency) : distanceRates[rateID as string] ?? {}; const {unit, rate} = mileageRate; const distance = DistanceRequestUtils.getDistanceFromMerchant(transactionMerchant, unit); @@ -578,7 +578,7 @@ export default withOnyx `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : '0'}`, canEvict: false, }, - rates: { + distanceRates: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, selector: DistanceRequestUtils.getMileageRates, }, diff --git a/src/libs/DistanceRequestUtils.ts b/src/libs/DistanceRequestUtils.ts index 676c4493fe75..e7884360915a 100644 --- a/src/libs/DistanceRequestUtils.ts +++ b/src/libs/DistanceRequestUtils.ts @@ -116,7 +116,7 @@ function getRoundedDistanceInUnits(distanceInMeters: number, unit: Unit): string * @param currency The currency associated with the rate * @param translate Translate function * @param toLocaleDigit Function to convert to localized digit - * @returns A string that describes the distance traveled and the rate used for expense calculation + * @returns A string that displays the rate used for expense calculation */ function getRateForDisplay( unit: Unit | undefined, @@ -134,11 +134,11 @@ function getRateForDisplay( } const singularDistanceUnit = unit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? translate('common.mile') : translate('common.kilometer'); - const ratePerUnit = PolicyUtils.getUnitRateValue(toLocaleDigit, {rate}); + const formattedRate = PolicyUtils.getUnitRateValue(toLocaleDigit, {rate}); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const currencySymbol = CurrencyUtils.getCurrencySymbol(currency) || `${currency} `; - return `${currencySymbol}${ratePerUnit} / ${singularDistanceUnit}`; + return `${currencySymbol}${formattedRate} / ${singularDistanceUnit}`; } /** @@ -201,11 +201,7 @@ function getDistanceMerchant( function getMileageRates(policy: OnyxEntry): Record { const mileageRates: Record = {}; - if (!policy) { - return mileageRates; - } - - if (!policy?.customUnits) { + if (!policy || !policy?.customUnits) { return mileageRates; } @@ -227,6 +223,13 @@ function getMileageRates(policy: OnyxEntry): Record return mileageRates; } +/** + * Retrieves the rate and unit for a P2P distance expense for a given currency. + * + * @param currency + * @returns The rate and unit in RateAndUnit object. + */ + function getRateForP2P(currency: string): RateAndUnit { return CONST.CURRENCY_TO_DEFAULT_MILEAGE_RATE[currency] ?? CONST.CURRENCY_TO_DEFAULT_MILEAGE_RATE.USD; } From 69f54e26349d082f402a3115511fbf4ae459d0ac Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 22 Apr 2024 18:21:01 +0200 Subject: [PATCH 02/10] fix: NAB comments + change requested from pull 38543 --- .../MoneyRequestPreviewContent.tsx | 2 +- .../ReportActionItem/MoneyRequestView.tsx | 5 ++++- .../ReportActionItem/ReportPreview.tsx | 2 +- src/languages/en.ts | 2 +- src/languages/es.ts | 2 +- src/libs/DistanceRequestUtils.ts | 21 +++++-------------- src/libs/ReportUtils.ts | 4 ++-- src/libs/actions/IOU.ts | 4 ++-- .../request/step/IOURequestStepDistance.tsx | 6 +++--- 9 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx index 8994d456904a..7f70a3e538a9 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx @@ -196,7 +196,7 @@ function MoneyRequestPreviewContent({ } if (isFetchingWaypointsFromServer && !requestAmount) { - return translate('iou.routePending'); + return translate('iou.fieldPending'); } return CurrencyUtils.convertToDisplayString(requestAmount, requestCurrency); diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 09ced8ac4eab..f15769cda9db 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -40,6 +40,7 @@ import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; +import type {IOUMessage} from '@src/types/onyx/OriginalMessage'; import type {TransactionPendingFieldsKey} from '@src/types/onyx/Transaction'; import ReportActionItemImage from './ReportActionItemImage'; @@ -103,8 +104,9 @@ function MoneyRequestView({ const {isOffline} = useNetwork(); const {isSmallScreenWidth} = useWindowDimensions(); const {translate, toLocaleDigit} = useLocalize(); - const {canUseViolations, canUseP2PDistanceRequests} = usePermissions(); const parentReportAction = parentReportActions?.[report.parentReportActionID ?? ''] ?? null; + const isExpenseTracking = (parentReportAction?.originalMessage as IOUMessage)?.type === CONST.IOU.REPORT_ACTION_TYPE.TRACK; + const {canUseViolations, canUseP2PDistanceRequests} = usePermissions(isExpenseTracking ? CONST.IOU.TYPE.TRACK_EXPENSE : undefined); const moneyRequestReport = parentReport; const { created: transactionDate, @@ -289,6 +291,7 @@ function MoneyRequestView({ } /> + {/* TODO: correct the pending field action https://github.com/Expensify/App/issues/36988 (?) */} = {}; -Onyx.connect({ - key: ONYXKEYS.COLLECTION.POLICY, - callback: (policy, key) => { - if (!policy || !key || !policy.name) { - return; - } - - policies[key] = policy; - }, -}); - let lastSelectedDistanceRates: OnyxEntry = {}; Onyx.connect({ key: ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES, @@ -49,6 +37,7 @@ Onyx.connect({ const METERS_TO_KM = 0.001; // 1 kilometer is 1000 meters const METERS_TO_MILES = 0.000621371; // There are approximately 0.000621371 miles in a meter +const distanceMerchantRegex = /^[0-9.]+ \w+ @ (-|-\()?(\p{Sc}|\p{L}|\w){1,3} ?[0-9.]+\)? \/ \w+$/u; /** * Retrieves the default mileage rate based on a given policy. @@ -130,7 +119,7 @@ function getRateForDisplay( return translate('iou.defaultRate'); } if (!rate || !currency || !unit) { - return translate('iou.routePending'); + return translate('iou.fieldPending'); } const singularDistanceUnit = unit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? translate('common.mile') : translate('common.kilometer'); @@ -151,7 +140,7 @@ function getRateForDisplay( */ function getDistanceForDisplay(hasRoute: boolean, distanceInMeters: number, unit: Unit | undefined, rate: number | undefined, translate: LocaleContextProps['translate']): string { if (!hasRoute || !rate || !unit) { - return translate('iou.routePending'); + return translate('iou.fieldPending'); } const distanceInUnits = getRoundedDistanceInUnits(distanceInMeters, unit); @@ -182,7 +171,7 @@ function getDistanceMerchant( toLocaleDigit: LocaleContextProps['toLocaleDigit'], ): string { if (!hasRoute || !rate) { - return translate('iou.routePending'); + return translate('iou.fieldPending'); } const distanceInUnits = getDistanceForDisplay(hasRoute, distanceInMeters, unit, rate, translate); @@ -255,7 +244,7 @@ function getDistanceRequestAmount(distance: number, unit: Unit, rate: number): n * @returns The distance extracted from the merchant string. */ function getDistanceFromMerchant(merchant: string | undefined, unit: Unit): number { - if (!merchant) { + if (!merchant || !distanceMerchantRegex.test(merchant ?? '')) { return 0; } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fc677dedc96e..aad7cf63fc86 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2629,7 +2629,7 @@ function getTransactionReportName(reportAction: OnyxEntry Date: Mon, 22 Apr 2024 20:09:45 +0200 Subject: [PATCH 03/10] fix: typecheck error --- 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 1effe667f2a5..cdea49755471 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -106,7 +106,7 @@ function MoneyRequestView({ const {translate, toLocaleDigit} = useLocalize(); const parentReportAction = parentReportActions?.[report.parentReportActionID ?? ''] ?? null; const isExpenseTracking = (parentReportAction?.originalMessage as IOUMessage)?.type === CONST.IOU.REPORT_ACTION_TYPE.TRACK; - const {canUseViolations, canUseP2PDistanceRequests} = usePermissions(isExpenseTracking ? CONST.IOU.TYPE.TRACK_EXPENSE : undefined); + const {canUseViolations, canUseP2PDistanceRequests} = usePermissions(isExpenseTracking ? CONST.IOU.TYPE.TRACK : undefined); const moneyRequestReport = parentReport; const { created: transactionDate, From 7851a8b3720fb587119f9c4121cdc781d1cce8c8 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 22 Apr 2024 20:25:55 +0200 Subject: [PATCH 04/10] fix: show pending field when route is 0 --- src/libs/DistanceRequestUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/DistanceRequestUtils.ts b/src/libs/DistanceRequestUtils.ts index 8f1b2bc6df5e..5ba0762b307a 100644 --- a/src/libs/DistanceRequestUtils.ts +++ b/src/libs/DistanceRequestUtils.ts @@ -139,7 +139,7 @@ function getRateForDisplay( * @returns A string that describes the distance traveled */ function getDistanceForDisplay(hasRoute: boolean, distanceInMeters: number, unit: Unit | undefined, rate: number | undefined, translate: LocaleContextProps['translate']): string { - if (!hasRoute || !rate || !unit) { + if (!hasRoute || !rate || !unit || !distanceInMeters) { return translate('iou.fieldPending'); } From 535cc20e14834be2bc34b0ced517b00475aec90d Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 22 Apr 2024 21:23:16 +0200 Subject: [PATCH 05/10] fix: apply requested changes --- src/components/ReportActionItem/MoneyRequestView.tsx | 3 ++- src/libs/DistanceRequestUtils.ts | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index cdea49755471..0a73cee2984f 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -189,7 +189,8 @@ function MoneyRequestView({ const currency = policy ? policy.outputCurrency : PolicyUtils.getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD; const mileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(currency) : distanceRates[rateID as string] ?? {}; - const {unit, rate} = mileageRate; + const {unit} = mileageRate; + const rate = (transaction?.comment?.customUnit?.defaultP2PRate as number) ?? mileageRate.rate; const distance = DistanceRequestUtils.getDistanceFromMerchant(transactionMerchant, unit); const rateToDisplay = DistanceRequestUtils.getRateForDisplay(unit, rate, currency, translate, toLocaleDigit, isOffline); diff --git a/src/libs/DistanceRequestUtils.ts b/src/libs/DistanceRequestUtils.ts index 5ba0762b307a..a485541942bc 100644 --- a/src/libs/DistanceRequestUtils.ts +++ b/src/libs/DistanceRequestUtils.ts @@ -37,6 +37,11 @@ Onyx.connect({ const METERS_TO_KM = 0.001; // 1 kilometer is 1000 meters const METERS_TO_MILES = 0.000621371; // There are approximately 0.000621371 miles in a meter + +/** Validates that the merchant for a distance request transaction is in the expected format. + * @ / + * Example: 1.45 miles @ $0.67 / mi + */ const distanceMerchantRegex = /^[0-9.]+ \w+ @ (-|-\()?(\p{Sc}|\p{L}|\w){1,3} ?[0-9.]+\)? \/ \w+$/u; /** From eefa1529b7216f5f66e78b87ef09e8461a7f4cd3 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 22 Apr 2024 21:57:21 +0200 Subject: [PATCH 06/10] fix: get the distance from comment quantity --- .../ReportActionItem/MoneyRequestView.tsx | 2 +- src/libs/DistanceRequestUtils.ts | 28 ++++++------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 0a73cee2984f..cba2b26a583d 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -192,7 +192,7 @@ function MoneyRequestView({ const {unit} = mileageRate; const rate = (transaction?.comment?.customUnit?.defaultP2PRate as number) ?? mileageRate.rate; - const distance = DistanceRequestUtils.getDistanceFromMerchant(transactionMerchant, unit); + const distance = DistanceRequestUtils.convertToDistanceInMeters((transaction?.comment?.customUnit?.quantity as number) ?? 0, unit); const rateToDisplay = DistanceRequestUtils.getRateForDisplay(unit, rate, currency, translate, toLocaleDigit, isOffline); const distanceToDisplay = DistanceRequestUtils.getDistanceForDisplay(hasRoute, distance, unit, rate, translate); diff --git a/src/libs/DistanceRequestUtils.ts b/src/libs/DistanceRequestUtils.ts index a485541942bc..d88a2ab080e9 100644 --- a/src/libs/DistanceRequestUtils.ts +++ b/src/libs/DistanceRequestUtils.ts @@ -38,12 +38,6 @@ Onyx.connect({ const METERS_TO_KM = 0.001; // 1 kilometer is 1000 meters const METERS_TO_MILES = 0.000621371; // There are approximately 0.000621371 miles in a meter -/** Validates that the merchant for a distance request transaction is in the expected format. - * @ / - * Example: 1.45 miles @ $0.67 / mi - */ -const distanceMerchantRegex = /^[0-9.]+ \w+ @ (-|-\()?(\p{Sc}|\p{L}|\w){1,3} ?[0-9.]+\)? \/ \w+$/u; - /** * Retrieves the default mileage rate based on a given policy. * @@ -243,22 +237,18 @@ function getDistanceRequestAmount(distance: number, unit: Unit, rate: number): n } /** - * Extracts the distance from a merchant string. + * Converts the distance from kilometers or miles to meters. * - * @param merchant - The merchant string containing the distance. - * @returns The distance extracted from the merchant string. + * @param distance - The distance to be converted. + * @param unit - The unit of measurement for the distance. + * @returns The distance in meters. */ -function getDistanceFromMerchant(merchant: string | undefined, unit: Unit): number { - if (!merchant || !distanceMerchantRegex.test(merchant ?? '')) { - return 0; - } - const distance = Number(merchant.split(' ')[0]); - if (!distance) { - return 0; +function convertToDistanceInMeters(distance: number, unit: Unit): number { + if (unit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_KILOMETERS) { + return distance / METERS_TO_KM; } - // we need to convert the distance back to meters (it's saved in kilometers or miles in merchant) to pass it to getDistanceForDisplay - return unit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_KILOMETERS ? distance / METERS_TO_KM : distance / METERS_TO_MILES; + return distance / METERS_TO_MILES; } /** @@ -286,8 +276,8 @@ export default { getMileageRates, getDistanceForDisplay, getRateForP2P, - getDistanceFromMerchant, getCustomUnitRateID, + convertToDistanceInMeters, }; export type {MileageRate}; From 5355ccad141aa2be0a6df496d533353512a15740 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 22 Apr 2024 22:17:36 +0200 Subject: [PATCH 07/10] fix: fix initially focused option --- src/pages/iou/request/step/IOURequestStepDistanceRate.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx index 160d4903a512..1b9ccf1876cf 100644 --- a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx @@ -66,7 +66,7 @@ function IOURequestStepDistanceRate({ const unit = (Object.values(rates)[0]?.unit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? translate('common.mile') : translate('common.kilometer')) as Unit; - const initiallyFocusedOption = rates[lastSelectedRateID]?.name ?? CONST.CUSTOM_UNITS.DEFAULT_RATE; + const initiallyFocusedOption = sections.find((item) => item.isSelected)?.keyForList; function selectDistanceRate(customUnitRateID: string) { IOU.updateDistanceRequestRate(transactionID, customUnitRateID, policy?.id ?? ''); From 895d37e6c51b5ca07873d1ebfc3d7417903ef9ac Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 23 Apr 2024 11:24:34 +0200 Subject: [PATCH 08/10] fix: minor fixes --- src/components/ReportActionItem/MoneyRequestView.tsx | 2 +- src/libs/DistanceRequestUtils.ts | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index cba2b26a583d..cdfe3aae0986 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -293,7 +293,7 @@ function MoneyRequestView({ onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID))} /> - {/* TODO: correct the pending field action https://github.com/Expensify/App/issues/36988 (?) */} + {/* TODO: correct the pending field action https://github.com/Expensify/App/issues/36988 */} ): Record * @param currency * @returns The rate and unit in RateAndUnit object. */ - function getRateForP2P(currency: string): RateAndUnit { return CONST.CURRENCY_TO_DEFAULT_MILEAGE_RATE[currency] ?? CONST.CURRENCY_TO_DEFAULT_MILEAGE_RATE.USD; } @@ -243,7 +242,6 @@ function getDistanceRequestAmount(distance: number, unit: Unit, rate: number): n * @param unit - The unit of measurement for the distance. * @returns The distance in meters. */ - function convertToDistanceInMeters(distance: number, unit: Unit): number { if (unit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_KILOMETERS) { return distance / METERS_TO_KM; From f88f23d2c92d394cf34c5c39321fe0628db96915 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 23 Apr 2024 18:47:34 +0200 Subject: [PATCH 09/10] fix: display pending while changing the distance, block editing distance for tracked expense --- src/components/ReportActionItem/MoneyRequestView.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index cdfe3aae0986..e389ad42ae78 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -40,7 +40,6 @@ import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; -import type {IOUMessage} from '@src/types/onyx/OriginalMessage'; import type {TransactionPendingFieldsKey} from '@src/types/onyx/Transaction'; import ReportActionItemImage from './ReportActionItemImage'; @@ -105,8 +104,8 @@ function MoneyRequestView({ const {isSmallScreenWidth} = useWindowDimensions(); const {translate, toLocaleDigit} = useLocalize(); const parentReportAction = parentReportActions?.[report.parentReportActionID ?? ''] ?? null; - const isExpenseTracking = (parentReportAction?.originalMessage as IOUMessage)?.type === CONST.IOU.REPORT_ACTION_TYPE.TRACK; - const {canUseViolations, canUseP2PDistanceRequests} = usePermissions(isExpenseTracking ? CONST.IOU.TYPE.TRACK : undefined); + const isTrackExpense = ReportUtils.isTrackExpenseReport(report); + const {canUseViolations, canUseP2PDistanceRequests} = usePermissions(isTrackExpense ? CONST.IOU.TYPE.TRACK : undefined); const moneyRequestReport = parentReport; const { created: transactionDate, @@ -152,7 +151,8 @@ function MoneyRequestView({ const canEditMerchant = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.MERCHANT); const canEditDate = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DATE); const canEditReceipt = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.RECEIPT); - const canEditDistance = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE); + // TODO: remove the !isTrackExpense from this condition after this fix: https://github.com/Expensify/Expensify/issues/382786 + const canEditDistance = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, CONST.EDIT_REQUEST_FIELD.DISTANCE) && !isTrackExpense; // A flag for verifying that the current report is a sub-report of a workspace chat // if the policy of the report is either Collect or Control, then this report must be tied to workspace chat @@ -160,7 +160,6 @@ function MoneyRequestView({ const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTagList), [policyTagList]); - const isTrackExpense = ReportUtils.isTrackExpenseReport(report); const iouType = isTrackExpense ? CONST.IOU.TYPE.TRACK : CONST.IOU.TYPE.SUBMIT; // Flags for showing categories and tags @@ -286,7 +285,7 @@ function MoneyRequestView({ Date: Tue, 23 Apr 2024 20:53:05 +0200 Subject: [PATCH 10/10] fix: minor fix --- 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 e389ad42ae78..08bcc16cbbee 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -292,7 +292,7 @@ function MoneyRequestView({ onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(CONST.IOU.ACTION.EDIT, iouType, transaction?.transactionID ?? '', report.reportID))} /> - {/* TODO: correct the pending field action https://github.com/Expensify/App/issues/36988 */} + {/* TODO: correct the pending field action https://github.com/Expensify/App/issues/36987 */}