diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 9044f43eabb9..33fb66807bc6 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -583,6 +583,9 @@ function clearAvatarErrors(policyID) { * @param {String} currency */ function updateGeneralSettings(policyID, name, currency) { + const policy = allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; + const distanceUnit = _.find(_.values(policy.customUnits), (unit) => unit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE); + const distanceRate = _.find(_.values(distanceUnit ? distanceUnit.rates : {}), (rate) => rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE); const optimisticData = [ { // We use SET because it's faster than merge and avoids a race condition when setting the currency and navigating the user to the Bank account page in confirmCurrencyChangeAndHideModal @@ -601,6 +604,21 @@ function updateGeneralSettings(policyID, name, currency) { }, name, outputCurrency: currency, + ...(distanceUnit + ? { + customUnits: { + [distanceUnit.customUnitID]: { + ...distanceUnit, + rates: { + [distanceRate.customUnitRateID]: { + ...distanceRate, + currency, + }, + }, + }, + }, + } + : {}), }, }, ]; @@ -626,6 +644,13 @@ function updateGeneralSettings(policyID, name, currency) { errorFields: { generalSettings: ErrorUtils.getMicroSecondOnyxError('workspace.editor.genericFailureMessage'), }, + ...(distanceUnit + ? { + customUnits: { + [distanceUnit.customUnitID]: distanceUnit, + }, + } + : {}), }, }, ];