Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ const DYNAMIC_ROUTES = {
path: 'imported',
entryScreens: [SCREENS.WORKSPACE.CATEGORIES],
},
SPEND_CATEGORY_SELECTOR: {
path: 'spend-category-selector/:groupID',
entryScreens: [SCREENS.WORKSPACE.CATEGORIES_SETTINGS, SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_SETTINGS],
getRoute: (groupID: string) => `spend-category-selector/${groupID}` as const,
},
DEFAULT_CATEGORY_SELECTOR: {
path: 'default-category-selector/:customUnitID',
entryScreens: [SCREENS.WORKSPACE.DISTANCE_RATES_SETTINGS, SCREENS.WORKSPACE.PER_DIEM_SETTINGS],
getRoute: (customUnitID: string) => `default-category-selector/${customUnitID}` as const,
},
WORKSPACE_INVITE: {
path: 'invite',
entryScreens: [SCREENS.WORKSPACE.PROFILE, SCREENS.WORKSPACE.MEMBERS],
Expand Down
2 changes: 2 additions & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,8 @@ const SCREENS = {
CATEGORIES_SETTINGS: 'Categories_Settings',
DYNAMIC_CATEGORIES_IMPORT: 'Dynamic_Categories_Import',
DYNAMIC_CATEGORIES_IMPORTED: 'Dynamic_Categories_Imported',
DYNAMIC_SPEND_CATEGORY_SELECTOR: 'Dynamic_Spend_Category_Selector',
DYNAMIC_DEFAULT_CATEGORY_SELECTOR: 'Dynamic_Default_Category_Selector',
MORE_FEATURES: 'Workspace_More_Features',
MEMBER_DETAILS: 'Workspace_Member_Details',
MEMBER_DETAILS_ROLE: 'Workspace_Member_Details_Role',
Expand Down
64 changes: 0 additions & 64 deletions src/components/CategorySelector/CategorySelectorModal.tsx

This file was deleted.

75 changes: 0 additions & 75 deletions src/components/CategorySelector/index.tsx

This file was deleted.

52 changes: 52 additions & 0 deletions src/components/CustomUnitDefaultCategorySelector/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import useThemeStyles from '@hooks/useThemeStyles';
import {getDecodedCategoryName} from '@libs/CategoryUtils';
import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import {DYNAMIC_ROUTES} from '@src/ROUTES';

type CustomUnitDefaultCategorySelectorProps = {
/** Currently selected category */
defaultValue?: string;

/** Label to display on field */
label: string;

/** Any additional styles to apply */
wrapperStyle: StyleProp<ViewStyle>;

/** Whether item is focused or active */
focused?: boolean;

/** The custom unit ID to update when selecting a category */
customUnitID: string;
};

function CustomUnitDefaultCategorySelector({defaultValue = '', wrapperStyle, label, focused, customUnitID}: CustomUnitDefaultCategorySelectorProps) {
const styles = useThemeStyles();

const decodedCategoryName = getDecodedCategoryName(defaultValue);
const descStyle = decodedCategoryName.length === 0 ? styles.textNormal : null;

const onPress = () => {
Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.DEFAULT_CATEGORY_SELECTOR.getRoute(customUnitID)));
};

return (
<MenuItemWithTopDescription
shouldShowRightIcon
title={decodedCategoryName}
description={label}
descriptionTextStyle={descStyle}
onPress={onPress}
wrapperStyle={wrapperStyle}
focused={focused}
sentryLabel={CONST.SENTRY_LABEL.WORKSPACE.RULES.CATEGORY_SELECTOR}
/>
);
}

