11import React from 'react' ;
22import type { StyleProp , ViewStyle } from 'react-native' ;
3- import { View } from 'react-native' ;
43import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription' ;
5- import type { ListItem } from '@components/SelectionList/types' ;
64import useThemeStyles from '@hooks/useThemeStyles' ;
75import { getDecodedCategoryName } from '@libs/CategoryUtils' ;
6+ import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute' ;
7+ import Navigation from '@libs/Navigation/Navigation' ;
88import CONST from '@src/CONST' ;
9- import CategorySelectorModal from './CategorySelectorModal ' ;
9+ import { DYNAMIC_ROUTES } from '@src/ROUTES ' ;
1010
1111type CategorySelectorProps = {
12- /** The ID of the associated policy */
13- policyID : string ;
14-
15- /** Function to call when the user selects a category */
16- setNewCategory : ( value : ListItem ) => void ;
17-
1812 /** Currently selected category */
1913 defaultValue ?: string ;
2014
@@ -27,48 +21,31 @@ type CategorySelectorProps = {
2721 /** Whether item is focused or active */
2822 focused ?: boolean ;
2923
30- /** Whether category item picker is visible */
31- isPickerVisible : boolean ;
32-
33- /** Callback to show category picker */
34- showPickerModal : ( ) => void ;
35-
36- /** Callback to hide category picker */
37- hidePickerModal : ( ) => void ;
24+ /** The custom unit ID to update when selecting a category */
25+ customUnitID : string ;
3826} ;
3927
40- function CategorySelector ( { defaultValue = '' , wrapperStyle, label, setNewCategory , policyID , focused, isPickerVisible , showPickerModal , hidePickerModal } : CategorySelectorProps ) {
28+ function CategorySelector ( { defaultValue = '' , wrapperStyle, label, focused, customUnitID } : CategorySelectorProps ) {
4129 const styles = useThemeStyles ( ) ;
4230
43- const updateCategoryInput = ( categoryItem : ListItem ) => {
44- setNewCategory ( categoryItem ) ;
45- hidePickerModal ( ) ;
46- } ;
47-
4831 const decodedCategoryName = getDecodedCategoryName ( defaultValue ) ;
4932 const descStyle = decodedCategoryName . length === 0 ? styles . textNormal : null ;
5033
34+ const onPress = ( ) => {
35+ Navigation . navigate ( createDynamicRoute ( DYNAMIC_ROUTES . DEFAULT_CATEGORY_SELECTOR . getRoute ( customUnitID ) ) ) ;
36+ } ;
37+
5138 return (
52- < View >
53- < MenuItemWithTopDescription
54- shouldShowRightIcon
55- title = { decodedCategoryName }
56- description = { label }
57- descriptionTextStyle = { descStyle }
58- onPress = { showPickerModal }
59- wrapperStyle = { wrapperStyle }
60- focused = { focused }
61- sentryLabel = { CONST . SENTRY_LABEL . WORKSPACE . RULES . CATEGORY_SELECTOR }
62- />
63- < CategorySelectorModal
64- policyID = { policyID }
65- isVisible = { isPickerVisible }
66- currentCategory = { defaultValue }
67- onClose = { hidePickerModal }
68- onCategorySelected = { updateCategoryInput }
69- label = { label }
70- />
71- </ View >
39+ < MenuItemWithTopDescription
40+ shouldShowRightIcon
41+ title = { decodedCategoryName }
42+ description = { label }
43+ descriptionTextStyle = { descStyle }
44+ onPress = { onPress }
45+ wrapperStyle = { wrapperStyle }
46+ focused = { focused }
47+ sentryLabel = { CONST . SENTRY_LABEL . WORKSPACE . RULES . CATEGORY_SELECTOR }
48+ />
7249 ) ;
7350}
7451
0 commit comments