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

fix: Distance rates - Enabled distance rate changes to Disabled after deleting it. #48859

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion src/libs/actions/Policy/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ function deleteWorkspaceCategories(policyID: string, categoryNamesToDelete: stri
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
const policyCategories = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`] ?? {};
const optimisticPolicyCategoriesData = categoryNamesToDelete.reduce<Record<string, Partial<PolicyCategory>>>((acc, categoryName) => {
acc[categoryName] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE};
acc[categoryName] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, enabled: false};
return acc;
}, {});
const shouldDisableRequiresCategory = !OptionsListUtils.hasEnabledOptions(
Expand Down Expand Up @@ -878,6 +878,7 @@ function deleteWorkspaceCategories(policyID: string, categoryNamesToDelete: stri
acc[categoryName] = {
pendingAction: null,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.categories.deleteFailureMessage'),
enabled: !!policyCategories?.[categoryName]?.enabled,
};
return acc;
}, {}),
Expand Down
8 changes: 6 additions & 2 deletions src/libs/actions/Policy/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ function deletePolicyTags(policyID: string, tagsToDelete: string[]) {
[policyTag.name]: {
tags: {
...tagsToDelete.reduce<Record<string, Partial<OnyxValueWithOfflineFeedback<PolicyTag>>>>((acc, tagName) => {
acc[tagName] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE};
acc[tagName] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, enabled: false};
return acc;
}, {}),
},
Expand Down Expand Up @@ -388,7 +388,11 @@ function deletePolicyTags(policyID: string, tagsToDelete: string[]) {
[policyTag.name]: {
tags: {
...tagsToDelete.reduce<Record<string, Partial<OnyxValueWithOfflineFeedback<PolicyTag>>>>((acc, tagName) => {
acc[tagName] = {pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.tags.deleteFailureMessage')};
acc[tagName] = {
pendingAction: null,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.tags.deleteFailureMessage'),
enabled: !!policyTag?.tags[tagName]?.enabled,
};
return acc;
}, {}),
},
Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/TaxRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function setPolicyTaxesEnabled(policyID: string, taxesIDsToUpdate: string[], isE

type TaxRateDeleteMap = Record<
string,
| (Pick<TaxRate, 'pendingAction'> & {
| (Pick<TaxRate, 'pendingAction' | 'isDisabled'> & {
errors: OnyxCommon.Errors | null;
})
| null
Expand Down Expand Up @@ -306,7 +306,7 @@ function deletePolicyTaxes(policyID: string, taxesToDelete: string[]) {
pendingFields: {foreignTaxDefault: isForeignTaxRemoved ? CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE : null},
foreignTaxDefault: isForeignTaxRemoved ? firstTaxID : foreignTaxDefault,
taxes: taxesToDelete.reduce<TaxRateDeleteMap>((acc, taxID) => {
acc[taxID] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, errors: null};
acc[taxID] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, errors: null, isDisabled: true};
return acc;
}, {}),
},
Expand Down Expand Up @@ -339,6 +339,7 @@ function deletePolicyTaxes(policyID: string, taxesToDelete: string[]) {
acc[taxID] = {
pendingAction: null,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.taxes.error.deleteFailureMessage'),
isDisabled: !!policyTaxRates?.[taxID]?.isDisabled,
};
return acc;
}, {}),
Expand Down
Loading