Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out rate with pending action #41997

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ 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;

// Rates can be disabled or deleted as long as in the remaining rates there is always at least one enabled rate and there are no pending delete action
const canDisableOrDeleteRate = Object.values(customUnit?.rates).some(
Copy link
Contributor

@ishpaul777 ishpaul777 May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a regression #41293 (comment), this reintroduced #40481, we are handling this as follow up of orignal issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishpaul777 We need to update to

const canDisableOrDeleteRate = Object.values(customUnit?.rates ?? {})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR here: #42502

(distanceRate: Rate) => distanceRate?.enabled && rateID !== distanceRate?.customUnitRateID && distanceRate?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
);
const errorFields = rate?.errorFields;

if (!rate) {
Expand All @@ -61,7 +64,7 @@ function PolicyDistanceRateDetailsPage({policy, route}: PolicyDistanceRateDetail
};

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