From 299e1e6fb78fe5db6db2e719b483c5044062a67b Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 27 Mar 2024 15:18:00 +0700 Subject: [PATCH 01/11] fix categorize all expense switch is not disabled --- src/libs/actions/Policy.ts | 48 +++++++++++++------ .../WorkspaceCategoriesSettingsPage.tsx | 2 +- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 45fc139b6742..4e1706433c08 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -60,6 +60,7 @@ import getIsNarrowLayout from '@libs/getIsNarrowLayout'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as NumberUtils from '@libs/NumberUtils'; +import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; import * as PhoneNumber from '@libs/PhoneNumber'; import * as PolicyUtils from '@libs/PolicyUtils'; @@ -2854,27 +2855,28 @@ function createWorkspaceFromIOUPayment(iouReport: Report | EmptyObject): string function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Record) { const policyCategories = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`] ?? {}; + const optimisticPolicyCategoriesData = { + ...Object.keys(categoriesToUpdate).reduce((acc, key) => { + acc[key] = { + ...policyCategories[key], + ...categoriesToUpdate[key], + errors: null, + pendingFields: { + enabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }; + return acc; + }, {}), + }; + const shouldTurnOffCategoriesEnabled = !OptionsListUtils.hasEnabledOptions({...policyCategories, ...optimisticPolicyCategoriesData}); const onyxData: OnyxData = { optimisticData: [ { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`, - value: { - ...Object.keys(categoriesToUpdate).reduce((acc, key) => { - acc[key] = { - ...policyCategories[key], - ...categoriesToUpdate[key], - errors: null, - pendingFields: { - enabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }, - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }; - - return acc; - }, {}), - }, + value: optimisticPolicyCategoriesData, }, ], successData: [ @@ -2920,6 +2922,22 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor }, ], }; + if (shouldTurnOffCategoriesEnabled) { + onyxData.optimisticData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + areCategoriesEnabled: false, + }, + }); + onyxData.failureData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + areCategoriesEnabled: false, + }, + }); + } const parameters = { policyID, diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index 0ec937b19ba2..3d60ad5cb9e5 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -50,7 +50,7 @@ function WorkspaceCategoriesSettingsPage({route}: WorkspaceCategoriesSettingsPag {translate('workspace.categories.requiresCategory')} Date: Thu, 28 Mar 2024 11:51:43 +0700 Subject: [PATCH 02/11] fix revert areCategories if failed --- src/libs/actions/Policy.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 4e1706433c08..f885d8b1cd5b 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -2855,6 +2855,7 @@ function createWorkspaceFromIOUPayment(iouReport: Report | EmptyObject): string function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Record) { const policyCategories = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`] ?? {}; + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; const optimisticPolicyCategoriesData = { ...Object.keys(categoriesToUpdate).reduce((acc, key) => { acc[key] = { @@ -2934,7 +2935,7 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - areCategoriesEnabled: false, + areCategoriesEnabled: policy?.areCategoriesEnabled, }, }); } From 547f69b6a144cebd51d61898e5967dc598546924 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 28 Mar 2024 11:57:49 +0700 Subject: [PATCH 03/11] fix navigate user to more feature page --- src/libs/actions/Policy.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index f885d8b1cd5b..5d39c187b51c 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -2946,6 +2946,9 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor }; API.write(WRITE_COMMANDS.SET_WORKSPACE_CATEGORIES_ENABLED, parameters, onyxData); + if (shouldTurnOffCategoriesEnabled) { + Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID)); + } } function createPolicyCategory(policyID: string, categoryName: string) { From 3874d9cf41f7ddbc4cb7b4d3e7a528a078fc0c85 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 28 Mar 2024 12:08:23 +0700 Subject: [PATCH 04/11] fix add pendingFields --- src/libs/actions/Policy.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 5d39c187b51c..8fc616bdcdf2 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -2929,6 +2929,18 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { areCategoriesEnabled: false, + pendingFields: { + areCategoriesEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + }, + }); + onyxData.successData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + pendingFields: { + areCategoriesEnabled: null, + }, }, }); onyxData.failureData?.push({ @@ -2936,6 +2948,9 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { areCategoriesEnabled: policy?.areCategoriesEnabled, + pendingFields: { + areCategoriesEnabled: null, + }, }, }); } From 830640c96d04b45068b55f9307c289519400af96 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 28 Mar 2024 15:40:33 +0700 Subject: [PATCH 05/11] fix goback before navigate to more feature screen --- src/libs/actions/Policy.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 8fc616bdcdf2..16379dfb1abe 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -2962,7 +2962,8 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor API.write(WRITE_COMMANDS.SET_WORKSPACE_CATEGORIES_ENABLED, parameters, onyxData); if (shouldTurnOffCategoriesEnabled) { - Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID)); + Navigation.goBack(); + Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID), CONST.NAVIGATION.TYPE.UP); } } From 85cd494af0d23f404b50197f7e8605f29086c0bc Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 29 Mar 2024 09:33:41 +0700 Subject: [PATCH 06/11] fix only turn off require category --- src/libs/actions/Policy.ts | 18 +++++++----------- .../WorkspaceCategoriesSettingsPage.tsx | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 16379dfb1abe..4f6c79920fba 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -2871,7 +2871,7 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor return acc; }, {}), }; - const shouldTurnOffCategoriesEnabled = !OptionsListUtils.hasEnabledOptions({...policyCategories, ...optimisticPolicyCategoriesData}); + const shouldDisableRequiresCategory = !OptionsListUtils.hasEnabledOptions({...policyCategories, ...optimisticPolicyCategoriesData}); const onyxData: OnyxData = { optimisticData: [ { @@ -2923,14 +2923,14 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor }, ], }; - if (shouldTurnOffCategoriesEnabled) { + if (shouldDisableRequiresCategory) { onyxData.optimisticData?.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - areCategoriesEnabled: false, + requiresCategory: false, pendingFields: { - areCategoriesEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + requiresCategory: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, }, }); @@ -2939,7 +2939,7 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { pendingFields: { - areCategoriesEnabled: null, + requiresCategory: null, }, }, }); @@ -2947,9 +2947,9 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - areCategoriesEnabled: policy?.areCategoriesEnabled, + requiresCategory: policy?.areCategoriesEnabled, pendingFields: { - areCategoriesEnabled: null, + requiresCategory: null, }, }, }); @@ -2961,10 +2961,6 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor }; API.write(WRITE_COMMANDS.SET_WORKSPACE_CATEGORIES_ENABLED, parameters, onyxData); - if (shouldTurnOffCategoriesEnabled) { - Navigation.goBack(); - Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID), CONST.NAVIGATION.TYPE.UP); - } } function createPolicyCategory(policyID: string, categoryName: string) { diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index 3d60ad5cb9e5..0ec937b19ba2 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -50,7 +50,7 @@ function WorkspaceCategoriesSettingsPage({route}: WorkspaceCategoriesSettingsPag {translate('workspace.categories.requiresCategory')} Date: Fri, 29 Mar 2024 09:35:14 +0700 Subject: [PATCH 07/11] fix using policy?.requiresCategory --- src/libs/actions/Policy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 4f6c79920fba..c66f688644b8 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -2947,7 +2947,7 @@ function setWorkspaceCategoryEnabled(policyID: string, categoriesToUpdate: Recor onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { - requiresCategory: policy?.areCategoriesEnabled, + requiresCategory: policy?.requiresCategory, pendingFields: { requiresCategory: null, }, From eceebef71fb1725d23bf3f25c014e1c6ee270f7b Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 1 Apr 2024 15:32:11 +0700 Subject: [PATCH 08/11] fix disable switch button once there is no enabled category --- .../WorkspaceCategoriesSettingsPage.tsx | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index 0ec937b19ba2..57c69be49809 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -1,6 +1,8 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React from 'react'; import {View} from 'react-native'; +import type {OnyxEntry} from 'react-native-onyx'; +import {withOnyx} from 'react-native-onyx'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -9,16 +11,24 @@ import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {setWorkspaceRequiresCategory} from '@libs/actions/Policy'; +import * as OptionsListUtils from '@libs/OptionsListUtils'; import type {SettingsNavigatorParamList} from '@navigation/types'; import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper'; import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper'; import PaidPolicyAccessOrNotFoundWrapper from '@pages/workspace/PaidPolicyAccessOrNotFoundWrapper'; import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; +import type * as OnyxTypes from '@src/types/onyx'; -type WorkspaceCategoriesSettingsPageProps = StackScreenProps; +type WorkspaceCategoriesSettingsPageOnyxProps = { + /** Collection of categories attached to a policy */ + policyCategories: OnyxEntry; +}; -function WorkspaceCategoriesSettingsPage({route}: WorkspaceCategoriesSettingsPageProps) { +type WorkspaceCategoriesSettingsPageProps = WorkspaceCategoriesSettingsPageOnyxProps & StackScreenProps; + +function WorkspaceCategoriesSettingsPage({route, policyCategories}: WorkspaceCategoriesSettingsPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -26,6 +36,7 @@ function WorkspaceCategoriesSettingsPage({route}: WorkspaceCategoriesSettingsPag setWorkspaceRequiresCategory(route.params.policyID, value); }; + const policyCategoriesCount = OptionsListUtils.getEnabledCategoriesCount(policyCategories ?? {}); return ( @@ -53,7 +64,7 @@ function WorkspaceCategoriesSettingsPage({route}: WorkspaceCategoriesSettingsPag isOn={policy?.requiresCategory ?? false} accessibilityLabel={translate('workspace.categories.requiresCategory')} onToggle={updateWorkspaceRequiresCategory} - disabled={!policy?.areCategoriesEnabled} + disabled={!policy?.areCategoriesEnabled || policyCategoriesCount === 0} /> @@ -69,4 +80,8 @@ function WorkspaceCategoriesSettingsPage({route}: WorkspaceCategoriesSettingsPag WorkspaceCategoriesSettingsPage.displayName = 'WorkspaceCategoriesSettingsPage'; -export default WorkspaceCategoriesSettingsPage; +export default withOnyx({ + policyCategories: { + key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params.policyID}`, + }, +})(WorkspaceCategoriesSettingsPage); From a19beb1867790895ac4cced1b19c14d30d934d39 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 2 Apr 2024 23:49:08 +0700 Subject: [PATCH 09/11] fix use hasEnabledOptions insteads of getEnabledCategoriesCount --- .../workspace/categories/WorkspaceCategoriesSettingsPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index 57c69be49809..260b6b94d4dc 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -36,7 +36,7 @@ function WorkspaceCategoriesSettingsPage({route, policyCategories}: WorkspaceCat setWorkspaceRequiresCategory(route.params.policyID, value); }; - const policyCategoriesCount = OptionsListUtils.getEnabledCategoriesCount(policyCategories ?? {}); + const hasEnabledOptions = OptionsListUtils.hasEnabledOptions(policyCategories ?? {}); return ( @@ -64,7 +64,7 @@ function WorkspaceCategoriesSettingsPage({route, policyCategories}: WorkspaceCat isOn={policy?.requiresCategory ?? false} accessibilityLabel={translate('workspace.categories.requiresCategory')} onToggle={updateWorkspaceRequiresCategory} - disabled={!policy?.areCategoriesEnabled || policyCategoriesCount === 0} + disabled={!policy?.areCategoriesEnabled || !hasEnabledOptions} /> From 6b050576a6f8d93eb32a45943dfc8370810eb62d Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 3 Apr 2024 14:23:06 +0700 Subject: [PATCH 10/11] fix disable require category switch once remove any category --- src/libs/OptionsListUtils.ts | 4 +- src/libs/actions/Policy.ts | 45 +++++++++++++++++-- .../WorkspaceCategoriesSettingsPage.tsx | 2 +- src/types/onyx/PolicyTag.ts | 6 +-- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index ca44931e7e8e..56e2492a99b1 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -826,8 +826,8 @@ function getSearchValueForPhoneOrEmail(searchTerm: string) { /** * Verifies that there is at least one enabled option */ -function hasEnabledOptions(options: PolicyCategories | PolicyTag[]): boolean { - return Object.values(options).some((option) => option.enabled); +function hasEnabledOptions(options: PolicyCategories | PolicyTag[], shouldContainPendingDeleteOption = true): boolean { + return Object.values(options).some((option) => option.enabled && (shouldContainPendingDeleteOption || option.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)); } /** diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 778c9a8ff888..2464d7aee722 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -3471,15 +3471,21 @@ function clearCategoryErrors(policyID: string, categoryName: string) { } function deleteWorkspaceCategories(policyID: string, categoryNamesToDelete: string[]) { + 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}; + return acc; + }, {}); + const shouldDisableRequiresCategory = !OptionsListUtils.hasEnabledOptions( + Object.values(policyCategories).filter((category) => !categoryNamesToDelete.includes(category.name) && category.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE), + ); const onyxData: OnyxData = { optimisticData: [ { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`, - value: categoryNamesToDelete.reduce>>((acc, categoryName) => { - acc[categoryName] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}; - return acc; - }, {}), + value: optimisticPolicyCategoriesData, }, ], successData: [ @@ -3506,6 +3512,37 @@ function deleteWorkspaceCategories(policyID: string, categoryNamesToDelete: stri }, ], }; + if (shouldDisableRequiresCategory) { + onyxData.optimisticData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + requiresCategory: false, + pendingFields: { + requiresCategory: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + }, + }); + onyxData.successData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + pendingFields: { + requiresCategory: null, + }, + }, + }); + onyxData.failureData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + requiresCategory: policy?.requiresCategory, + pendingFields: { + requiresCategory: null, + }, + }, + }); + } const parameters = { policyID, diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index 260b6b94d4dc..bf17abd463b1 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -36,7 +36,7 @@ function WorkspaceCategoriesSettingsPage({route, policyCategories}: WorkspaceCat setWorkspaceRequiresCategory(route.params.policyID, value); }; - const hasEnabledOptions = OptionsListUtils.hasEnabledOptions(policyCategories ?? {}); + const hasEnabledOptions = OptionsListUtils.hasEnabledOptions(policyCategories ?? {}, false); return ( diff --git a/src/types/onyx/PolicyTag.ts b/src/types/onyx/PolicyTag.ts index f469ac7fff70..37e979fb58f6 100644 --- a/src/types/onyx/PolicyTag.ts +++ b/src/types/onyx/PolicyTag.ts @@ -1,6 +1,6 @@ import type * as OnyxCommon from './OnyxCommon'; -type PolicyTag = { +type PolicyTag = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Name of a Tag */ name: string; @@ -13,9 +13,9 @@ type PolicyTag = { /** A list of errors keyed by microtime */ errors?: OnyxCommon.Errors | null; -}; +}>; -type PolicyTags = Record>; +type PolicyTags = Record; type PolicyTagList = Record< T, From a45c9a9448993253d93becb01e5596a82c77794e Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 3 Apr 2024 22:53:07 +0700 Subject: [PATCH 11/11] fix remove shouldContainPendingDeleteOption --- src/libs/OptionsListUtils.ts | 4 ++-- .../workspace/categories/WorkspaceCategoriesSettingsPage.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 56e2492a99b1..2f86819d91c6 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -826,8 +826,8 @@ function getSearchValueForPhoneOrEmail(searchTerm: string) { /** * Verifies that there is at least one enabled option */ -function hasEnabledOptions(options: PolicyCategories | PolicyTag[], shouldContainPendingDeleteOption = true): boolean { - return Object.values(options).some((option) => option.enabled && (shouldContainPendingDeleteOption || option.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)); +function hasEnabledOptions(options: PolicyCategories | PolicyTag[]): boolean { + return Object.values(options).some((option) => option.enabled && option.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); } /** diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index bf17abd463b1..260b6b94d4dc 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -36,7 +36,7 @@ function WorkspaceCategoriesSettingsPage({route, policyCategories}: WorkspaceCat setWorkspaceRequiresCategory(route.params.policyID, value); }; - const hasEnabledOptions = OptionsListUtils.hasEnabledOptions(policyCategories ?? {}, false); + const hasEnabledOptions = OptionsListUtils.hasEnabledOptions(policyCategories ?? {}); return (