Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Policy category - Add GL Code #43149

Merged
merged 47 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
156a162
add route for category glcode
rushatgabhane Jun 5, 2024
0fdc592
add screen for category glcode
rushatgabhane Jun 5, 2024
1a93283
add lang for glcode
rushatgabhane Jun 5, 2024
2e34de5
link to glcode screen and add type
rushatgabhane Jun 5, 2024
e8f55eb
link to glcode screen and add type
rushatgabhane Jun 5, 2024
8e9262e
add nav type
rushatgabhane Jun 5, 2024
476161e
add nav type
rushatgabhane Jun 5, 2024
aa4bfb6
add menu item for gl code
rushatgabhane Jun 5, 2024
5790939
add page for glcode
rushatgabhane Jun 5, 2024
da4b4d0
add edit gl code form
rushatgabhane Jun 5, 2024
7e455e1
decode categeory name from uri
rushatgabhane Jun 5, 2024
09f10dc
fix lint
rushatgabhane Jun 5, 2024
e864c7e
add glcode type
rushatgabhane Jun 5, 2024
6d8788f
add err message
rushatgabhane Jun 5, 2024
17f33a8
add type glcode command
rushatgabhane Jun 5, 2024
ee455af
add api command for glcode category
rushatgabhane Jun 5, 2024
f92e72e
add api command param type
rushatgabhane Jun 5, 2024
46ef1b4
add api command param type
rushatgabhane Jun 5, 2024
92b7424
export params
rushatgabhane Jun 5, 2024
690f59c
Update src/pages/workspace/categories/CategoryGLCodePage.tsx
rushatgabhane Jun 5, 2024
17b9ca5
rename to glcode in tests
rushatgabhane Jun 5, 2024
a1152d4
rm unused
rushatgabhane Jun 5, 2024
69c2ba1
add pending fields for glcode
rushatgabhane Jun 6, 2024
3495676
Update src/languages/es.ts
rushatgabhane Jun 6, 2024
1e4dd4d
Update src/languages/en.ts
rushatgabhane Jun 6, 2024
1a26ba1
rename to gl_code and merge main
rushatgabhane Jun 24, 2024
4062539
rename to update gl code
rushatgabhane Jun 24, 2024
e1a58a0
rename to update gl code
rushatgabhane Jun 24, 2024
e02ceae
fix err
rushatgabhane Jun 24, 2024
4ca6c61
fix err
rushatgabhane Jun 24, 2024
b4fb2aa
add 256 chars max length
rushatgabhane Jun 26, 2024
540a524
add 256 chars max length
rushatgabhane Jun 26, 2024
bfe2abc
merge main
rushatgabhane Jun 26, 2024
0f5854a
fix merge
rushatgabhane Jul 6, 2024
9ffae3d
Update src/libs/actions/Policy/Category.ts
rushatgabhane Jul 6, 2024
26615d5
add type
rushatgabhane Jul 6, 2024
df7a56e
Merge branch 'gl-code' of github.com:rushatgabhane/exfy into gl-code
rushatgabhane Jul 6, 2024
ead9b90
use onyx hook instead of hoc
rushatgabhane Jul 6, 2024
c9ce122
rename to GL CODE to match backend
rushatgabhane Jul 6, 2024
48d1abb
rename to GL Code in tests
rushatgabhane Jul 6, 2024
bb0f7f0
update spanish
rushatgabhane Jul 6, 2024
84513ac
rename to GL Code
rushatgabhane Jul 6, 2024
c519409
fix conflicts
rushatgabhane Jul 9, 2024
e4aabf8
add spanish
rushatgabhane Jul 9, 2024
ca614a4
add control policy check
rushatgabhane Jul 9, 2024
6c7c294
fix merge
rushatgabhane Jul 10, 2024
16b6308
Merge branch 'main' into gl-code
rushatgabhane Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,9 @@ 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',
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
updateGLCodeFailureMessage: 'An error occurred while updating the GL code, please try again.',
payrollCode: 'Payroll code',
rushatgabhane marked this conversation as resolved.
Show resolved Hide resolved
},
moreFeatures: {
spendSection: {
Expand Down
3 changes: 3 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,9 @@ 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: 'An error occurred while updating the GL code, please try again.',
payrollCode: 'Payroll code',
rushatgabhane marked this conversation as resolved.
Show resolved Hide resolved
},
moreFeatures: {
spendSection: {
Expand Down
7 changes: 7 additions & 0 deletions src/libs/API/parameters/UpdatePolicyCategoryGLCodeParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type UpdatePolicyCategoryGLCodeParams = {
policyID: string;
categoryName: string;
glCode: string;
};

export default UpdatePolicyCategoryGLCodeParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB - damn i wish we could rename all of these to "Policy" for consistency...... But not really appropriate in this PR lol

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';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -339,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.WORKSPACE.OWNER_CHANGE_ERROR]: () => 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ const FULL_SCREEN_TO_RHP_MAPPING: Partial<Record<FullScreenName, string[]>> = {
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,
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
],
[SCREENS.WORKSPACE.DISTANCE_RATES]: [
SCREENS.WORKSPACE.CREATE_DISTANCE_RATE,
SCREENS.WORKSPACE.DISTANCE_RATES_SETTINGS,
Expand Down
6 changes: 6 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
categoryName: (categoryName: string) => decodeURIComponent(categoryName),
},
},
[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,
},
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ type SettingsNavigatorParamList = {
categoryName: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.CATEGORY_GLCODE]: {
policyID: string;
categoryName: string;
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
};
[SCREENS.WORKSPACE.CATEGORY_SETTINGS]: {
policyID: string;
categoryName: string;
Expand Down
61 changes: 61 additions & 0 deletions src/libs/actions/Policy/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
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,
Gonals marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
],
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,
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
errors: ErrorUtils.getMicroSecondOnyxError('workspace.categories.updateGLCodeFailureMessage'),
pendingAction: null,
rushatgabhane marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
],
};

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: [
Expand Down Expand Up @@ -593,6 +653,7 @@ export {
setWorkspaceRequiresCategory,
createPolicyCategory,
renamePolicyCategory,
setPolicyCategoryGLCode,
clearCategoryErrors,
enablePolicyCategories,
setPolicyDistanceRatesDefaultCategory,
Expand Down
94 changes: 94 additions & 0 deletions src/pages/workspace/categories/CategoryGLCodePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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 {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';
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 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<PolicyCategories>;
};

type EditCategoryPageProps = WorkspaceEditCategoryGLCodePageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.CATEGORY_GLCODE>;

function CategoryGLCodePage({route, policyCategories}: EditCategoryPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const categoryName = route.params.categoryName;
const glCode = policyCategories?.[categoryName]?.glCode;
const {inputCallbackRef} = useAutoFocusInput();

const editGLCode = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
const newGLCode = values.glCode.trim();
if (newGLCode !== glCode) {
Category.setPolicyCategoryGLCode(route.params.policyID, categoryName, newGLCode);
}
Navigation.goBack();
},
[categoryName, glCode, route.params.policyID],
);

return (
<AccessOrNotFoundWrapper
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
policyID={route.params.policyID}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED}
>
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
style={[styles.defaultModalContainer]}
testID={CategoryGLCodePage.displayName}
shouldEnableMaxHeight
>
<HeaderWithBackButton
title={translate('workspace.categories.glCode')}
onBackButtonPress={() => Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName))}
/>
<FormProvider
formID={ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM}
onSubmit={editGLCode}
submitButtonText={translate('common.save')}
style={[styles.mh5, styles.flex1]}
enabledWhenOffline
>
<InputWrapper
ref={inputCallbackRef}
InputComponent={TextInput}
defaultValue={glCode}
label={translate('workspace.categories.glCode')}
accessibilityLabel={translate('workspace.categories.glCode')}
inputID={INPUT_IDS.GL_CODE}
role={CONST.ROLE.PRESENTATION}
/>
</FormProvider>
</ScreenWrapper>
</AccessOrNotFoundWrapper>
);
}

