diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 0d7a4f97a9ad..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, }, }, }, @@ -2887,6 +2886,36 @@ 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; + } + + 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]: { + errors: null, + pendingAction: null, + }, + }, + }, + }); +} + function setWorkspaceRequiresCategory(policyID: string, requiresCategory: boolean) { const onyxData: OnyxData = { optimisticData: [ @@ -3651,6 +3680,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)} /> )}