From 73431914cd10b04cb137fb671d8df5f68a71f0fc Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Wed, 4 Sep 2024 12:19:01 +0200 Subject: [PATCH] refactor: address review comments --- src/libs/actions/Policy/Policy.ts | 16 +--------------- .../SpendCategorySelectorListItem.tsx} | 10 +++++----- .../WorkspaceCategoriesSettingsPage.tsx | 6 +++--- 3 files changed, 9 insertions(+), 23 deletions(-) rename src/{components/SelectionList/CategorySelectorListItem.tsx => pages/workspace/categories/SpendCategorySelectorListItem.tsx} (81%) diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 9599bcc40b06..49bfb1c20b09 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -3468,7 +3468,6 @@ function setWorkspaceDefaultSpendCategory(policyID: string, groupID: string, cat onyxMethod: Onyx.METHOD.MERGE, key: `policy_${policyID}`, value: { - isPendingUpgrade: true, mccGroup: { ...mccGroup, [groupID]: { @@ -3481,32 +3480,19 @@ function setWorkspaceDefaultSpendCategory(policyID: string, groupID: string, cat ] : []; - const successData: OnyxUpdate[] = mccGroup - ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `policy_${policyID}`, - value: { - isPendingUpgrade: false, - }, - }, - ] - : []; - const failureData: OnyxUpdate[] = mccGroup ? [ { onyxMethod: Onyx.METHOD.MERGE, key: `policy_${policyID}`, value: { - isPendingUpgrade: false, mccGroup, }, }, ] : []; - API.write(WRITE_COMMANDS.SET_WORKSPACE_DEFAULT_SPEND_CATEGORY, {policyID, groupID, category}, {optimisticData, successData, failureData}); + API.write(WRITE_COMMANDS.SET_WORKSPACE_DEFAULT_SPEND_CATEGORY, {policyID, groupID, category}, {optimisticData, successData: [], failureData}); } /** * Call the API to set the receipt required amount for the given policy diff --git a/src/components/SelectionList/CategorySelectorListItem.tsx b/src/pages/workspace/categories/SpendCategorySelectorListItem.tsx similarity index 81% rename from src/components/SelectionList/CategorySelectorListItem.tsx rename to src/pages/workspace/categories/SpendCategorySelectorListItem.tsx index f23b800fb322..77dede3cebbe 100644 --- a/src/components/SelectionList/CategorySelectorListItem.tsx +++ b/src/pages/workspace/categories/SpendCategorySelectorListItem.tsx @@ -1,11 +1,11 @@ import React, {useState} from 'react'; +import BaseListItem from '@components/SelectionList/BaseListItem'; +import type {BaseListItemProps, ListItem} from '@components/SelectionList/types'; import useThemeStyles from '@hooks/useThemeStyles'; import CategorySelector from '@pages/workspace/distanceRates/CategorySelector'; import * as Policy from '@userActions/Policy/Policy'; -import BaseListItem from './BaseListItem'; -import type {InviteMemberListItemProps, ListItem} from './types'; -function CategorySelectorListItem({item, onSelectRow, isFocused}: InviteMemberListItemProps) { +function SpendCategorySelectorListItem({item, onSelectRow, isFocused}: BaseListItemProps) { const styles = useThemeStyles(); const [isCategoryPickerVisible, setIsCategoryPickerVisible] = useState(false); const {policyID, groupID, categoryID} = item; @@ -52,6 +52,6 @@ function CategorySelectorListItem({item, onSelectRow, is ); } -CategorySelectorListItem.displayName = 'CategorySelectorListItem'; +SpendCategorySelectorListItem.displayName = 'SpendCategorySelectorListItem'; -export default CategorySelectorListItem; +export default SpendCategorySelectorListItem; diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index 3383e8e33735..64c875b60cdb 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -4,7 +4,7 @@ import {useOnyx} from 'react-native-onyx'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import SelectionList from '@components/SelectionList'; -import CategorySelectorListItem from '@components/SelectionList/CategorySelectorListItem'; +import SpendCategorySelectorListItem from '@components/SelectionList/SpendCategorySelectorListItem'; import type {ListItem} from '@components/SelectionList/types'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; @@ -92,13 +92,13 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet {!!currentPolicy && sections?.length > 0 && ( + {translate('workspace.categories.defaultSpendCategories')} {translate('workspace.categories.spendCategoriesDescription')} } sections={sections} - ListItem={CategorySelectorListItem} + ListItem={SpendCategorySelectorListItem} onSelectRow={() => {}} /> )}