CategoryGLCodePage.displayName = 'CategoryGLCodePage';

export default withOnyx<EditCategoryPageProps, WorkspaceEditCategoryGLCodePageOnyxProps>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use useOnyx instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rushatgabhane Bump here.

policyCategories: {
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route?.params?.policyID}`,
},
})(CategoryGLCodePage);
8 changes: 8 additions & 0 deletions src/pages/workspace/categories/CategorySettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ function CategorySettingsPage({route, policyCategories, navigation}: CategorySet
shouldShowRightIcon
/>
</OfflineWithFeedback>
<OfflineWithFeedback pendingAction={policyCategory.pendingFields?.glCode}>
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
<MenuItemWithTopDescription
title={policyCategory.glCode}
description={translate(`workspace.categories.glCode`)}
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_GLCODE.getRoute(route.params.policyID, policyCategory.name))}
shouldShowRightIcon
/>
</OfflineWithFeedback>
</View>
</ScreenWrapper>
</AccessOrNotFoundWrapper>
Expand Down
2 changes: 2 additions & 0 deletions src/types/form/WorkspaceCategoryForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type Form from './Form';

const INPUT_IDS = {
CATEGORY_NAME: 'categoryName',
GL_CODE: 'glCode',
} as const;

type InputID = ValueOf<typeof INPUT_IDS>;
Expand All @@ -11,6 +12,7 @@ type WorkspaceCategoryForm = Form<
InputID,
{
[INPUT_IDS.CATEGORY_NAME]: string;
[INPUT_IDS.GL_CODE]: string;
}
>;

Expand Down
3 changes: 1 addition & 2 deletions src/types/onyx/PolicyCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading