Skip to content

Commit

Permalink
filter out rate with pending action
Browse files Browse the repository at this point in the history
  • Loading branch information
cretadn22 committed May 11, 2024
1 parent c00ca12 commit 96e0fd8
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ function PolicyDistanceRateDetailsPage({policy, route}: PolicyDistanceRateDetail
const customUnit = customUnits[Object.keys(customUnits)[0]];
const rate = customUnit.rates[rateID];
const currency = rate.currency ?? CONST.CURRENCY.USD;
const canDeleteRate = Object.values(customUnit.rates).filter((distanceRate) => distanceRate.enabled).length > 1 || !rate.enabled;
const canDisableRate = Object.values(customUnit.rates).filter((distanceRate) => distanceRate.enabled).length > 1;
const canDisableorDeleteRate = Object.values(customUnit.rates).some(
(distanceRate: Rate) => distanceRate.enabled && rateID !== distanceRate.customUnitRateID && distanceRate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
);
const errorFields = rate.errorFields;

const editRateValue = () => {
Navigation.navigate(ROUTES.WORKSPACE_DISTANCE_RATE_EDIT.getRoute(policyID, rateID));
};

const toggleRate = () => {
if (!rate.enabled || canDisableRate) {
if (!rate.enabled || canDisableorDeleteRate) {
Policy.setPolicyDistanceRatesEnabled(policyID, customUnit, [{...rate, enabled: !rate.enabled}]);
} else {
setIsWarningModalVisible(true);
Expand All @@ -77,7 +78,7 @@ function PolicyDistanceRateDetailsPage({policy, route}: PolicyDistanceRateDetail
icon: Expensicons.Trashcan,
text: translate('workspace.distanceRates.deleteDistanceRate'),
onSelected: () => {
if (canDeleteRate) {
if (canDisableorDeleteRate) {
setIsDeleteModalVisible(true);
return;
}
Expand Down

0 comments on commit 96e0fd8

Please sign in to comment.