Skip to content

Commit

Permalink
Merge pull request #48859 from Krishna2323/krishna2323/issue/48290
Browse files Browse the repository at this point in the history
fix: Distance rates - Enabled distance rate changes to Disabled after deleting it.
  • Loading branch information
puneetlath authored Oct 6, 2024
2 parents 6155703 + 0bc1ada commit 6d8e739
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
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

0 comments on commit 6d8e739

Please sign in to comment.