From 43a94aa2823a0d31588070e4864770d88a94859c Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Thu, 14 Mar 2024 22:42:01 +0500 Subject: [PATCH 1/3] fix: allow selection list to be greyed for tags --- src/libs/actions/Policy.ts | 19 +++++++++++++++++++ .../workspace/tags/WorkspaceTagsPage.tsx | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 0d7a4f97a9ad..f2adeb4386f9 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -2887,6 +2887,24 @@ function createPolicyTag(policyID: string, tagName: string) { API.write(WRITE_COMMANDS.CREATE_POLICY_TAG, parameters, onyxData); } +function clearPolicyTagErrors(policyID: string, tagName: string) { + const tagListName = Object.keys(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {})[0]; + const tag = allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`]?.[tagListName].tags?.[tagName]; + if (!tag) { + return; + } + + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, { + [tagListName]: { + tags: { + [tagName]: { + errors: null, + }, + }, + }, + }); +} + function setWorkspaceRequiresCategory(policyID: string, requiresCategory: boolean) { const onyxData: OnyxData = { optimisticData: [ @@ -3651,6 +3669,7 @@ export { openPolicyDistanceRatesPage, openPolicyMoreFeaturesPage, createPolicyTag, + clearPolicyTagErrors, clearWorkspaceReimbursementErrors, deleteWorkspaceCategories, }; diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 4ea8ba669b9b..d696678c3b4c 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -73,6 +73,8 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { text: value.name, keyForList: value.name, isSelected: !!selectedTags[value.name], + pendingAction: value.pendingAction, + errors: value.errors ?? undefined, rightElement: ( @@ -189,6 +191,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { ListItem={TableListItem} customListHeader={getCustomListHeader()} listHeaderWrapperStyle={[styles.ph9, styles.pv3, styles.pb5]} + onDismissError={(item) => Policy.clearPolicyTagErrors(route.params.policyID, item.value)} /> )} From c047c0b6dbfdca53326a6561ab14a2cd15c42e6b Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Fri, 15 Mar 2024 04:42:12 +0500 Subject: [PATCH 2/3] fix: remove tags along with errors --- src/libs/actions/Policy.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index f2adeb4386f9..9648fb70179a 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -2897,9 +2897,12 @@ function clearPolicyTagErrors(policyID: string, tagName: string) { Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, { [tagListName]: { tags: { - [tagName]: { - errors: null, - }, + [tagName]: + tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD + ? null + : { + errors: null, + }, }, }, }); From 861fa37eaa8be454e0faabce2a7fc382470b92fc Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Fri, 15 Mar 2024 05:12:35 +0500 Subject: [PATCH 3/3] fix: remove tags along with errors --- src/libs/actions/Policy.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 9648fb70179a..1b9aca80c987 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -2870,7 +2870,6 @@ function createPolicyTag(policyID: string, tagName: string) { tags: { [tagName]: { errors: ErrorUtils.getMicroSecondOnyxError('workspace.tags.genericFailureMessage'), - pendingAction: null, }, }, }, @@ -2894,15 +2893,24 @@ function clearPolicyTagErrors(policyID: string, tagName: string) { return; } + if (tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, { + [tagListName]: { + tags: { + [tagName]: null, + }, + }, + }); + return; + } + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, { [tagListName]: { tags: { - [tagName]: - tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD - ? null - : { - errors: null, - }, + [tagName]: { + errors: null, + pendingAction: null, + }, }, }, });