1- import React , { useCallback , useEffect } from 'react' ;
1+ import React , { useMemo } from 'react' ;
22import { View } from 'react-native' ;
33import type { OnyxEntry } from 'react-native-onyx' ;
44import Icon from '@components//Icon' ;
@@ -7,31 +7,28 @@ import FixedFooter from '@components/FixedFooter';
77import HeaderWithBackButton from '@components/HeaderWithBackButton' ;
88import ScreenWrapper from '@components/ScreenWrapper' ;
99import Text from '@components/Text' ;
10+ import useDynamicBackPath from '@hooks/useDynamicBackPath' ;
1011import { useMemoizedLazyIllustrations } from '@hooks/useLazyAsset' ;
1112import useLocalize from '@hooks/useLocalize' ;
1213import useNetwork from '@hooks/useNetwork' ;
1314import useOnyx from '@hooks/useOnyx' ;
1415import useThemeStyles from '@hooks/useThemeStyles' ;
15- import type { PlatformStackScreenProps } from '@libs/Navigation/PlatformStackNavigation/types' ;
1616import Navigation from '@navigation/Navigation' ;
17- import type { SettingsNavigatorParamList } from '@navigation/types' ;
1817import variables from '@styles/variables' ;
1918import { switchToOldDot } from '@userActions/ExitSurvey' ;
2019import { openOldDotLink } from '@userActions/Link' ;
2120import CONST from '@src/CONST' ;
2221import ONYXKEYS from '@src/ONYXKEYS' ;
23- import ROUTES from '@src/ROUTES' ;
24- import type SCREENS from '@src/SCREENS ' ;
22+ import type { Route } from '@src/ROUTES' ;
23+ import ROUTES , { DYNAMIC_ROUTES } from '@src/ROUTES ' ;
2524import type { ExitSurveyResponseForm } from '@src/types/form/ExitSurveyResponseForm' ;
2625import RESPONSE_INPUT_IDS from '@src/types/form/ExitSurveyResponseForm' ;
2726import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
2827import ExitSurveyOffline from './ExitSurveyOffline' ;
2928
30- type ExitSurveyConfirmPageProps = PlatformStackScreenProps < SettingsNavigatorParamList , typeof SCREENS . SETTINGS . EXIT_SURVEY . CONFIRM > ;
31-
3229const exitResponseSelector = ( value : OnyxEntry < ExitSurveyResponseForm > ) => value ?. [ RESPONSE_INPUT_IDS . RESPONSE ] ;
3330
34- function ExitSurveyConfirmPage ( { route , navigation } : ExitSurveyConfirmPageProps ) {
31+ function DynamicExitSurveyConfirmPage ( ) {
3532 const { translate} = useLocalize ( ) ;
3633 const { isOffline} = useNetwork ( ) ;
3734 const styles = useThemeStyles ( ) ;
@@ -43,34 +40,28 @@ function ExitSurveyConfirmPage({route, navigation}: ExitSurveyConfirmPageProps)
4340 const shouldShowQuickTips =
4441 isEmptyObject ( tryNewDot ) || tryNewDot ?. classicRedirect ?. dismissed === true || ( ! isEmptyObject ( tryNewDot ) && tryNewDot ?. classicRedirect ?. dismissed === undefined ) ;
4542
46- const getBackToParam = useCallback ( ( ) => {
47- if ( isOffline ) {
43+ const parentBackPath = useDynamicBackPath ( DYNAMIC_ROUTES . EXIT_SURVEY_CONFIRM . path ) ;
44+ const backPath : Route = useMemo ( ( ) => {
45+ if ( isOffline || ! exitSurveyResponse ) {
4846 return ROUTES . SETTINGS ;
4947 }
50- if ( exitSurveyResponse ) {
51- return ROUTES . SETTINGS_EXIT_SURVEY_REASON ;
52- }
53- return ROUTES . SETTINGS ;
54- } , [ isOffline , exitSurveyResponse ] ) ;
55- const { backTo} = route . params || { } ;
56- useEffect ( ( ) => {
57- const newBackTo = getBackToParam ( ) ;
58- if ( backTo === newBackTo ) {
59- return ;
48+
49+ const reasonPathSuffix = DYNAMIC_ROUTES . EXIT_SURVEY_REASON . path ;
50+ if ( parentBackPath . endsWith ( reasonPathSuffix ) ) {
51+ return parentBackPath ;
6052 }
61- navigation . setParams ( {
62- backTo : newBackTo ,
63- } ) ;
64- } , [ backTo , getBackToParam , navigation ] ) ;
53+
54+ return `${ parentBackPath . replace ( / \/ + $ / , '' ) } /${ reasonPathSuffix } ` as Route ;
55+ } , [ isOffline , exitSurveyResponse , parentBackPath ] ) ;
6556
6657 return (
6758 < ScreenWrapper
68- testID = "ExitSurveyConfirmPage "
59+ testID = "DynamicExitSurveyConfirmPage "
6960 shouldShowOfflineIndicatorInWideScreen
7061 >
7162 < HeaderWithBackButton
7263 title = { translate ( shouldShowQuickTips ? 'exitSurvey.goToExpensifyClassic' : 'exitSurvey.header' ) }
73- onBackButtonPress = { ( ) => Navigation . goBack ( backTo ) }
64+ onBackButtonPress = { ( ) => Navigation . goBack ( backPath ) }
7465 />
7566 < View style = { [ styles . flex1 , styles . justifyContentCenter , styles . alignItemsCenter , styles . mh5 ] } >
7667 { isOffline && < ExitSurveyOffline /> }
@@ -107,4 +98,4 @@ function ExitSurveyConfirmPage({route, navigation}: ExitSurveyConfirmPageProps)
10798 ) ;
10899}
109100
110- export default ExitSurveyConfirmPage ;
101+ export default DynamicExitSurveyConfirmPage ;
0 commit comments