@@ -2,6 +2,7 @@ import React, {useCallback} from 'react';
22import type { FormInputErrors , FormOnyxValues } from '@components/Form/types' ;
33import HeaderWithBackButton from '@components/HeaderWithBackButton' ;
44import ScreenWrapper from '@components/ScreenWrapper' ;
5+ import useDynamicBackPath from '@hooks/useDynamicBackPath' ;
56import useLocalize from '@hooks/useLocalize' ;
67import usePolicyData from '@hooks/usePolicyData' ;
78import useThemeStyles from '@hooks/useThemeStyles' ;
@@ -12,21 +13,22 @@ import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
1213import { renamePolicyCategory } from '@userActions/Policy/Category' ;
1314import CONST from '@src/CONST' ;
1415import type ONYXKEYS from '@src/ONYXKEYS' ;
15- import ROUTES from '@src/ROUTES' ;
16+ import ROUTES , { DYNAMIC_ROUTES } from '@src/ROUTES' ;
1617import SCREENS from '@src/SCREENS' ;
1718import CategoryForm from './CategoryForm' ;
1819
1920type EditCategoryPageProps =
2021 | PlatformStackScreenProps < SettingsNavigatorParamList , typeof SCREENS . WORKSPACE . CATEGORY_EDIT >
21- | PlatformStackScreenProps < SettingsNavigatorParamList , typeof SCREENS . SETTINGS_CATEGORIES . SETTINGS_CATEGORY_EDIT > ;
22+ | PlatformStackScreenProps < SettingsNavigatorParamList , typeof SCREENS . SETTINGS_CATEGORIES . DYNAMIC_SETTINGS_CATEGORY_EDIT > ;
2223
2324function EditCategoryPage ( { route} : EditCategoryPageProps ) {
24- const { backTo , policyID, categoryName : currentCategoryName } = route . params ;
25+ const { policyID, categoryName : currentCategoryName } = route . params ;
2526 const policyData = usePolicyData ( policyID ) ;
2627 const { categories : policyCategories } = policyData ;
2728 const styles = useThemeStyles ( ) ;
2829 const { translate} = useLocalize ( ) ;
29- const isQuickSettingsFlow = route . name === SCREENS . SETTINGS_CATEGORIES . SETTINGS_CATEGORY_EDIT ;
30+ const isQuickSettingsFlow = route . name === SCREENS . SETTINGS_CATEGORIES . DYNAMIC_SETTINGS_CATEGORY_EDIT ;
31+ const backPath = useDynamicBackPath ( DYNAMIC_ROUTES . SETTINGS_CATEGORY_EDIT . path ) ;
3032
3133 const validate = useCallback (
3234 ( values : FormOnyxValues < typeof ONYXKEYS . FORMS . WORKSPACE_CATEGORY_FORM > ) => {
@@ -56,15 +58,10 @@ function EditCategoryPage({route}: EditCategoryPageProps) {
5658
5759 // Ensure Onyx.update is executed before navigation to prevent UI blinking issues, affecting the category name and rate.
5860 Navigation . setNavigationActionToMicrotaskQueue ( ( ) => {
59- Navigation . goBack (
60- isQuickSettingsFlow
61- ? ROUTES . SETTINGS_CATEGORY_SETTINGS . getRoute ( policyID , currentCategoryName , backTo )
62- : ROUTES . WORKSPACE_CATEGORY_SETTINGS . getRoute ( policyID , currentCategoryName ) ,
63- { compareParams : false } ,
64- ) ;
61+ Navigation . goBack ( isQuickSettingsFlow ? backPath : ROUTES . WORKSPACE_CATEGORY_SETTINGS . getRoute ( policyID , currentCategoryName ) , { compareParams : false } ) ;
6562 } ) ;
6663 } ,
67- [ isQuickSettingsFlow , currentCategoryName , policyData , policyID , backTo ] ,
64+ [ currentCategoryName , policyData , isQuickSettingsFlow , backPath , policyID ] ,
6865 ) ;
6966
7067 return (
@@ -82,11 +79,7 @@ function EditCategoryPage({route}: EditCategoryPageProps) {
8279 < HeaderWithBackButton
8380 title = { translate ( 'workspace.categories.editCategory' ) }
8481 onBackButtonPress = { ( ) =>
85- Navigation . goBack (
86- isQuickSettingsFlow
87- ? ROUTES . SETTINGS_CATEGORY_SETTINGS . getRoute ( route . params . policyID , route . params . categoryName , backTo )
88- : ROUTES . WORKSPACE_CATEGORY_SETTINGS . getRoute ( route . params . policyID , route . params . categoryName ) ,
89- )
82+ Navigation . goBack ( isQuickSettingsFlow ? backPath : ROUTES . WORKSPACE_CATEGORY_SETTINGS . getRoute ( route . params . policyID , route . params . categoryName ) )
9083 }
9184 />
9285 < CategoryForm
0 commit comments