@@ -4,45 +4,34 @@ import CategoryPicker from '@components/CategoryPicker';
44import CurrencySelectionList from '@components/CurrencySelectionList' ;
55import HeaderWithBackButton from '@components/HeaderWithBackButton' ;
66import ScreenWrapper from '@components/ScreenWrapper' ;
7+ import useDynamicBackPath from '@hooks/useDynamicBackPath' ;
78import useLocalize from '@hooks/useLocalize' ;
89import useThemeStyles from '@hooks/useThemeStyles' ;
910import Navigation from '@libs/Navigation/Navigation' ;
1011import type { PlatformStackScreenProps } from '@libs/Navigation/PlatformStackNavigation/types' ;
1112import type { DebugParamList } from '@libs/Navigation/types' ;
1213import { appendParam } from '@libs/Url' ;
1314import CONST from '@src/CONST' ;
15+ import { DYNAMIC_ROUTES } from '@src/ROUTES' ;
1416import type SCREENS from '@src/SCREENS' ;
1517import TRANSACTION_FORM_INPUT_IDS from '@src/types/form/DebugTransactionForm' ;
1618import ConstantPicker from './ConstantPicker' ;
1719import DebugTagPicker from './DebugTagPicker' ;
1820
19- type DebugDetailsConstantPickerPageProps = PlatformStackScreenProps < DebugParamList , typeof SCREENS . DEBUG . DETAILS_CONSTANT_PICKER_PAGE > ;
21+ type DynamicDebugDetailsConstantPickerPageProps = PlatformStackScreenProps < DebugParamList , typeof SCREENS . DEBUG . DYNAMIC_DETAILS_CONSTANT_PICKER_PAGE > ;
2022
21- function DebugDetailsConstantPickerPage ( {
23+ function DynamicDebugDetailsConstantPickerPage ( {
2224 route : {
23- params : { formType, fieldName, fieldValue, policyID = '' , backTo = '' } ,
25+ params : { formType, fieldName, fieldValue, policyID = '' } ,
2426 } ,
25- navigation,
26- } : DebugDetailsConstantPickerPageProps ) {
27+ } : DynamicDebugDetailsConstantPickerPageProps ) {
2728 const { translate} = useLocalize ( ) ;
2829 const styles = useThemeStyles ( ) ;
29- const onSubmit = useCallback (
30- ( item : { text ?: string ; keyForList ?: string } ) => {
31- const value = item . text === fieldValue ? '' : ( item . text ?? '' ) ;
32- // Check the navigation state and "backTo" parameter to decide navigation behavior
33- if ( navigation . getState ( ) . routes . length === 1 && ! backTo ) {
34- // If there is only one route and "backTo" is empty, go back in navigation
35- Navigation . goBack ( ) ;
36- } else if ( ! ! backTo && navigation . getState ( ) . routes . length === 1 ) {
37- // If "backTo" is not empty and there is only one route, go back to the specific route defined in "backTo" with a country parameter
38- Navigation . goBack ( appendParam ( backTo , fieldName , value ) ) ;
39- } else {
40- // Otherwise, navigate to the specific route defined in "backTo" with a country parameter
41- Navigation . navigate ( appendParam ( backTo , fieldName , value ) ) ;
42- }
43- } ,
44- [ backTo , fieldName , fieldValue , navigation ] ,
45- ) ;
30+ const backPath = useDynamicBackPath ( DYNAMIC_ROUTES . DETAILS_CONSTANT_PICKER . path ) ;
31+ const onSubmit = ( item : { text ?: string ; keyForList ?: string } ) => {
32+ const value = item . text === fieldValue ? '' : ( item . text ?? '' ) ;
33+ Navigation . goBack ( appendParam ( backPath , fieldName ?? '' , value ) , { compareParams : false } ) ;
34+ } ;
4635
4736 const renderPicker = useCallback ( ( ) => {
4837 if ( ( [ TRANSACTION_FORM_INPUT_IDS . CURRENCY , TRANSACTION_FORM_INPUT_IDS . MODIFIED_CURRENCY , TRANSACTION_FORM_INPUT_IDS . ORIGINAL_CURRENCY ] as string [ ] ) . includes ( fieldName ) ) {
@@ -91,10 +80,16 @@ function DebugDetailsConstantPickerPage({
9180
9281 return (
9382 < ScreenWrapper testID = "DebugDetailsConstantPickerPage" >
94- < HeaderWithBackButton title = { fieldName } />
83+ < HeaderWithBackButton
84+ title = { fieldName }
85+ shouldShowBackButton
86+ onBackButtonPress = { ( ) => {
87+ Navigation . goBack ( fieldValue ? appendParam ( backPath , fieldName , fieldValue ) : backPath , { compareParams : false } ) ;
88+ } }
89+ />
9590 < View style = { styles . containerWithSpaceBetween } > { renderPicker ( ) } </ View >
9691 </ ScreenWrapper >
9792 ) ;
9893}
9994
100- export default DebugDetailsConstantPickerPage ;
95+ export default DynamicDebugDetailsConstantPickerPage ;
0 commit comments