From e24235dc155a57e6c522245cf6807c174d9d00cd Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 6 Jun 2024 15:26:40 -0600 Subject: [PATCH] Merge pull request #43226 from Expensify/camrtins-fixCustomunitCrash [CP Staging] Fix crash when submitting expense on a newly created workspace (cherry picked from commit 69863d5e7f872196f890b20d7f1bff08a9e6813c) --- src/libs/DistanceRequestUtils.ts | 4 ++-- src/libs/actions/Policy/Policy.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/DistanceRequestUtils.ts b/src/libs/DistanceRequestUtils.ts index ed4a6a73c9b9..cbae1e0d3bfb 100644 --- a/src/libs/DistanceRequestUtils.ts +++ b/src/libs/DistanceRequestUtils.ts @@ -52,7 +52,7 @@ function getMileageRates(policy: OnyxEntry, includeDisabledRates = false } Object.entries(distanceUnit.rates).forEach(([rateID, rate]) => { - if (!includeDisabledRates && !rate.enabled) { + if (!includeDisabledRates && rate.enabled === false) { return; } @@ -89,7 +89,7 @@ function getDefaultMileageRate(policy: OnyxEntry | EmptyObject): Mileage } const mileageRates = getMileageRates(policy); - const distanceRate = Object.values(mileageRates).find((rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE) ?? Object.values(mileageRates)[0]; + const distanceRate = Object.values(mileageRates).find((rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE) ?? Object.values(mileageRates)[0] ?? {}; return { customUnitRateID: distanceRate.customUnitRateID, diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index a44a989ac91a..08aa0254ddc7 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -2000,6 +2000,7 @@ function buildOptimisticCustomUnits(): OptimisticCustomUnits { customUnitRateID, name: CONST.CUSTOM_UNITS.DEFAULT_RATE, rate: CONST.CUSTOM_UNITS.MILEAGE_IRS_RATE * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, + enabled: true, currency, }, },