export default CustomUnitDefaultCategorySelector;
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.WORKSPACE.CATEGORIES_SETTINGS]: () => require<ReactComponentModule>('../../../../pages/workspace/categories/WorkspaceCategoriesSettingsPage').default,
[SCREENS.WORKSPACE.DYNAMIC_CATEGORIES_IMPORT]: () => require<ReactComponentModule>('../../../../pages/workspace/categories/ImportCategoriesPage').default,
[SCREENS.WORKSPACE.DYNAMIC_CATEGORIES_IMPORTED]: () => require<ReactComponentModule>('../../../../pages/workspace/categories/ImportedCategoriesPage').default,
[SCREENS.WORKSPACE.DYNAMIC_SPEND_CATEGORY_SELECTOR]: () => require<ReactComponentModule>('../../../../pages/workspace/categories/DynamicSpendCategorySelectorPage').default,
[SCREENS.WORKSPACE.DYNAMIC_DEFAULT_CATEGORY_SELECTOR]: () => require<ReactComponentModule>('../../../../pages/workspace/categories/DynamicDefaultCategorySelectorPage').default,
[SCREENS.WORKSPACE.UPGRADE]: () => require<ReactComponentModule>('../../../../pages/workspace/upgrade/WorkspaceUpgradePage').default,
[SCREENS.WORKSPACE.DOWNGRADE]: () => require<ReactComponentModule>('../../../../pages/workspace/downgrade/WorkspaceDowngradePage').default,
[SCREENS.WORKSPACE.PAY_AND_DOWNGRADE]: () => require<ReactComponentModule>('../../../../pages/workspace/downgrade/PayAndDowngradePage').default,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,8 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
},
[SCREENS.WORKSPACE.DYNAMIC_CATEGORIES_IMPORT]: DYNAMIC_ROUTES.WORKSPACE_CATEGORIES_IMPORT.path,
[SCREENS.WORKSPACE.DYNAMIC_CATEGORIES_IMPORTED]: DYNAMIC_ROUTES.WORKSPACE_CATEGORIES_IMPORTED.path,
[SCREENS.WORKSPACE.DYNAMIC_SPEND_CATEGORY_SELECTOR]: DYNAMIC_ROUTES.SPEND_CATEGORY_SELECTOR.path,
[SCREENS.WORKSPACE.DYNAMIC_DEFAULT_CATEGORY_SELECTOR]: DYNAMIC_ROUTES.DEFAULT_CATEGORY_SELECTOR.path,
[SCREENS.WORKSPACE.WORKFLOWS_PAYER]: {
path: ROUTES.WORKSPACE_WORKFLOWS_PAYER.route,
},
Expand Down
8 changes: 8 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ type SettingsNavigatorParamList = {
// eslint-disable-next-line no-restricted-syntax -- `backTo` usages in this file are legacy. Do not add new `backTo` params to screens. See contributingGuides/NAVIGATION.md
backTo?: Routes;
};
[SCREENS.WORKSPACE.DYNAMIC_SPEND_CATEGORY_SELECTOR]: {
policyID: string;
groupID: string;
};
[SCREENS.WORKSPACE.DYNAMIC_DEFAULT_CATEGORY_SELECTOR]: {
policyID: string;
customUnitID: string;
};
[SCREENS.WORKSPACE.DYNAMIC_CATEGORIES_IMPORT]: {
policyID: string;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';
import CategoryPicker from '@components/CategoryPicker';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import type {ListItem} from '@components/SelectionList/types';
import useDynamicBackPath from '@hooks/useDynamicBackPath';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import {setPolicyCustomUnitDefaultCategory} from '@userActions/Policy/Category';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {DYNAMIC_ROUTES} from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';

type DynamicDefaultCategorySelectorPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.DYNAMIC_DEFAULT_CATEGORY_SELECTOR>;

function DynamicDefaultCategorySelectorPage({route}: DynamicDefaultCategorySelectorPageProps) {
const {policyID, customUnitID} = route.params;
const styles = useThemeStyles();
const {translate} = useLocalize();
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(policyID)}`);
const currentCategory = policy?.customUnits?.[customUnitID]?.defaultCategory ?? '';
const backPath = useDynamicBackPath(DYNAMIC_ROUTES.DEFAULT_CATEGORY_SELECTOR.path);

const onCategorySelected = (selectedCategory: ListItem) => {
if (!selectedCategory.searchText) {
return;
}
if (currentCategory === selectedCategory.searchText) {
Navigation.goBack(backPath);
return;
}
setPolicyCustomUnitDefaultCategory(policyID, customUnitID, currentCategory, selectedCategory.searchText);
Navigation.goBack(backPath);
};

return (
<AccessOrNotFoundWrapper
policyID={policyID}
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED}
>
<ScreenWrapper
style={styles.pb0}
enableEdgeToEdgeBottomSafeAreaPadding
shouldEnableKeyboardAvoidingView={false}
testID="DynamicDefaultCategorySelectorPage"
>
<HeaderWithBackButton
title={translate('workspace.common.defaultCategory')}
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack(backPath)}
/>
<CategoryPicker
policyID={policyID}
selectedCategory={currentCategory}
onSubmit={onCategorySelected}
addBottomSafeAreaPadding
/>
</ScreenWrapper>
</AccessOrNotFoundWrapper>
);
}

export default DynamicDefaultCategorySelectorPage;
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';
import CategoryPicker from '@components/CategoryPicker';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import type {ListItem} from '@components/SelectionList/types';
import useDynamicBackPath from '@hooks/useDynamicBackPath';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import {setWorkspaceDefaultSpendCategory} from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {DYNAMIC_ROUTES} from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';

type DynamicSpendCategorySelectorPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.DYNAMIC_SPEND_CATEGORY_SELECTOR>;

function DynamicSpendCategorySelectorPage({route}: DynamicSpendCategorySelectorPageProps) {
const {policyID, groupID} = route.params;
const styles = useThemeStyles();
const backPath = useDynamicBackPath(DYNAMIC_ROUTES.SPEND_CATEGORY_SELECTOR.path);
Comment thread
jmusial marked this conversation as resolved.

const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(policyID)}`);
const label = groupID.charAt(0).toUpperCase() + groupID.slice(1);
const currentCategory = policy?.mccGroup?.[groupID]?.category ?? '';

const onCategorySelected = (selectedCategory: ListItem) => {
if (!selectedCategory.keyForList) {
return;
}
if (currentCategory === selectedCategory.keyForList) {
Navigation.goBack(backPath);
return;
}
setWorkspaceDefaultSpendCategory(policyID, groupID, selectedCategory.keyForList, policy?.mccGroup);
Navigation.goBack(backPath);
};

return (
<AccessOrNotFoundWrapper
policyID={policyID}
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED}
>
<ScreenWrapper
style={styles.pb0}
enableEdgeToEdgeBottomSafeAreaPadding
shouldEnableKeyboardAvoidingView={false}
testID="DynamicSpendCategorySelectorPage"
>
<HeaderWithBackButton
title={label}
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack(backPath)}
/>
<CategoryPicker
policyID={policyID}
selectedCategory={currentCategory}
onSubmit={onCategorySelected}
addBottomSafeAreaPadding
/>
</ScreenWrapper>
</AccessOrNotFoundWrapper>
);
}

export default DynamicSpendCategorySelectorPage;
Loading
Loading