@@ -30,10 +30,12 @@ function EditCategoryPage({route}: EditCategoryPageProps) {
3030 const isQuickSettingsFlow = route . name === SCREENS . SETTINGS_CATEGORIES . DYNAMIC_SETTINGS_CATEGORY_EDIT ;
3131 const backPath = useDynamicBackPath ( DYNAMIC_ROUTES . SETTINGS_CATEGORY_EDIT . path ) ;
3232
33+ const sanitizeCategoryName = useCallback ( ( name : string ) => name . replaceAll ( CONST . REGEX . NON_BREAKING_SPACE , ' ' ) . trim ( ) , [ ] ) ;
34+
3335 const validate = useCallback (
3436 ( values : FormOnyxValues < typeof ONYXKEYS . FORMS . WORKSPACE_CATEGORY_FORM > ) => {
3537 const errors : FormInputErrors < typeof ONYXKEYS . FORMS . WORKSPACE_CATEGORY_FORM > = { } ;
36- const newCategoryName = values . categoryName . trim ( ) ;
38+ const newCategoryName = sanitizeCategoryName ( values . categoryName ) ;
3739
3840 if ( ! newCategoryName ) {
3941 errors . categoryName = translate ( 'workspace.categories.categoryRequiredError' ) ;
@@ -45,23 +47,23 @@ function EditCategoryPage({route}: EditCategoryPageProps) {
4547 }
4648 return errors ;
4749 } ,
48- [ policyCategories , currentCategoryName , translate ] ,
50+ [ policyCategories , currentCategoryName , translate , sanitizeCategoryName ] ,
4951 ) ;
5052
5153 const editCategory = useCallback (
5254 ( values : FormOnyxValues < typeof ONYXKEYS . FORMS . WORKSPACE_CATEGORY_FORM > ) => {
53- const newCategoryName = values . categoryName . trim ( ) ;
55+ const newCategoryName = sanitizeCategoryName ( values . categoryName ) ;
5456 // Do not call the API if the edited category name is the same as the current category name
5557 if ( currentCategoryName !== newCategoryName ) {
56- renamePolicyCategory ( policyData , { oldName : currentCategoryName , newName : values . categoryName } ) ;
58+ renamePolicyCategory ( policyData , { oldName : currentCategoryName , newName : newCategoryName } ) ;
5759 }
5860
5961 // Ensure Onyx.update is executed before navigation to prevent UI blinking issues, affecting the category name and rate.
6062 Navigation . setNavigationActionToMicrotaskQueue ( ( ) => {
6163 Navigation . goBack ( isQuickSettingsFlow ? backPath : ROUTES . WORKSPACE_CATEGORY_SETTINGS . getRoute ( policyID , currentCategoryName ) , { compareParams : false } ) ;
6264 } ) ;
6365 } ,
64- [ currentCategoryName , policyData , isQuickSettingsFlow , backPath , policyID ] ,
66+ [ currentCategoryName , policyData , isQuickSettingsFlow , backPath , policyID , sanitizeCategoryName ] ,
6567 ) ;
6668
6769 return (
0 commit comments