From 156a16201effc85a211beb010ecd3124a8b5cd93 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 19:06:03 +0300 Subject: [PATCH 01/40] add route for category glcode --- src/ROUTES.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 61034382fefd..f8fed727661c 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -687,6 +687,10 @@ const ROUTES = { route: 'settings/workspaces/:policyID/categories/:categoryName/edit', getRoute: (policyID: string, categoryName: string) => `settings/workspaces/${policyID}/categories/${encodeURIComponent(categoryName)}/edit` as const, }, + WORKSPACE_CATEGORY_GLCODE: { + route: 'settings/workspaces/:policyID/categories/:categoryName/glcode', + getRoute: (policyID: string, categoryName: string) => `settings/workspaces/${policyID}/categories/${encodeURIComponent(categoryName)}/glcode` as const, + }, WORKSPACE_MORE_FEATURES: { route: 'settings/workspaces/:policyID/more-features', getRoute: (policyID: string) => `settings/workspaces/${policyID}/more-features` as const, From 0fdc592a832f9f3b167e827e4209d6f77c4ad39e Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 19:06:19 +0300 Subject: [PATCH 02/40] add screen for category glcode --- src/SCREENS.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SCREENS.ts b/src/SCREENS.ts index 6f32f980d6c2..9f97caad480b 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -309,6 +309,7 @@ const SCREENS = { NAME: 'Workspace_Profile_Name', CATEGORY_CREATE: 'Category_Create', CATEGORY_EDIT: 'Category_Edit', + CATEGORY_GLCODE: 'Category_GLCode', CATEGORY_SETTINGS: 'Category_Settings', CATEGORIES_SETTINGS: 'Categories_Settings', MORE_FEATURES: 'Workspace_More_Features', From 1a93283037070f28ed98241ddcd97d4ea04aa850 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 19:06:33 +0300 Subject: [PATCH 03/40] add lang for glcode --- src/languages/en.ts | 2 ++ src/languages/es.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/languages/en.ts b/src/languages/en.ts index 8ed0ef8207f1..930d82afddef 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -2174,6 +2174,8 @@ export default { existingCategoryError: 'A category with this name already exists.', invalidCategoryName: 'Invalid category name.', importedFromAccountingSoftware: 'The categories below are imported from your', + glCode: 'GL code', + payrollCode: 'Payroll code', }, moreFeatures: { spendSection: { diff --git a/src/languages/es.ts b/src/languages/es.ts index 2316a5d09c9f..5d2bdc1b4ccb 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -2212,6 +2212,8 @@ export default { existingCategoryError: 'Ya existe una categoría con este nombre.', invalidCategoryName: 'Lo nombre de la categoría es invalido.', importedFromAccountingSoftware: 'Categorías importadas desde', + glCode: 'GL code', + payrollCode: 'Payroll code', }, moreFeatures: { spendSection: { From 2e34de53e47342b85a4d86d0cad86acdfa98cc98 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 19:06:56 +0300 Subject: [PATCH 04/40] link to glcode screen and add type --- .../linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts | 8 +++++++- src/libs/Navigation/linkingConfig/config.ts | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts index 2aaceb96f52a..13368903cfa5 100755 --- a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts +++ b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts @@ -74,7 +74,13 @@ const FULL_SCREEN_TO_RHP_MAPPING: Partial> = { SCREENS.WORKSPACE.TAG_EDIT, SCREENS.WORKSPACE.TAG_LIST_VIEW, ], - [SCREENS.WORKSPACE.CATEGORIES]: [SCREENS.WORKSPACE.CATEGORY_CREATE, SCREENS.WORKSPACE.CATEGORY_SETTINGS, SCREENS.WORKSPACE.CATEGORIES_SETTINGS, SCREENS.WORKSPACE.CATEGORY_EDIT], + [SCREENS.WORKSPACE.CATEGORIES]: [ + SCREENS.WORKSPACE.CATEGORY_CREATE, + SCREENS.WORKSPACE.CATEGORY_SETTINGS, + SCREENS.WORKSPACE.CATEGORIES_SETTINGS, + SCREENS.WORKSPACE.CATEGORY_EDIT, + SCREENS.WORKSPACE.CATEGORY_GLCODE, + ], [SCREENS.WORKSPACE.DISTANCE_RATES]: [ SCREENS.WORKSPACE.CREATE_DISTANCE_RATE, SCREENS.WORKSPACE.DISTANCE_RATES_SETTINGS, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index b19fbc4c38e0..1f3ccf37a668 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -404,6 +404,9 @@ const config: LinkingOptions['config'] = { categoryName: (categoryName: string) => decodeURIComponent(categoryName), }, }, + [SCREENS.WORKSPACE.CATEGORY_GLCODE]: { + path: ROUTES.WORKSPACE_CATEGORY_GLCODE.route, + }, [SCREENS.WORKSPACE.CREATE_DISTANCE_RATE]: { path: ROUTES.WORKSPACE_CREATE_DISTANCE_RATE.route, }, From e8f55ebd43b2150fcd0e83465b3d83f98b614295 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 19:07:14 +0300 Subject: [PATCH 05/40] link to glcode screen and add type --- src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index 67890a132d2d..36333e9aa50d 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -243,6 +243,7 @@ const SettingsModalStackNavigator = createModalStackNavigator require('../../../../pages/workspace/members/WorkspaceOwnerChangeErrorPage').default as React.ComponentType, [SCREENS.WORKSPACE.CATEGORY_CREATE]: () => require('../../../../pages/workspace/categories/CreateCategoryPage').default as React.ComponentType, [SCREENS.WORKSPACE.CATEGORY_EDIT]: () => require('../../../../pages/workspace/categories/EditCategoryPage').default as React.ComponentType, + [SCREENS.WORKSPACE.CATEGORY_GLCODE]: () => require('../../../../pages/workspace/categories/CategoryGLCodePage').default as React.ComponentType, [SCREENS.WORKSPACE.CREATE_DISTANCE_RATE]: () => require('../../../../pages/workspace/distanceRates/CreateDistanceRatePage').default as React.ComponentType, [SCREENS.WORKSPACE.DISTANCE_RATES_SETTINGS]: () => require('../../../../pages/workspace/distanceRates/PolicyDistanceRatesSettingsPage').default as React.ComponentType, [SCREENS.WORKSPACE.DISTANCE_RATE_DETAILS]: () => require('../../../../pages/workspace/distanceRates/PolicyDistanceRateDetailsPage').default as React.ComponentType, From 8e9262e164fda194de257908210d8273bf144da7 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 19:07:26 +0300 Subject: [PATCH 06/40] add nav type --- src/types/onyx/PolicyCategory.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/types/onyx/PolicyCategory.ts b/src/types/onyx/PolicyCategory.ts index d4162bfdcddf..10f05f41936b 100644 --- a/src/types/onyx/PolicyCategory.ts +++ b/src/types/onyx/PolicyCategory.ts @@ -14,8 +14,7 @@ type PolicyCategory = OnyxCommon.OnyxValueWithOfflineFeedback<{ areCommentsRequired?: boolean; /** "General Ledger code" that corresponds to this category in an accounting system. Similar to an ID. */ - // eslint-disable-next-line @typescript-eslint/naming-convention - 'GL Code'?: string; + glCode?: string; /** An ID for this category from an external accounting system */ externalID?: string; From 476161e32192a16f331534971f6b2539d0aaaa23 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 19:07:36 +0300 Subject: [PATCH 07/40] add nav type --- src/libs/Navigation/types.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index d4ee4aba1f51..53672ae203ff 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -200,6 +200,10 @@ type SettingsNavigatorParamList = { categoryName: string; backTo?: Routes; }; + [SCREENS.WORKSPACE.CATEGORY_GLCODE]: { + policyID: string; + categoryName: string; + }; [SCREENS.WORKSPACE.CATEGORY_SETTINGS]: { policyID: string; categoryName: string; From aa4bfb6f4fda2b4272945516e346e3815b258ee5 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 19:07:56 +0300 Subject: [PATCH 08/40] add menu item for gl code --- src/pages/workspace/categories/CategorySettingsPage.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pages/workspace/categories/CategorySettingsPage.tsx b/src/pages/workspace/categories/CategorySettingsPage.tsx index 22f2b4f02fbf..69641649bbc8 100644 --- a/src/pages/workspace/categories/CategorySettingsPage.tsx +++ b/src/pages/workspace/categories/CategorySettingsPage.tsx @@ -138,6 +138,14 @@ function CategorySettingsPage({route, policyCategories, navigation}: CategorySet shouldShowRightIcon /> + + Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_GLCODE.getRoute(route.params.policyID, policyCategory.name))} + shouldShowRightIcon + /> + From 57909397702e6541f00b97edd768a33f39d8b7cc Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 19:08:07 +0300 Subject: [PATCH 09/40] add page for glcode --- .../categories/CategoryGLCodePage.tsx | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/pages/workspace/categories/CategoryGLCodePage.tsx diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx new file mode 100644 index 000000000000..736aa5d2aa56 --- /dev/null +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -0,0 +1,103 @@ +import type {StackScreenProps} from '@react-navigation/stack'; +import React, {useCallback} from 'react'; +import {withOnyx} from 'react-native-onyx'; +import type {OnyxEntry} from 'react-native-onyx'; +import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; +import HeaderWithBackButton from '@components/HeaderWithBackButton'; +import ScreenWrapper from '@components/ScreenWrapper'; +import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import Navigation from '@libs/Navigation/Navigation'; +import type {SettingsNavigatorParamList} from '@navigation/types'; +import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; +import * as Category from '@userActions/Policy/Category'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; +import type SCREENS from '@src/SCREENS'; +import type {PolicyCategories} from '@src/types/onyx'; +import CategoryForm from './CategoryForm'; + +type WorkspaceEditCategoryGLCodePageOnyxProps = { + /** All policy categories */ + policyCategories: OnyxEntry; +}; + +type EditCategoryPageProps = WorkspaceEditCategoryGLCodePageOnyxProps & StackScreenProps; + +function CategoryGLCodePage({route, policyCategories}: EditCategoryPageProps) { + const styles = useThemeStyles(); + const {translate} = useLocalize(); + const currentCategoryName = route.params.categoryName; + const backTo = route.params?.backTo; + + const validate = useCallback( + (values: FormOnyxValues) => { + const errors: FormInputErrors = {}; + const newCategoryName = values.categoryName.trim(); + + if (!newCategoryName) { + errors.categoryName = 'workspace.categories.categoryRequiredError'; + } else if (policyCategories?.[newCategoryName] && currentCategoryName !== newCategoryName) { + errors.categoryName = 'workspace.categories.existingCategoryError'; + } + + return errors; + }, + [policyCategories, currentCategoryName], + ); + + const editCategory = useCallback( + (values: FormOnyxValues) => { + const newCategoryName = values.categoryName.trim(); + // Do not call the API if the edited category name is the same as the current category name + if (currentCategoryName !== newCategoryName) { + Category.renamePolicyCategory(route.params.policyID, {oldName: currentCategoryName, newName: values.categoryName}); + } + if (backTo) { + Navigation.goBack(ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo)); + return; + } + Navigation.goBack(); + }, + [backTo, currentCategoryName, route.params.categoryName, route.params.policyID], + ); + + return ( + + + + backTo + ? Navigation.goBack(ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo)) + : Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName)) + } + /> + + + + ); +} + +CategoryGLCodePage.displayName = 'CategoryGLCodePage'; + +export default withOnyx({ + policyCategories: { + key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route?.params?.policyID}`, + }, +})(CategoryGLCodePage); From da4b4d005e72bc89cc78d6deb43c4fe732e74df4 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 23:36:15 +0300 Subject: [PATCH 10/40] add edit gl code form --- .../categories/CategoryGLCodePage.tsx | 78 +++++++++---------- 1 file changed, 35 insertions(+), 43 deletions(-) diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 736aa5d2aa56..231bfa356722 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -2,9 +2,13 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback} from 'react'; import {withOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; +import FormProvider from '@components/Form/FormProvider'; +import InputWrapper from '@components/Form/InputWrapper'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; +import TextInput from '@components/TextInput'; +import useAutoFocusInput from '@hooks/useAutoFocusInput'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; @@ -15,52 +19,33 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {PolicyCategories} from '@src/types/onyx'; +import INPUT_IDS from '@src/types/form/WorkspaceCategoryForm'; +import type {PolicyCategories, PolicyCategory} from '@src/types/onyx'; import CategoryForm from './CategoryForm'; type WorkspaceEditCategoryGLCodePageOnyxProps = { - /** All policy categories */ + /** Policy category */ policyCategories: OnyxEntry; }; -type EditCategoryPageProps = WorkspaceEditCategoryGLCodePageOnyxProps & StackScreenProps; +type EditCategoryPageProps = WorkspaceEditCategoryGLCodePageOnyxProps & StackScreenProps; function CategoryGLCodePage({route, policyCategories}: EditCategoryPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); - const currentCategoryName = route.params.categoryName; - const backTo = route.params?.backTo; + const categoryName = route.params.categoryName; + const glCode = policyCategories?.[categoryName]?.glCode; + const {inputCallbackRef} = useAutoFocusInput(); - const validate = useCallback( + const editGLCode = useCallback( (values: FormOnyxValues) => { - const errors: FormInputErrors = {}; - const newCategoryName = values.categoryName.trim(); - - if (!newCategoryName) { - errors.categoryName = 'workspace.categories.categoryRequiredError'; - } else if (policyCategories?.[newCategoryName] && currentCategoryName !== newCategoryName) { - errors.categoryName = 'workspace.categories.existingCategoryError'; - } - - return errors; - }, - [policyCategories, currentCategoryName], - ); - - const editCategory = useCallback( - (values: FormOnyxValues) => { - const newCategoryName = values.categoryName.trim(); - // Do not call the API if the edited category name is the same as the current category name - if (currentCategoryName !== newCategoryName) { - Category.renamePolicyCategory(route.params.policyID, {oldName: currentCategoryName, newName: values.categoryName}); - } - if (backTo) { - Navigation.goBack(ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo)); - return; + const newGLCode = values.glCode.trim(); + if (newGLCode !== glCode) { + Category.setPolicyCategoryGLCode(route.params.policyID, categoryName, newGLCode); } Navigation.goBack(); }, - [backTo, currentCategoryName, route.params.categoryName, route.params.policyID], + [categoryName, glCode, route.params.policyID], ); return ( @@ -76,19 +61,26 @@ function CategoryGLCodePage({route, policyCategories}: EditCategoryPageProps) { shouldEnableMaxHeight > - backTo - ? Navigation.goBack(ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo)) - : Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName)) - } - /> - Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName))} /> + + + ); From 7e455e1a0c775898e83ce975b8ec18a2ba388250 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 23:36:56 +0300 Subject: [PATCH 11/40] decode categeory name from uri --- src/libs/Navigation/linkingConfig/config.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 1f3ccf37a668..3e2ec2820f01 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -406,6 +406,9 @@ const config: LinkingOptions['config'] = { }, [SCREENS.WORKSPACE.CATEGORY_GLCODE]: { path: ROUTES.WORKSPACE_CATEGORY_GLCODE.route, + parse: { + categoryName: (categoryName: string) => decodeURIComponent(categoryName), + }, }, [SCREENS.WORKSPACE.CREATE_DISTANCE_RATE]: { path: ROUTES.WORKSPACE_CREATE_DISTANCE_RATE.route, From 09f10dcc5d22908dd415ad07bc43896546053600 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 23:38:25 +0300 Subject: [PATCH 12/40] fix lint --- src/pages/workspace/categories/CategoryGLCodePage.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 231bfa356722..3e93c8f0ba17 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -20,8 +20,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import INPUT_IDS from '@src/types/form/WorkspaceCategoryForm'; -import type {PolicyCategories, PolicyCategory} from '@src/types/onyx'; -import CategoryForm from './CategoryForm'; +import type {PolicyCategories} from '@src/types/onyx'; type WorkspaceEditCategoryGLCodePageOnyxProps = { /** Policy category */ From e864c7e0aa6a75f742f098330988b9dd0d29e1c4 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 23:38:43 +0300 Subject: [PATCH 13/40] add glcode type --- src/types/form/WorkspaceCategoryForm.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/types/form/WorkspaceCategoryForm.ts b/src/types/form/WorkspaceCategoryForm.ts index 4f5f9282373c..56c4bd709fcc 100644 --- a/src/types/form/WorkspaceCategoryForm.ts +++ b/src/types/form/WorkspaceCategoryForm.ts @@ -3,6 +3,7 @@ import type Form from './Form'; const INPUT_IDS = { CATEGORY_NAME: 'categoryName', + GL_CODE: 'glCode', } as const; type InputID = ValueOf; @@ -11,6 +12,7 @@ type WorkspaceCategoryForm = Form< InputID, { [INPUT_IDS.CATEGORY_NAME]: string; + [INPUT_IDS.GL_CODE]: string; } >; From 6d8788fc64d8a5dc89180f953350d0c468a53158 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 23:52:49 +0300 Subject: [PATCH 14/40] add err message --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/languages/en.ts b/src/languages/en.ts index 930d82afddef..732c99bc66ff 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -2175,6 +2175,7 @@ export default { invalidCategoryName: 'Invalid category name.', importedFromAccountingSoftware: 'The categories below are imported from your', glCode: 'GL code', + updateGLCodeFailureMessage: 'An error occurred while updating the GL code, please try again.', payrollCode: 'Payroll code', }, moreFeatures: { diff --git a/src/languages/es.ts b/src/languages/es.ts index 5d2bdc1b4ccb..d2dc637a6974 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -2213,6 +2213,7 @@ export default { invalidCategoryName: 'Lo nombre de la categoría es invalido.', importedFromAccountingSoftware: 'Categorías importadas desde', glCode: 'GL code', + updateGLCodeFailureMessage: 'An error occurred while updating the GL code, please try again.', payrollCode: 'Payroll code', }, moreFeatures: { From 17f33a8e60135c5e37859cdafdc9fe0618bb313d Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 23:53:15 +0300 Subject: [PATCH 15/40] add type glcode command --- src/libs/API/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 6ca80d525682..322ecf227b42 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -132,6 +132,7 @@ const WRITE_COMMANDS = { CREATE_POLICY_TAG: 'CreatePolicyTag', RENAME_POLICY_TAG: 'RenamePolicyTag', SET_WORKSPACE_REQUIRES_CATEGORY: 'SetWorkspaceRequiresCategory', + UPDATE_POLICY_CATEGORY_GL_CODE: 'UpdatePolicyCategoryGLCode', DELETE_WORKSPACE_CATEGORIES: 'DeleteWorkspaceCategories', SET_POLICY_REQUIRES_TAG: 'SetPolicyRequiresTag', RENAME_POLICY_TAG_LIST: 'RenamePolicyTaglist', From ee455af96c96801a7cd95bdbff8361c94da6fbd2 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 5 Jun 2024 23:53:29 +0300 Subject: [PATCH 16/40] add api command for glcode category --- src/libs/actions/Policy/Category.ts | 61 +++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index 294712666bdf..4a7c804ce61c 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -334,6 +334,66 @@ function renamePolicyCategory(policyID: string, policyCategory: {oldName: string API.write(WRITE_COMMANDS.RENAME_WORKSPACE_CATEGORY, parameters, onyxData); } +function setPolicyCategoryGLCode(policyID: string, categoryName: string, glCode: string) { + const policyCategoryToUpdate = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`]?.[categoryName] ?? {}; + + const onyxData: OnyxData = { + optimisticData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`, + value: { + [categoryName]: { + ...policyCategoryToUpdate, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + pendingFields: { + name: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + glCode, + }, + }, + }, + ], + successData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`, + value: { + [categoryName]: { + ...policyCategoryToUpdate, + pendingAction: null, + pendingFields: { + name: null, + }, + glCode, + }, + }, + }, + ], + failureData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`, + value: { + [categoryName]: { + ...policyCategoryToUpdate, + errors: ErrorUtils.getMicroSecondOnyxError('workspace.categories.updateGLCodeFailureMessage'), + pendingAction: null, + }, + }, + }, + ], + }; + + const parameters = { + policyID, + categoryName, + glCode, + }; + + API.write(WRITE_COMMANDS.UPDATE_POLICY_CATEGORY_GL_CODE, parameters, onyxData); +} + function setWorkspaceRequiresCategory(policyID: string, requiresCategory: boolean) { const onyxData: OnyxData = { optimisticData: [ @@ -593,6 +653,7 @@ export { setWorkspaceRequiresCategory, createPolicyCategory, renamePolicyCategory, + setPolicyCategoryGLCode, clearCategoryErrors, enablePolicyCategories, setPolicyDistanceRatesDefaultCategory, From f92e72ea214d13f81ec8267624f9a87ded65a737 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 6 Jun 2024 00:05:12 +0300 Subject: [PATCH 17/40] add api command param type --- .../API/parameters/UpdatePolicyCategoryGLCodeParams.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/libs/API/parameters/UpdatePolicyCategoryGLCodeParams.ts diff --git a/src/libs/API/parameters/UpdatePolicyCategoryGLCodeParams.ts b/src/libs/API/parameters/UpdatePolicyCategoryGLCodeParams.ts new file mode 100644 index 000000000000..f5e4d4ab7eca --- /dev/null +++ b/src/libs/API/parameters/UpdatePolicyCategoryGLCodeParams.ts @@ -0,0 +1,7 @@ +type UpdatePolicyCategoryGLCodeParams = { + policyID: string; + categoryName: string; + glCode: string; +}; + +export default UpdatePolicyCategoryGLCodeParams; From 46ef1b400b1825f572ed175d089f99fd7b2300ae Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 6 Jun 2024 00:05:17 +0300 Subject: [PATCH 18/40] add api command param type --- src/libs/API/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 322ecf227b42..c87c20a75bda 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -340,6 +340,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.RENAME_WORKSPACE_CATEGORY]: Parameters.RenameWorkspaceCategoriesParams; [WRITE_COMMANDS.SET_WORKSPACE_REQUIRES_CATEGORY]: Parameters.SetWorkspaceRequiresCategoryParams; [WRITE_COMMANDS.DELETE_WORKSPACE_CATEGORIES]: Parameters.DeleteWorkspaceCategoriesParams; + [WRITE_COMMANDS.UPDATE_POLICY_CATEGORY_GL_CODE]: Parameters.UpdatePolicyCategoryGLCodeParams; [WRITE_COMMANDS.SET_POLICY_REQUIRES_TAG]: Parameters.SetPolicyRequiresTag; [WRITE_COMMANDS.RENAME_POLICY_TAG_LIST]: Parameters.RenamePolicyTaglist; [WRITE_COMMANDS.CREATE_POLICY_TAG]: Parameters.CreatePolicyTagsParams; From 92b7424460192a01181343c47224f357589966c3 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 6 Jun 2024 00:12:14 +0300 Subject: [PATCH 19/40] export params --- src/libs/API/parameters/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 6fa58f44bd89..9f79dc02ed7b 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -166,6 +166,7 @@ export type {default as RenameWorkspaceCategoriesParams} from './RenameWorkspace export type {default as SetWorkspaceRequiresCategoryParams} from './SetWorkspaceRequiresCategoryParams'; export type {default as DeleteWorkspaceCategoriesParams} from './DeleteWorkspaceCategoriesParams'; export type {default as SetWorkspaceAutoReportingParams} from './SetWorkspaceAutoReportingParams'; +export type {default as UpdatePolicyCategoryGLCodeParams} from './UpdatePolicyCategoryGLCodeParams'; export type {default as SetWorkspaceAutoReportingFrequencyParams} from './SetWorkspaceAutoReportingFrequencyParams'; export type {default as SetWorkspaceAutoReportingMonthlyOffsetParams} from './SetWorkspaceAutoReportingMonthlyOffsetParams'; export type {default as SetWorkspaceApprovalModeParams} from './SetWorkspaceApprovalModeParams'; From 690f59c81a2001e45b55aaf2f2de55abda25f652 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 6 Jun 2024 00:14:09 +0300 Subject: [PATCH 20/40] Update src/pages/workspace/categories/CategoryGLCodePage.tsx --- src/pages/workspace/categories/CategoryGLCodePage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 3e93c8f0ba17..1340c7286424 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -23,7 +23,7 @@ import INPUT_IDS from '@src/types/form/WorkspaceCategoryForm'; import type {PolicyCategories} from '@src/types/onyx'; type WorkspaceEditCategoryGLCodePageOnyxProps = { - /** Policy category */ + /** Collection of categories attached to a policy */ policyCategories: OnyxEntry; }; From 17b9ca5de12e1faabe53779117fa65d2e7a59b99 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 6 Jun 2024 00:21:13 +0300 Subject: [PATCH 21/40] rename to glcode in tests --- tests/unit/OptionsListUtilsTest.ts | 36 +++++++++++------------ tests/utils/collections/policyCategory.ts | 3 +- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 59fc3c9b3a12..efaeeb684069 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -814,7 +814,7 @@ describe('OptionsListUtils', () => { name: 'Taxi', unencodedName: 'Taxi', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', pendingAction: undefined, @@ -824,7 +824,7 @@ describe('OptionsListUtils', () => { name: 'Restaurant', unencodedName: 'Restaurant', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', pendingAction: 'delete', @@ -834,7 +834,7 @@ describe('OptionsListUtils', () => { name: 'Food', unencodedName: 'Food', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', pendingAction: undefined, @@ -844,7 +844,7 @@ describe('OptionsListUtils', () => { name: 'Food: Meat', unencodedName: 'Food: Meat', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', pendingAction: undefined, @@ -927,7 +927,7 @@ describe('OptionsListUtils', () => { name: 'Taxi', unencodedName: 'Taxi', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -936,7 +936,7 @@ describe('OptionsListUtils', () => { name: 'Restaurant', unencodedName: 'Restaurant', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -945,7 +945,7 @@ describe('OptionsListUtils', () => { name: 'Food', unencodedName: 'Food', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -954,7 +954,7 @@ describe('OptionsListUtils', () => { name: 'Food: Meat', unencodedName: 'Food: Meat', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -963,7 +963,7 @@ describe('OptionsListUtils', () => { name: 'Food: Milk', unencodedName: 'Food: Milk', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -972,7 +972,7 @@ describe('OptionsListUtils', () => { name: 'Food: Vegetables', unencodedName: 'Food: Vegetables', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -981,7 +981,7 @@ describe('OptionsListUtils', () => { name: 'Cars: Audi', unencodedName: 'Cars: Audi', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -990,7 +990,7 @@ describe('OptionsListUtils', () => { name: 'Cars: BMW', unencodedName: 'Cars: BMW', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -999,7 +999,7 @@ describe('OptionsListUtils', () => { name: 'Cars: Mercedes-Benz', unencodedName: 'Cars: Mercedes-Benz', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -1008,7 +1008,7 @@ describe('OptionsListUtils', () => { name: 'Medical', unencodedName: 'Medical', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -1017,7 +1017,7 @@ describe('OptionsListUtils', () => { name: 'Travel: Meals', unencodedName: 'Travel: Meals', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -1026,7 +1026,7 @@ describe('OptionsListUtils', () => { name: 'Travel: Meals: Breakfast', unencodedName: 'Travel: Meals: Breakfast', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -1035,7 +1035,7 @@ describe('OptionsListUtils', () => { name: 'Travel: Meals: Dinner', unencodedName: 'Travel: Meals: Dinner', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, @@ -1044,7 +1044,7 @@ describe('OptionsListUtils', () => { name: 'Travel: Meals: Lunch', unencodedName: 'Travel: Meals: Lunch', areCommentsRequired: false, - 'GL Code': '', + glCode: '', externalID: '', origin: '', }, diff --git a/tests/utils/collections/policyCategory.ts b/tests/utils/collections/policyCategory.ts index 37a5ecb4f21f..123500a8eb37 100644 --- a/tests/utils/collections/policyCategory.ts +++ b/tests/utils/collections/policyCategory.ts @@ -8,8 +8,7 @@ export default function createRandomPolicyCategories(numberOfCategories = 0): Po categories[categoryName] = { name: categoryName, enabled: false, - // eslint-disable-next-line @typescript-eslint/naming-convention - 'GL Code': '', + glCode: '', unencodedName: categoryName, externalID: '', areCommentsRequired: false, From a1152d43c68ce66d659006602c535a74945ec637 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 6 Jun 2024 00:49:57 +0300 Subject: [PATCH 22/40] rm unused --- src/pages/workspace/categories/CategoryGLCodePage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 1340c7286424..a33e326179ba 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -4,7 +4,7 @@ import {withOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; -import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; +import type {FormOnyxValues} from '@components/Form/types'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import TextInput from '@components/TextInput'; From 69c2ba17e5388823a14a01b2bab49343af30d3b6 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 6 Jun 2024 03:24:01 +0300 Subject: [PATCH 23/40] add pending fields for glcode --- src/libs/actions/Policy/Category.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index 4a7c804ce61c..f7a218882d1d 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -347,7 +347,7 @@ function setPolicyCategoryGLCode(policyID: string, categoryName: string, glCode: ...policyCategoryToUpdate, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, pendingFields: { - name: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + glCode: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, glCode, }, @@ -363,7 +363,7 @@ function setPolicyCategoryGLCode(policyID: string, categoryName: string, glCode: ...policyCategoryToUpdate, pendingAction: null, pendingFields: { - name: null, + glCode: null, }, glCode, }, From 3495676e0801b4893d150a673fc1509a51604d72 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 6 Jun 2024 03:36:44 +0300 Subject: [PATCH 24/40] Update src/languages/es.ts --- src/languages/es.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/languages/es.ts b/src/languages/es.ts index d2dc637a6974..ef14d34eebd2 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -2214,7 +2214,6 @@ export default { importedFromAccountingSoftware: 'Categorías importadas desde', glCode: 'GL code', updateGLCodeFailureMessage: 'An error occurred while updating the GL code, please try again.', - payrollCode: 'Payroll code', }, moreFeatures: { spendSection: { From 1e4dd4de98eead4bab18c91a038d152169f195f0 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Thu, 6 Jun 2024 03:36:51 +0300 Subject: [PATCH 25/40] Update src/languages/en.ts --- src/languages/en.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 732c99bc66ff..b6d65f12b76d 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -2176,7 +2176,6 @@ export default { importedFromAccountingSoftware: 'The categories below are imported from your', glCode: 'GL code', updateGLCodeFailureMessage: 'An error occurred while updating the GL code, please try again.', - payrollCode: 'Payroll code', }, moreFeatures: { spendSection: { From 4062539ca6222d30a23cd3a8da35ec2fa237385a Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Mon, 24 Jun 2024 07:44:52 +0300 Subject: [PATCH 26/40] rename to update gl code --- src/libs/actions/Policy/Category.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index 1f8ba0880ce6..c668e4a6127b 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -331,7 +331,7 @@ function renamePolicyCategory(policyID: string, policyCategory: {oldName: string API.write(WRITE_COMMANDS.RENAME_WORKSPACE_CATEGORY, parameters, onyxData); } -function setPolicyCategoryGLCode(policyID: string, categoryName: string, glCode: string) { +function updatePolicyCategoryGLCode(policyID: string, categoryName: string, glCode: string) { const policyCategoryToUpdate = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`]?.[categoryName] ?? {}; const onyxData: OnyxData = { @@ -650,7 +650,7 @@ export { setWorkspaceRequiresCategory, createPolicyCategory, renamePolicyCategory, - setPolicyCategoryGLCode, + updatePolicyCategoryGLCode, clearCategoryErrors, enablePolicyCategories, setPolicyDistanceRatesDefaultCategory, From e1a58a0db031f6c398c7701d05837e28de5e7bbe Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Mon, 24 Jun 2024 07:45:27 +0300 Subject: [PATCH 27/40] rename to update gl code --- src/pages/workspace/categories/CategoryGLCodePage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index c16550fcdd88..1547be5bb42d 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -40,7 +40,7 @@ function CategoryGLCodePage({route, policyCategories}: EditCategoryPageProps) { (values: FormOnyxValues) => { const newGLCode = values.glCode.trim(); if (newGLCode !== glCode) { - Category.setPolicyCategoryGLCode(route.params.policyID, categoryName, newGLCode); + Category.updatePolicyCategoryGLCode(route.params.policyID, categoryName, newGLCode); } Navigation.goBack(); }, From e02ceaecd9430bd3929ffafc01b6248f65986366 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Mon, 24 Jun 2024 07:55:12 +0300 Subject: [PATCH 28/40] fix err --- src/libs/actions/Policy/Category.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index c668e4a6127b..819bd334ea06 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -374,7 +374,7 @@ function updatePolicyCategoryGLCode(policyID: string, categoryName: string, glCo value: { [categoryName]: { ...policyCategoryToUpdate, - errors: ErrorUtils.getMicroSecondOnyxError('workspace.categories.updateGLCodeFailureMessage'), + errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.categories.updateGLCodeFailureMessage'), pendingAction: null, }, }, From 4ca6c616063052cca5c44676a895fac5a60f2c76 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Mon, 24 Jun 2024 08:02:17 +0300 Subject: [PATCH 29/40] fix err --- src/libs/API/parameters/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index c4f64a4512af..c8636973c13a 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -165,7 +165,6 @@ export type {default as CreateWorkspaceCategoriesParams} from './CreateWorkspace export type {default as RenameWorkspaceCategoriesParams} from './RenameWorkspaceCategoriesParams'; export type {default as SetWorkspaceRequiresCategoryParams} from './SetWorkspaceRequiresCategoryParams'; export type {default as DeleteWorkspaceCategoriesParams} from './DeleteWorkspaceCategoriesParams'; -export type {default as SetWorkspaceAutoReportingParams} from './SetWorkspaceAutoReportingParams'; export type {default as UpdatePolicyCategoryGLCodeParams} from './UpdatePolicyCategoryGLCodeParams'; export type {default as SetWorkspaceAutoReportingFrequencyParams} from './SetWorkspaceAutoReportingFrequencyParams'; export type {default as SetWorkspaceAutoReportingMonthlyOffsetParams} from './SetWorkspaceAutoReportingMonthlyOffsetParams'; From b4fb2aa33c9e11275ae7a2f18bd8f62963bfe057 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 26 Jun 2024 15:53:17 +0300 Subject: [PATCH 30/40] add 256 chars max length --- src/CONST.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CONST.ts b/src/CONST.ts index c485268b55e2..ef1a81c9661a 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -4903,6 +4903,8 @@ const CONST = { }, }, + MAX_LENGTH_256: 256, + EXCLUDE_FROM_LAST_VISITED_PATH: [SCREENS.NOT_FOUND, SCREENS.SAML_SIGN_IN, SCREENS.VALIDATE_LOGIN] as string[], } as const; From 540a524cee153a11c5227f3c05f2b309b223c56d Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Wed, 26 Jun 2024 15:53:22 +0300 Subject: [PATCH 31/40] add 256 chars max length --- src/pages/workspace/categories/CategoryGLCodePage.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 1547be5bb42d..873c1aa145a7 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -78,6 +78,7 @@ function CategoryGLCodePage({route, policyCategories}: EditCategoryPageProps) { accessibilityLabel={translate('workspace.categories.glCode')} inputID={INPUT_IDS.GL_CODE} role={CONST.ROLE.PRESENTATION} + maxLength={CONST.MAX_LENGTH_256} /> From 9ffae3d08cdadf4b3c88e9ab0ca36808c36389dc Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Sat, 6 Jul 2024 19:03:08 +0300 Subject: [PATCH 32/40] Update src/libs/actions/Policy/Category.ts Co-authored-by: Alex Beaman --- src/libs/actions/Policy/Category.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index 6c56febc2b33..6550eaf682d3 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -376,6 +376,9 @@ function updatePolicyCategoryGLCode(policyID: string, categoryName: string, glCo ...policyCategoryToUpdate, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.categories.updateGLCodeFailureMessage'), pendingAction: null, + pendingFields: { + glCode: null, + }, }, }, }, From 26615d5b5c2358f8200400c46f83183cbfcf3261 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Sat, 6 Jul 2024 19:04:46 +0300 Subject: [PATCH 33/40] add type --- src/libs/actions/Policy/Category.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index 6c56febc2b33..bba2e66597af 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -2,7 +2,7 @@ import lodashUnion from 'lodash/union'; import type {NullishDeep, OnyxCollection, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import * as API from '@libs/API'; -import type {EnablePolicyCategoriesParams, OpenPolicyCategoriesPageParams, SetPolicyDistanceRatesDefaultCategoryParams} from '@libs/API/parameters'; +import type {EnablePolicyCategoriesParams, OpenPolicyCategoriesPageParams, SetPolicyDistanceRatesDefaultCategoryParams, UpdatePolicyCategoryGLCodeParams} from '@libs/API/parameters'; import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import * as ErrorUtils from '@libs/ErrorUtils'; import getIsNarrowLayout from '@libs/getIsNarrowLayout'; @@ -382,7 +382,7 @@ function updatePolicyCategoryGLCode(policyID: string, categoryName: string, glCo ], }; - const parameters = { + const parameters: UpdatePolicyCategoryGLCodeParams = { policyID, categoryName, glCode, From ead9b905cebde40369b4e9aa717e42bbcf1bf662 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Sat, 6 Jul 2024 19:17:23 +0300 Subject: [PATCH 34/40] use onyx hook instead of hoc --- .../categories/CategoryGLCodePage.tsx | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 873c1aa145a7..3600200df88a 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -1,7 +1,6 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback} from 'react'; -import {withOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; import type {FormOnyxValues} from '@components/Form/types'; @@ -20,20 +19,17 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import INPUT_IDS from '@src/types/form/WorkspaceCategoryForm'; -import type {PolicyCategories} from '@src/types/onyx'; -type WorkspaceEditCategoryGLCodePageOnyxProps = { - /** Collection of categories attached to a policy */ - policyCategories: OnyxEntry; -}; +type EditCategoryPageProps = StackScreenProps; -type EditCategoryPageProps = WorkspaceEditCategoryGLCodePageOnyxProps & StackScreenProps; - -function CategoryGLCodePage({route, policyCategories}: EditCategoryPageProps) { +function CategoryGLCodePage({route}: EditCategoryPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); + const policyId = route.params.policyID ?? '-1'; + const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyId}`); + const categoryName = route.params.categoryName; - const glCode = policyCategories?.[categoryName]?.glCode; + const glCode = policyCategories?.[categoryName]?.['GL Code']; const {inputCallbackRef} = useAutoFocusInput(); const editGLCode = useCallback( @@ -88,8 +84,4 @@ function CategoryGLCodePage({route, policyCategories}: EditCategoryPageProps) { CategoryGLCodePage.displayName = 'CategoryGLCodePage'; -export default withOnyx({ - policyCategories: { - key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route?.params?.policyID}`, - }, -})(CategoryGLCodePage); +export default CategoryGLCodePage; From c9ce12259d0d3d91a1ddb1baf3428c23857e419f Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Sat, 6 Jul 2024 19:17:40 +0300 Subject: [PATCH 35/40] rename to GL CODE to match backend --- src/libs/actions/Policy/Category.ts | 15 ++++++++++----- src/types/onyx/PolicyCategory.ts | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index ca1a754981d2..3af4749569c9 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -344,9 +344,11 @@ function updatePolicyCategoryGLCode(policyID: string, categoryName: string, glCo ...policyCategoryToUpdate, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, pendingFields: { - glCode: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + // eslint-disable-next-line @typescript-eslint/naming-convention + 'GL Code': CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, - glCode, + // eslint-disable-next-line @typescript-eslint/naming-convention + 'GL Code': glCode, }, }, }, @@ -360,9 +362,11 @@ function updatePolicyCategoryGLCode(policyID: string, categoryName: string, glCo ...policyCategoryToUpdate, pendingAction: null, pendingFields: { - glCode: null, + // eslint-disable-next-line @typescript-eslint/naming-convention + 'GL Code': null, }, - glCode, + // eslint-disable-next-line @typescript-eslint/naming-convention + 'GL Code': glCode, }, }, }, @@ -377,7 +381,8 @@ function updatePolicyCategoryGLCode(policyID: string, categoryName: string, glCo errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.categories.updateGLCodeFailureMessage'), pendingAction: null, pendingFields: { - glCode: null, + // eslint-disable-next-line @typescript-eslint/naming-convention + 'GL Code': null, }, }, }, diff --git a/src/types/onyx/PolicyCategory.ts b/src/types/onyx/PolicyCategory.ts index e579ef957553..c9191ae5b8d9 100644 --- a/src/types/onyx/PolicyCategory.ts +++ b/src/types/onyx/PolicyCategory.ts @@ -15,7 +15,8 @@ type PolicyCategory = OnyxCommon.OnyxValueWithOfflineFeedback<{ areCommentsRequired?: boolean; /** "General Ledger code" that corresponds to this category in an accounting system. Similar to an ID. */ - glCode?: string; + // eslint-disable-next-line @typescript-eslint/naming-convention + 'GL Code'?: string; /** An ID for this category from an external accounting system */ externalID?: string; From 48d1abbf4214755306f7518e58bf7e1fba0e1ec5 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Sat, 6 Jul 2024 19:21:19 +0300 Subject: [PATCH 36/40] rename to GL Code in tests --- tests/unit/OptionsListUtilsTest.ts | 36 +++++++++++------------ tests/utils/collections/policyCategory.ts | 3 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 0741888f750d..4a1171658f4d 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -836,7 +836,7 @@ describe('OptionsListUtils', () => { name: 'Taxi', unencodedName: 'Taxi', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', pendingAction: undefined, @@ -846,7 +846,7 @@ describe('OptionsListUtils', () => { name: 'Restaurant', unencodedName: 'Restaurant', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', pendingAction: 'delete', @@ -856,7 +856,7 @@ describe('OptionsListUtils', () => { name: 'Food', unencodedName: 'Food', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', pendingAction: undefined, @@ -866,7 +866,7 @@ describe('OptionsListUtils', () => { name: 'Food: Meat', unencodedName: 'Food: Meat', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', pendingAction: undefined, @@ -949,7 +949,7 @@ describe('OptionsListUtils', () => { name: 'Taxi', unencodedName: 'Taxi', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -958,7 +958,7 @@ describe('OptionsListUtils', () => { name: 'Restaurant', unencodedName: 'Restaurant', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -967,7 +967,7 @@ describe('OptionsListUtils', () => { name: 'Food', unencodedName: 'Food', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -976,7 +976,7 @@ describe('OptionsListUtils', () => { name: 'Food: Meat', unencodedName: 'Food: Meat', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -985,7 +985,7 @@ describe('OptionsListUtils', () => { name: 'Food: Milk', unencodedName: 'Food: Milk', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -994,7 +994,7 @@ describe('OptionsListUtils', () => { name: 'Food: Vegetables', unencodedName: 'Food: Vegetables', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -1003,7 +1003,7 @@ describe('OptionsListUtils', () => { name: 'Cars: Audi', unencodedName: 'Cars: Audi', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -1012,7 +1012,7 @@ describe('OptionsListUtils', () => { name: 'Cars: BMW', unencodedName: 'Cars: BMW', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -1021,7 +1021,7 @@ describe('OptionsListUtils', () => { name: 'Cars: Mercedes-Benz', unencodedName: 'Cars: Mercedes-Benz', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -1030,7 +1030,7 @@ describe('OptionsListUtils', () => { name: 'Medical', unencodedName: 'Medical', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -1039,7 +1039,7 @@ describe('OptionsListUtils', () => { name: 'Travel: Meals', unencodedName: 'Travel: Meals', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -1048,7 +1048,7 @@ describe('OptionsListUtils', () => { name: 'Travel: Meals: Breakfast', unencodedName: 'Travel: Meals: Breakfast', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -1057,7 +1057,7 @@ describe('OptionsListUtils', () => { name: 'Travel: Meals: Dinner', unencodedName: 'Travel: Meals: Dinner', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, @@ -1066,7 +1066,7 @@ describe('OptionsListUtils', () => { name: 'Travel: Meals: Lunch', unencodedName: 'Travel: Meals: Lunch', areCommentsRequired: false, - glCode: '', + 'GL Code': '', externalID: '', origin: '', }, diff --git a/tests/utils/collections/policyCategory.ts b/tests/utils/collections/policyCategory.ts index 123500a8eb37..37a5ecb4f21f 100644 --- a/tests/utils/collections/policyCategory.ts +++ b/tests/utils/collections/policyCategory.ts @@ -8,7 +8,8 @@ export default function createRandomPolicyCategories(numberOfCategories = 0): Po categories[categoryName] = { name: categoryName, enabled: false, - glCode: '', + // eslint-disable-next-line @typescript-eslint/naming-convention + 'GL Code': '', unencodedName: categoryName, externalID: '', areCommentsRequired: false, From bb0f7f0b15798f184f99173debd867a737e0d93f Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Sat, 6 Jul 2024 19:24:28 +0300 Subject: [PATCH 37/40] update spanish --- src/languages/es.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/es.ts b/src/languages/es.ts index 84038548c04a..a304473a1605 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -2524,7 +2524,7 @@ export default { invalidCategoryName: 'Lo nombre de la categoría es invalido.', importedFromAccountingSoftware: 'Categorías importadas desde', glCode: 'GL code', - updateGLCodeFailureMessage: 'An error occurred while updating the GL code, please try again.', + updateGLCodeFailureMessage: 'Se produjo un error al actualizar el GL code, inténtelo nuevamente.', }, moreFeatures: { spendSection: { From 84513ac24ee3feca34b14c1f53e1d6472389ad9e Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Sat, 6 Jul 2024 19:27:16 +0300 Subject: [PATCH 38/40] rename to GL Code --- src/pages/workspace/categories/CategorySettingsPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/categories/CategorySettingsPage.tsx b/src/pages/workspace/categories/CategorySettingsPage.tsx index aec83eb47d6a..9fa78a4e6d8c 100644 --- a/src/pages/workspace/categories/CategorySettingsPage.tsx +++ b/src/pages/workspace/categories/CategorySettingsPage.tsx @@ -126,9 +126,9 @@ function CategorySettingsPage({route, policyCategories, navigation}: CategorySet shouldShowRightIcon /> - + Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_GL_CODE.getRoute(route.params.policyID, policyCategory.name))} shouldShowRightIcon From e4aabf86eeffbb3564d712cd55ce30fa0351fb76 Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Tue, 9 Jul 2024 15:38:35 +0300 Subject: [PATCH 39/40] add spanish --- src/languages/es.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/languages/es.ts b/src/languages/es.ts index 00501b07f219..d47306419e14 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -2540,8 +2540,8 @@ export default { existingCategoryError: 'Ya existe una categoría con este nombre.', invalidCategoryName: 'Lo nombre de la categoría es invalido.', importedFromAccountingSoftware: 'Categorías importadas desde', - glCode: 'GL code', - updateGLCodeFailureMessage: 'Se produjo un error al actualizar el GL code, inténtelo nuevamente.', + glCode: 'Código GL', + updateGLCodeFailureMessage: 'Se produjo un error al actualizar el código GL. Inténtelo nuevamente.', }, moreFeatures: { spendSection: { From ca614a44e5a6ad4a6e35790b7bcfe3106114355d Mon Sep 17 00:00:00 2001 From: Rushat Gabhane Date: Tue, 9 Jul 2024 15:41:13 +0300 Subject: [PATCH 40/40] add control policy check --- src/CONST.ts | 1 + src/libs/PolicyUtils.ts | 5 +++++ src/pages/workspace/AccessOrNotFoundWrapper.tsx | 1 + src/pages/workspace/categories/CategoryGLCodePage.tsx | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/CONST.ts b/src/CONST.ts index caf0b1453fae..c5953fb74a03 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2048,6 +2048,7 @@ const CONST = { ACCESS_VARIANTS: { PAID: 'paid', ADMIN: 'admin', + CONTROL: 'control', }, DEFAULT_MAX_EXPENSE_AGE: 90, DEFAULT_MAX_EXPENSE_AMOUNT: 200000, diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index fc9a04e2507c..74709faedc9c 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -305,6 +305,10 @@ function isPaidGroupPolicy(policy: OnyxEntry): boolean { return policy?.type === CONST.POLICY.TYPE.TEAM || policy?.type === CONST.POLICY.TYPE.CORPORATE; } +function isControlPolicy(policy: OnyxEntry): boolean { + return policy?.type === CONST.POLICY.TYPE.CORPORATE; +} + function isTaxTrackingEnabled(isPolicyExpenseChat: boolean, policy: OnyxEntry, isDistanceRequest: boolean): boolean { const distanceUnit = getCustomUnit(policy); const customUnitID = distanceUnit?.customUnitID ?? 0; @@ -727,6 +731,7 @@ export { getIntegrationLastSuccessfulDate, getCurrentConnectionName, getCustomersOrJobsLabelNetSuite, + isControlPolicy, }; export type {MemberEmailsToAccountIDs}; diff --git a/src/pages/workspace/AccessOrNotFoundWrapper.tsx b/src/pages/workspace/AccessOrNotFoundWrapper.tsx index c7f89559fdda..770358335680 100644 --- a/src/pages/workspace/AccessOrNotFoundWrapper.tsx +++ b/src/pages/workspace/AccessOrNotFoundWrapper.tsx @@ -24,6 +24,7 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject'; const ACCESS_VARIANTS = { [CONST.POLICY.ACCESS_VARIANTS.PAID]: (policy: OnyxEntry) => PolicyUtils.isPaidGroupPolicy(policy), [CONST.POLICY.ACCESS_VARIANTS.ADMIN]: (policy: OnyxEntry, login: string) => PolicyUtils.isPolicyAdmin(policy, login), + [CONST.POLICY.ACCESS_VARIANTS.CONTROL]: (policy: OnyxEntry) => PolicyUtils.isControlPolicy(policy), [CONST.IOU.ACCESS_VARIANTS.CREATE]: ( policy: OnyxEntry, login: string, diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 3600200df88a..050ced2e497c 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -45,7 +45,7 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) { return (