From fd3dac22f82fbef3c1079589ed5964dac43354b6 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 10 Sep 2024 10:26:18 +0530 Subject: [PATCH 1/3] fix: Distance rates - Enabled distance rate changes to Disabled after deleting it. Signed-off-by: krishna2323 --- src/libs/actions/Policy/Category.ts | 3 ++- src/libs/actions/Policy/Tag.ts | 8 ++++++-- src/libs/actions/TaxRate.ts | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index 16d28481f06f..bbaca4104d55 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -790,7 +790,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>>((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( @@ -822,6 +822,7 @@ function deleteWorkspaceCategories(policyID: string, categoryNamesToDelete: stri acc[categoryName] = { pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.categories.deleteFailureMessage'), + enabled: policyCategories?.[categoryName].enabled, }; return acc; }, {}), diff --git a/src/libs/actions/Policy/Tag.ts b/src/libs/actions/Policy/Tag.ts index 49a285c12bbe..8441a32ea8d9 100644 --- a/src/libs/actions/Policy/Tag.ts +++ b/src/libs/actions/Policy/Tag.ts @@ -298,7 +298,7 @@ function deletePolicyTags(policyID: string, tagsToDelete: string[]) { [policyTag.name]: { tags: { ...tagsToDelete.reduce>>>((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; }, {}), }, @@ -330,7 +330,11 @@ function deletePolicyTags(policyID: string, tagsToDelete: string[]) { [policyTag.name]: { tags: { ...tagsToDelete.reduce>>>((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; }, {}), }, diff --git a/src/libs/actions/TaxRate.ts b/src/libs/actions/TaxRate.ts index 514b73915633..179d71743017 100644 --- a/src/libs/actions/TaxRate.ts +++ b/src/libs/actions/TaxRate.ts @@ -275,7 +275,7 @@ function setPolicyTaxesEnabled(policyID: string, taxesIDsToUpdate: string[], isE type TaxRateDeleteMap = Record< string, - | (Pick & { + | (Pick & { errors: OnyxCommon.Errors | null; }) | null @@ -304,7 +304,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((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; }, {}), }, @@ -337,6 +337,7 @@ function deletePolicyTaxes(policyID: string, taxesToDelete: string[]) { acc[taxID] = { pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.taxes.error.deleteFailureMessage'), + isDisabled: policyTaxRates?.[taxID].isDisabled, }; return acc; }, {}), From ec7fd1dfd67377314a255a80e4aad0800aa842fe Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Fri, 4 Oct 2024 09:14:56 +0530 Subject: [PATCH 2/3] minor fix. Signed-off-by: krishna2323 --- src/libs/actions/Policy/Category.ts | 2 +- src/libs/actions/Policy/Tag.ts | 2 +- src/libs/actions/TaxRate.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index 1289185105ef..ae09c5efcc45 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -878,7 +878,7 @@ function deleteWorkspaceCategories(policyID: string, categoryNamesToDelete: stri acc[categoryName] = { pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.categories.deleteFailureMessage'), - enabled: policyCategories?.[categoryName].enabled, + enabled: policyCategories?.[categoryName]?.enabled, }; return acc; }, {}), diff --git a/src/libs/actions/Policy/Tag.ts b/src/libs/actions/Policy/Tag.ts index 6ebd4c150d00..3344ebcc73ec 100644 --- a/src/libs/actions/Policy/Tag.ts +++ b/src/libs/actions/Policy/Tag.ts @@ -391,7 +391,7 @@ function deletePolicyTags(policyID: string, tagsToDelete: string[]) { acc[tagName] = { pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.tags.deleteFailureMessage'), - enabled: policyTag?.tags[tagName].enabled, + enabled: policyTag?.tags[tagName]?.enabled, }; return acc; }, {}), diff --git a/src/libs/actions/TaxRate.ts b/src/libs/actions/TaxRate.ts index beec01b14bcd..495faf9a4a0d 100644 --- a/src/libs/actions/TaxRate.ts +++ b/src/libs/actions/TaxRate.ts @@ -339,7 +339,7 @@ function deletePolicyTaxes(policyID: string, taxesToDelete: string[]) { acc[taxID] = { pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.taxes.error.deleteFailureMessage'), - isDisabled: policyTaxRates?.[taxID].isDisabled, + isDisabled: policyTaxRates?.[taxID]?.isDisabled, }; return acc; }, {}), From 0bc1adaca688aa6599a2b70327211094472242ba Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Sat, 5 Oct 2024 07:49:58 +0530 Subject: [PATCH 3/3] minor update. Signed-off-by: krishna2323 --- src/libs/actions/Policy/Category.ts | 2 +- src/libs/actions/Policy/Tag.ts | 2 +- src/libs/actions/TaxRate.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index ae09c5efcc45..a623989cfb6c 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -878,7 +878,7 @@ function deleteWorkspaceCategories(policyID: string, categoryNamesToDelete: stri acc[categoryName] = { pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.categories.deleteFailureMessage'), - enabled: policyCategories?.[categoryName]?.enabled, + enabled: !!policyCategories?.[categoryName]?.enabled, }; return acc; }, {}), diff --git a/src/libs/actions/Policy/Tag.ts b/src/libs/actions/Policy/Tag.ts index 3344ebcc73ec..7708921f57b5 100644 --- a/src/libs/actions/Policy/Tag.ts +++ b/src/libs/actions/Policy/Tag.ts @@ -391,7 +391,7 @@ function deletePolicyTags(policyID: string, tagsToDelete: string[]) { acc[tagName] = { pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.tags.deleteFailureMessage'), - enabled: policyTag?.tags[tagName]?.enabled, + enabled: !!policyTag?.tags[tagName]?.enabled, }; return acc; }, {}), diff --git a/src/libs/actions/TaxRate.ts b/src/libs/actions/TaxRate.ts index 495faf9a4a0d..52a8b8e143b8 100644 --- a/src/libs/actions/TaxRate.ts +++ b/src/libs/actions/TaxRate.ts @@ -339,7 +339,7 @@ function deletePolicyTaxes(policyID: string, taxesToDelete: string[]) { acc[taxID] = { pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.taxes.error.deleteFailureMessage'), - isDisabled: policyTaxRates?.[taxID]?.isDisabled, + isDisabled: !!policyTaxRates?.[taxID]?.isDisabled, }; return acc; }, {}),