From b3d60f1ce39f7531a94047d8690c75445adb2d56 Mon Sep 17 00:00:00 2001 From: Sachin Chavda Date: Mon, 14 Oct 2024 17:23:21 +0530 Subject: [PATCH] Sort Disstance Rates on IOURequestsStepDistanceRate.tsx --- .../step/IOURequestStepDistanceRate.tsx | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx index 59e1591a23ff..87ebf52b2288 100644 --- a/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistanceRate.tsx @@ -70,18 +70,20 @@ function IOURequestStepDistanceRate({ Navigation.goBack(backTo); }; - const sections = Object.values(rates).map((rate) => { - const rateForDisplay = DistanceRequestUtils.getRateForDisplay(rate.unit, rate.rate, rate.currency, translate, toLocaleDigit); - - return { - text: rate.name ?? rateForDisplay, - alternateText: rate.name ? rateForDisplay : '', - keyForList: rate.customUnitRateID, - value: rate.customUnitRateID, - isDisabled: !rate.enabled, - isSelected: currentRateID ? currentRateID === rate.customUnitRateID : rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE, - }; - }); + const sections = Object.values(rates) + .sort((rateA, rateB) => (rateA?.rate ?? 0) - (rateB?.rate ?? 0)) + .map((rate) => { + const rateForDisplay = DistanceRequestUtils.getRateForDisplay(rate.unit, rate.rate, rate.currency, translate, toLocaleDigit); + + return { + text: rate.name ?? rateForDisplay, + alternateText: rate.name ? rateForDisplay : '', + keyForList: rate.customUnitRateID, + value: rate.customUnitRateID, + isDisabled: !rate.enabled, + isSelected: currentRateID ? currentRateID === rate.customUnitRateID : rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE, + }; + }); const unit = (Object.values(rates).at(0)?.unit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? translate('common.mile') : translate('common.kilometer')) as Unit;