@@ -7,6 +7,7 @@ import type {ListItem} from '@components/SelectionList/types';
77import SelectionScreen from '@components/SelectionScreen' ;
88import type { SelectorType } from '@components/SelectionScreen' ;
99import Text from '@components/Text' ;
10+ import useDynamicBackPath from '@hooks/useDynamicBackPath' ;
1011import useLocalize from '@hooks/useLocalize' ;
1112import useThemeStyles from '@hooks/useThemeStyles' ;
1213import { updateSageIntacctAccountingMethod } from '@libs/actions/connections/SageIntacct' ;
@@ -15,24 +16,24 @@ import {settingsPendingAction} from '@libs/PolicyUtils';
1516import type { WithPolicyConnectionsProps } from '@pages/workspace/withPolicyConnections' ;
1617import withPolicyConnections from '@pages/workspace/withPolicyConnections' ;
1718import CONST from '@src/CONST' ;
18- import type { TranslationPaths } from '@src/languages/types' ;
19- import ROUTES from '@src/ROUTES' ;
19+ import { DYNAMIC_ROUTES } from '@src/ROUTES' ;
2020
2121type MenuListItem = ListItem & {
2222 value : ValueOf < typeof COMMON_CONST . INTEGRATIONS . ACCOUNTING_METHOD > ;
2323} ;
2424
25- function SageIntacctAccountingMethodPage ( { policy} : WithPolicyConnectionsProps ) {
25+ function DynamicSageIntacctAccountingMethodPage ( { policy} : WithPolicyConnectionsProps ) {
2626 const { translate} = useLocalize ( ) ;
2727 const policyID = policy ?. id ;
2828 const styles = useThemeStyles ( ) ;
2929 const config = policy ?. connections ?. intacct ?. config ;
3030 const accountingMethod = config ?. export ?. accountingMethod ?? COMMON_CONST . INTEGRATIONS . ACCOUNTING_METHOD . CASH ;
31+ const backPath = useDynamicBackPath ( DYNAMIC_ROUTES . POLICY_ACCOUNTING_SAGE_INTACCT_ACCOUNTING_METHOD . path ) ;
3132
3233 const data : MenuListItem [ ] = Object . values ( COMMON_CONST . INTEGRATIONS . ACCOUNTING_METHOD ) . map ( ( accountingMethodType ) => ( {
3334 value : accountingMethodType ,
34- text : translate ( `workspace.sageIntacct.accountingMethods.values.${ accountingMethodType } ` as TranslationPaths ) ,
35- alternateText : translate ( `workspace.sageIntacct.accountingMethods.alternateText.${ accountingMethodType } ` as TranslationPaths ) ,
35+ text : translate ( `workspace.sageIntacct.accountingMethods.values.${ accountingMethodType } ` as const ) ,
36+ alternateText : translate ( `workspace.sageIntacct.accountingMethods.alternateText.${ accountingMethodType } ` as const ) ,
3637 keyForList : `${ accountingMethodType } ` ,
3738 isSelected : accountingMethod === accountingMethodType ,
3839 } ) ) ;
@@ -49,19 +50,23 @@ function SageIntacctAccountingMethodPage({policy}: WithPolicyConnectionsProps) {
4950 [ translate , styles . pb5 , styles . ph5 ] ,
5051 ) ;
5152
53+ const goBack = useCallback ( ( ) => {
54+ Navigation . goBack ( backPath ) ;
55+ } , [ backPath ] ) ;
56+
5257 const selectExpenseReportApprovalLevel = useCallback (
5358 ( row : MenuListItem ) => {
5459 if ( row . value !== accountingMethod ) {
5560 updateSageIntacctAccountingMethod ( policyID , row . value , accountingMethod ) ;
5661 }
57- Navigation . goBack ( ROUTES . POLICY_ACCOUNTING_SAGE_INTACCT_AUTO_SYNC . getRoute ( policyID ) ) ;
62+ goBack ( ) ;
5863 } ,
59- [ accountingMethod , policyID ] ,
64+ [ accountingMethod , policyID , goBack ] ,
6065 ) ;
6166
6267 return (
6368 < SelectionScreen
64- displayName = "SageIntacctAccountingMethodPage "
69+ displayName = "DynamicSageIntacctAccountingMethodPage "
6570 headerTitleAlreadyTranslated = { translate ( 'workspace.sageIntacct.accountingMethods.label' ) }
6671 headerContent = { headerContent }
6772 data = { data }
@@ -71,12 +76,12 @@ function SageIntacctAccountingMethodPage({policy}: WithPolicyConnectionsProps) {
7176 policyID = { policyID }
7277 accessVariants = { [ CONST . POLICY . ACCESS_VARIANTS . ADMIN ] }
7378 featureName = { CONST . POLICY . MORE_FEATURES . ARE_CONNECTIONS_ENABLED }
74- onBackButtonPress = { ( ) => Navigation . goBack ( ROUTES . POLICY_ACCOUNTING_SAGE_INTACCT_AUTO_SYNC . getRoute ( policyID ) ) }
79+ onBackButtonPress = { goBack }
7580 connectionName = { CONST . POLICY . CONNECTIONS . NAME . SAGE_INTACCT }
7681 pendingAction = { pendingAction }
7782 shouldBeBlocked = { ! config ?. autoSync ?. enabled }
7883 />
7984 ) ;
8085}
8186
82- export default withPolicyConnections ( SageIntacctAccountingMethodPage ) ;
87+ export default withPolicyConnections ( DynamicSageIntacctAccountingMethodPage ) ;
0 commit comments