@@ -9,6 +9,7 @@ import SelectionList from '@components/SelectionList';
99import RadioListItem from '@components/SelectionList/ListItem/RadioListItem' ;
1010import type { ListItem } from '@components/SelectionList/types' ;
1111import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' ;
12+ import useDynamicBackPath from '@hooks/useDynamicBackPath' ;
1213import useEnvironment from '@hooks/useEnvironment' ;
1314import useLocalize from '@hooks/useLocalize' ;
1415import useOnyx from '@hooks/useOnyx' ;
@@ -22,7 +23,7 @@ import {isControlPolicy, isPolicyAdmin} from '@libs/PolicyUtils';
2223import { hasViolations as hasViolationsReportUtils , isAllowedToApproveExpenseReport , isMoneyRequestReport , isMoneyRequestReportPendingDeletion } from '@libs/ReportUtils' ;
2324import CONST from '@src/CONST' ;
2425import ONYXKEYS from '@src/ONYXKEYS' ;
25- import ROUTES from '@src/ROUTES' ;
26+ import ROUTES , { DYNAMIC_ROUTES } from '@src/ROUTES' ;
2627import type SCREENS from '@src/SCREENS' ;
2728import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
2829import NotFoundPage from './ErrorPage/NotFoundPage' ;
@@ -36,9 +37,9 @@ const APPROVER_TYPE = {
3637
3738type ApproverType = ValueOf < typeof APPROVER_TYPE > ;
3839
39- type ReportChangeApproverPageProps = WithReportOrNotFoundProps & PlatformStackScreenProps < ReportChangeApproverParamList , typeof SCREENS . REPORT_CHANGE_APPROVER . ROOT > ;
40+ type DynamicReportChangeApproverPageProps = WithReportOrNotFoundProps & PlatformStackScreenProps < ReportChangeApproverParamList , typeof SCREENS . REPORT_CHANGE_APPROVER . DYNAMIC_ROOT > ;
4041
41- function ReportChangeApproverPage ( { report, policy, isLoadingReportData} : ReportChangeApproverPageProps ) {
42+ function DynamicReportChangeApproverPage ( { report, policy, isLoadingReportData} : DynamicReportChangeApproverPageProps ) {
4243 const reportID = report ?. reportID ;
4344 const { translate} = useLocalize ( ) ;
4445 const styles = useThemeStyles ( ) ;
@@ -53,6 +54,11 @@ function ReportChangeApproverPage({report, policy, isLoadingReportData}: ReportC
5354 const [ reportNextStep ] = useOnyx ( `${ ONYXKEYS . COLLECTION . NEXT_STEP } ${ reportID } ` ) ;
5455 const hasAutoAppliedRef = useRef ( false ) ;
5556 const hasNavigatedToAddApproverRef = useRef ( false ) ;
57+ const backPath = useDynamicBackPath ( DYNAMIC_ROUTES . REPORT_CHANGE_APPROVER . path ) ;
58+
59+ const goBack = ( ) => {
60+ Navigation . goBack ( backPath ) ;
61+ } ;
5662
5763 const changeApprover = useCallback ( ( ) => {
5864 if ( ! selectedApproverType ) {
@@ -140,13 +146,13 @@ function ReportChangeApproverPage({report, policy, isLoadingReportData}: ReportC
140146
141147 return (
142148 < ScreenWrapper
143- testID = "ReportChangeApproverPage "
149+ testID = "DynamicReportChangeApproverPage "
144150 includeSafeAreaPaddingBottom
145151 shouldEnableMaxHeight
146152 >
147153 < HeaderWithBackButton
148154 title = { translate ( 'iou.changeApprover.title' ) }
149- onBackButtonPress = { Navigation . goBack }
155+ onBackButtonPress = { goBack }
150156 />
151157 < SelectionList
152158 data = { approverTypes }
@@ -176,6 +182,6 @@ function ReportChangeApproverPage({report, policy, isLoadingReportData}: ReportC
176182 ) ;
177183}
178184
179- export default withReportOrNotFound ( ) ( ReportChangeApproverPage ) ;
185+ export default withReportOrNotFound ( ) ( DynamicReportChangeApproverPage ) ;
180186export { APPROVER_TYPE } ;
181187export type { ApproverType } ;
0 commit comments