diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 4ddca3c3b391..34e1d7671093 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -107,6 +107,18 @@ const DYNAMIC_ROUTES = { path: 'visibility', entryScreens: [SCREENS.REPORT_SETTINGS.ROOT], }, + POLICY_ACCOUNTING_XERO_EXPORT_BANK_ACCOUNT_SELECT: { + path: 'bank-account-select', + entryScreens: [SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT], + }, + POLICY_ACCOUNTING_XERO_BILL_STATUS_SELECTOR: { + path: 'purchase-bill-status-selector', + entryScreens: [SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT], + }, + POLICY_ACCOUNTING_XERO_ACCOUNTING_METHOD: { + path: 'accounting-method', + entryScreens: [SCREENS.WORKSPACE.ACCOUNTING.XERO_AUTO_SYNC], + }, ADDRESS_COUNTRY: { path: 'country', entryScreens: [ @@ -3358,12 +3370,6 @@ const ROUTES = { // eslint-disable-next-line no-restricted-syntax -- Legacy route generation getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`workspaces/${policyID}/accounting/xero/export/purchase-bill-date-select` as const, backTo), }, - POLICY_ACCOUNTING_XERO_EXPORT_BANK_ACCOUNT_SELECT: { - route: 'workspaces/:policyID/accounting/xero/export/bank-account-select', - - // eslint-disable-next-line no-restricted-syntax -- Legacy route generation - getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`workspaces/${policyID}/accounting/xero/export/bank-account-select` as const, backTo), - }, POLICY_ACCOUNTING_XERO_ADVANCED: { route: 'workspaces/:policyID/accounting/xero/advanced', getRoute: (policyID: string | undefined) => { @@ -3388,23 +3394,6 @@ const ROUTES = { return getUrlWithBackToParam(`workspaces/${policyID}/accounting/xero/advanced/autosync` as const, backTo); }, }, - POLICY_ACCOUNTING_XERO_ACCOUNTING_METHOD: { - route: 'workspaces/:policyID/accounting/xero/advanced/autosync/accounting-method', - getRoute: (policyID: string | undefined, backTo?: string) => { - if (!policyID) { - Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_XERO_ACCOUNTING_METHOD route'); - } - - // eslint-disable-next-line no-restricted-syntax -- Legacy route generation - return getUrlWithBackToParam(`workspaces/${policyID}/accounting/xero/advanced/autosync/accounting-method` as const, backTo); - }, - }, - POLICY_ACCOUNTING_XERO_BILL_STATUS_SELECTOR: { - route: 'workspaces/:policyID/accounting/xero/export/purchase-bill-status-selector', - - // eslint-disable-next-line no-restricted-syntax -- Legacy route generation - getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`workspaces/${policyID}/accounting/xero/export/purchase-bill-status-selector` as const, backTo), - }, POLICY_ACCOUNTING_XERO_INVOICE_SELECTOR: { route: 'workspaces/:policyID/accounting/xero/advanced/invoice-account-selector', getRoute: (policyID: string | undefined) => { diff --git a/src/SCREENS.ts b/src/SCREENS.ts index a16d81bffb02..786995fc8973 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -567,12 +567,12 @@ const SCREENS = { XERO_EXPORT_PURCHASE_BILL_DATE_SELECT: 'Policy_Accounting_Xero_Export_Purchase_Bill_Date_Select', XERO_ADVANCED: 'Policy_Accounting_Xero_Advanced', XERO_AUTO_SYNC: 'Policy_Accounting_Xero_Auto_Sync', - XERO_ACCOUNTING_METHOD: 'Policy_Accounting_Xero_Accounting_Method', - XERO_BILL_STATUS_SELECTOR: 'Policy_Accounting_Xero_Export_Bill_Status_Selector', + DYNAMIC_XERO_ACCOUNTING_METHOD: 'Dynamic_Policy_Accounting_Xero_Accounting_Method', + DYNAMIC_XERO_BILL_STATUS_SELECTOR: 'Dynamic_Policy_Accounting_Xero_Export_Bill_Status_Selector', XERO_INVOICE_ACCOUNT_SELECTOR: 'Policy_Accounting_Xero_Invoice_Account_Selector', XERO_EXPORT_PREFERRED_EXPORTER_SELECT: 'Workspace_Accounting_Xero_Export_Preferred_Exporter_Select', XERO_BILL_PAYMENT_ACCOUNT_SELECTOR: 'Policy_Accounting_Xero_Bill_Payment_Account_Selector', - XERO_EXPORT_BANK_ACCOUNT_SELECT: 'Policy_Accounting_Xero_Export_Bank_Account_Select', + DYNAMIC_XERO_EXPORT_BANK_ACCOUNT_SELECT: 'Dynamic_Policy_Accounting_Xero_Export_Bank_Account_Select', NETSUITE_IMPORT_MAPPING: 'Policy_Accounting_NetSuite_Import_Mapping', NETSUITE_IMPORT_CUSTOM_FIELD: 'Policy_Accounting_NetSuite_Import_Custom_Field', NETSUITE_IMPORT_CUSTOM_FIELD_VIEW: 'Policy_Accounting_NetSuite_Import_Custom_Field_View', diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index f18ce8a6f3f3..911db019c460 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -667,13 +667,14 @@ const SettingsModalStackNavigator = createModalStackNavigator require('../../../../pages/workspace/accounting/xero/export/XeroExportConfigurationPage').default, [SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT_PURCHASE_BILL_DATE_SELECT]: () => require('../../../../pages/workspace/accounting/xero/export/XeroPurchaseBillDateSelectPage').default, - [SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT_BANK_ACCOUNT_SELECT]: () => - require('../../../../pages/workspace/accounting/xero/export/XeroBankAccountSelectPage').default, + [SCREENS.WORKSPACE.ACCOUNTING.DYNAMIC_XERO_EXPORT_BANK_ACCOUNT_SELECT]: () => + require('../../../../pages/workspace/accounting/xero/export/DynamicXeroBankAccountSelectPage').default, [SCREENS.WORKSPACE.ACCOUNTING.XERO_ADVANCED]: () => require('../../../../pages/workspace/accounting/xero/advanced/XeroAdvancedPage').default, [SCREENS.WORKSPACE.ACCOUNTING.XERO_AUTO_SYNC]: () => require('../../../../pages/workspace/accounting/xero/advanced/XeroAutoSyncPage').default, - [SCREENS.WORKSPACE.ACCOUNTING.XERO_ACCOUNTING_METHOD]: () => require('../../../../pages/workspace/accounting/xero/advanced/XeroAccountingMethodPage').default, - [SCREENS.WORKSPACE.ACCOUNTING.XERO_BILL_STATUS_SELECTOR]: () => - require('../../../../pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage').default, + [SCREENS.WORKSPACE.ACCOUNTING.DYNAMIC_XERO_ACCOUNTING_METHOD]: () => + require('../../../../pages/workspace/accounting/xero/advanced/DynamicXeroAccountingMethodPage').default, + [SCREENS.WORKSPACE.ACCOUNTING.DYNAMIC_XERO_BILL_STATUS_SELECTOR]: () => + require('../../../../pages/workspace/accounting/xero/export/DynamicXeroPurchaseBillStatusSelectorPage').default, [SCREENS.WORKSPACE.ACCOUNTING.XERO_INVOICE_ACCOUNT_SELECTOR]: () => require('../../../../pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage').default, [SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT_PREFERRED_EXPORTER_SELECT]: () => diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts b/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts index 0e292fed8bfe..007e6fb7b8cc 100755 --- a/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts @@ -107,12 +107,12 @@ const WORKSPACE_TO_RHP: Partial['config'] = { [SCREENS.WORKSPACE.ACCOUNTING.XERO_TAXES]: {path: ROUTES.POLICY_ACCOUNTING_XERO_TAXES.route}, [SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT]: {path: ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.route}, [SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT_PURCHASE_BILL_DATE_SELECT]: {path: ROUTES.POLICY_ACCOUNTING_XERO_EXPORT_PURCHASE_BILL_DATE_SELECT.route}, - [SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT_BANK_ACCOUNT_SELECT]: {path: ROUTES.POLICY_ACCOUNTING_XERO_EXPORT_BANK_ACCOUNT_SELECT.route}, + [SCREENS.WORKSPACE.ACCOUNTING.DYNAMIC_XERO_EXPORT_BANK_ACCOUNT_SELECT]: DYNAMIC_ROUTES.POLICY_ACCOUNTING_XERO_EXPORT_BANK_ACCOUNT_SELECT.path, [SCREENS.WORKSPACE.ACCOUNTING.XERO_ADVANCED]: {path: ROUTES.POLICY_ACCOUNTING_XERO_ADVANCED.route}, [SCREENS.WORKSPACE.ACCOUNTING.CLAIM_OFFER]: {path: ROUTES.POLICY_ACCOUNTING_CLAIM_OFFER.route}, [SCREENS.WORKSPACE.ACCOUNTING.XERO_AUTO_SYNC]: {path: ROUTES.POLICY_ACCOUNTING_XERO_AUTO_SYNC.route}, - [SCREENS.WORKSPACE.ACCOUNTING.XERO_ACCOUNTING_METHOD]: {path: ROUTES.POLICY_ACCOUNTING_XERO_ACCOUNTING_METHOD.route}, - [SCREENS.WORKSPACE.ACCOUNTING.XERO_BILL_STATUS_SELECTOR]: {path: ROUTES.POLICY_ACCOUNTING_XERO_BILL_STATUS_SELECTOR.route}, + [SCREENS.WORKSPACE.ACCOUNTING.DYNAMIC_XERO_ACCOUNTING_METHOD]: DYNAMIC_ROUTES.POLICY_ACCOUNTING_XERO_ACCOUNTING_METHOD.path, + [SCREENS.WORKSPACE.ACCOUNTING.DYNAMIC_XERO_BILL_STATUS_SELECTOR]: DYNAMIC_ROUTES.POLICY_ACCOUNTING_XERO_BILL_STATUS_SELECTOR.path, [SCREENS.WORKSPACE.ACCOUNTING.XERO_INVOICE_ACCOUNT_SELECTOR]: {path: ROUTES.POLICY_ACCOUNTING_XERO_INVOICE_SELECTOR.route}, [SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT_PREFERRED_EXPORTER_SELECT]: {path: ROUTES.POLICY_ACCOUNTING_XERO_PREFERRED_EXPORTER_SELECT.route}, [SCREENS.WORKSPACE.ACCOUNTING.XERO_BILL_PAYMENT_ACCOUNT_SELECTOR]: {path: ROUTES.POLICY_ACCOUNTING_XERO_BILL_PAYMENT_ACCOUNT_SELECTOR.route}, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 05abef226318..aede2c0120b8 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -901,15 +901,14 @@ type SettingsNavigatorParamList = { policyID: string; integration: string; }; - [SCREENS.WORKSPACE.ACCOUNTING.XERO_BILL_STATUS_SELECTOR]: { + [SCREENS.WORKSPACE.ACCOUNTING.DYNAMIC_XERO_BILL_STATUS_SELECTOR]: { policyID: string; - // eslint-disable-next-line no-restricted-syntax -- `backTo` usages in this file are legacy. Do not add new `backTo` params to screens. See contributingGuides/NAVIGATION.md - backTo?: Routes; }; - [SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT_BANK_ACCOUNT_SELECT]: { + [SCREENS.WORKSPACE.ACCOUNTING.DYNAMIC_XERO_ACCOUNTING_METHOD]: { + policyID: string; + }; + [SCREENS.WORKSPACE.ACCOUNTING.DYNAMIC_XERO_EXPORT_BANK_ACCOUNT_SELECT]: { policyID: string; - // eslint-disable-next-line no-restricted-syntax -- `backTo` usages in this file are legacy. Do not add new `backTo` params to screens. See contributingGuides/NAVIGATION.md - backTo?: Routes; }; [SCREENS.WORKSPACE.ACCOUNTING.XERO_INVOICE_ACCOUNT_SELECTOR]: { policyID: string; diff --git a/src/pages/workspace/accounting/xero/advanced/XeroAccountingMethodPage.tsx b/src/pages/workspace/accounting/xero/advanced/DynamicXeroAccountingMethodPage.tsx similarity index 85% rename from src/pages/workspace/accounting/xero/advanced/XeroAccountingMethodPage.tsx rename to src/pages/workspace/accounting/xero/advanced/DynamicXeroAccountingMethodPage.tsx index 4d9d131e85f2..7f805f681732 100644 --- a/src/pages/workspace/accounting/xero/advanced/XeroAccountingMethodPage.tsx +++ b/src/pages/workspace/accounting/xero/advanced/DynamicXeroAccountingMethodPage.tsx @@ -7,6 +7,7 @@ import type {ListItem} from '@components/SelectionList/types'; import SelectionScreen from '@components/SelectionScreen'; import type {SelectorType} from '@components/SelectionScreen'; import Text from '@components/Text'; +import useDynamicBackPath from '@hooks/useDynamicBackPath'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {updateXeroAccountingMethod} from '@libs/actions/connections/Xero'; @@ -16,21 +17,16 @@ import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnec import withPolicyConnections from '@pages/workspace/withPolicyConnections'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; -import type {Route} from '@src/ROUTES'; -import ROUTES from '@src/ROUTES'; +import {DYNAMIC_ROUTES} from '@src/ROUTES'; type MenuListItem = ListItem & { value: ValueOf; }; -type XeroAccountingMethodPageRouteParams = { - backTo?: Route; -}; - -function XeroAccountingMethodPage({policy, route}: WithPolicyConnectionsProps) { +function DynamicXeroAccountingMethodPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const policyID = policy?.id; - const {backTo} = route.params as XeroAccountingMethodPageRouteParams; + const backPath = useDynamicBackPath(DYNAMIC_ROUTES.POLICY_ACCOUNTING_XERO_ACCOUNTING_METHOD.path); const styles = useThemeStyles(); const config = policy?.connections?.xero?.config; const accountingMethod = config?.export?.accountingMethod ?? COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH; @@ -59,9 +55,9 @@ function XeroAccountingMethodPage({policy, route}: WithPolicyConnectionsProps) { if (row.value !== accountingMethod) { updateXeroAccountingMethod(policyID, row.value, accountingMethod); } - Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_AUTO_SYNC.getRoute(policyID, backTo)); + Navigation.goBack(backPath); }, - [accountingMethod, policyID, backTo], + [accountingMethod, policyID, backPath], ); return ( @@ -76,7 +72,7 @@ function XeroAccountingMethodPage({policy, route}: WithPolicyConnectionsProps) { policyID={policyID} accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} - onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_AUTO_SYNC.getRoute(policyID, backTo))} + onBackButtonPress={() => Navigation.goBack(backPath)} connectionName={CONST.POLICY.CONNECTIONS.NAME.XERO} pendingAction={pendingAction} shouldBeBlocked={!config?.autoSync?.enabled} @@ -84,4 +80,4 @@ function XeroAccountingMethodPage({policy, route}: WithPolicyConnectionsProps) { ); } -export default withPolicyConnections(XeroAccountingMethodPage); +export default withPolicyConnections(DynamicXeroAccountingMethodPage); diff --git a/src/pages/workspace/accounting/xero/advanced/XeroAutoSyncPage.tsx b/src/pages/workspace/accounting/xero/advanced/XeroAutoSyncPage.tsx index 0c624e22bf30..8d67c6f20054 100644 --- a/src/pages/workspace/accounting/xero/advanced/XeroAutoSyncPage.tsx +++ b/src/pages/workspace/accounting/xero/advanced/XeroAutoSyncPage.tsx @@ -8,6 +8,7 @@ import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {updateXeroAutoSync} from '@libs/actions/connections/Xero'; import {getLatestErrorField} from '@libs/ErrorUtils'; +import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute'; import Navigation from '@libs/Navigation/Navigation'; import {settingsPendingAction} from '@libs/PolicyUtils'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; @@ -18,7 +19,7 @@ import {clearXeroErrorField} from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import type {Route} from '@src/ROUTES'; -import ROUTES from '@src/ROUTES'; +import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES'; type XeroAutoSyncPageRouteParams = { backTo?: Route; @@ -85,7 +86,7 @@ function XeroAutoSyncPage({policy, route}: WithPolicyConnectionsProps) { } description={translate('workspace.xero.accountingMethods.label')} shouldShowRightIcon - onPress={() => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_ACCOUNTING_METHOD.getRoute(policyID, backTo))} + onPress={() => Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.POLICY_ACCOUNTING_XERO_ACCOUNTING_METHOD.path))} /> )} diff --git a/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx b/src/pages/workspace/accounting/xero/export/DynamicXeroBankAccountSelectPage.tsx similarity index 85% rename from src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx rename to src/pages/workspace/accounting/xero/export/DynamicXeroBankAccountSelectPage.tsx index 031e89d6a43d..abf548f90114 100644 --- a/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx +++ b/src/pages/workspace/accounting/xero/export/DynamicXeroBankAccountSelectPage.tsx @@ -1,4 +1,3 @@ -import {useRoute} from '@react-navigation/native'; import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; import BlockingView from '@components/BlockingViews/BlockingView'; @@ -6,24 +5,22 @@ import RadioListItem from '@components/SelectionList/ListItem/RadioListItem'; import type {SelectorType} from '@components/SelectionScreen'; import SelectionScreen from '@components/SelectionScreen'; import Text from '@components/Text'; +import useDynamicBackPath from '@hooks/useDynamicBackPath'; import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {clearXeroErrorField} from '@libs/actions/Policy/Policy'; import {getLatestErrorField} from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; -import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; -import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; import {getXeroBankAccounts, settingsPendingAction} from '@libs/PolicyUtils'; import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; import variables from '@styles/variables'; import {updateXeroExportNonReimbursableAccount} from '@userActions/connections/Xero'; import CONST from '@src/CONST'; -import ROUTES from '@src/ROUTES'; -import type SCREENS from '@src/SCREENS'; +import {DYNAMIC_ROUTES} from '@src/ROUTES'; -function XeroBankAccountSelectPage({policy}: WithPolicyConnectionsProps) { +function DynamicXeroBankAccountSelectPage({policy}: WithPolicyConnectionsProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const illustrations = useMemoizedLazyIllustrations(['Telescope']); @@ -36,12 +33,11 @@ function XeroBankAccountSelectPage({policy}: WithPolicyConnectionsProps) { () => getXeroBankAccounts(policy ?? undefined, config?.export?.nonReimbursableAccount || bankAccounts?.[0]?.id), [config?.export?.nonReimbursableAccount, policy, bankAccounts], ); - const route = useRoute>(); - const backTo = route.params?.backTo; + const backPath = useDynamicBackPath(DYNAMIC_ROUTES.POLICY_ACCOUNTING_XERO_EXPORT_BANK_ACCOUNT_SELECT.path); const goBack = useCallback(() => { - Navigation.goBack(backTo ?? (policyID && ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID))); - }, [policyID, backTo]); + Navigation.goBack(backPath); + }, [backPath]); const listHeaderComponent = useMemo( () => ( @@ -101,4 +97,4 @@ function XeroBankAccountSelectPage({policy}: WithPolicyConnectionsProps) { ); } -export default withPolicyConnections(XeroBankAccountSelectPage); +export default withPolicyConnections(DynamicXeroBankAccountSelectPage); diff --git a/src/pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage.tsx b/src/pages/workspace/accounting/xero/export/DynamicXeroPurchaseBillStatusSelectorPage.tsx similarity index 82% rename from src/pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage.tsx rename to src/pages/workspace/accounting/xero/export/DynamicXeroPurchaseBillStatusSelectorPage.tsx index f3d9547be48e..3fca09bbc81a 100644 --- a/src/pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage.tsx +++ b/src/pages/workspace/accounting/xero/export/DynamicXeroPurchaseBillStatusSelectorPage.tsx @@ -1,4 +1,3 @@ -import {useRoute} from '@react-navigation/native'; import isEmpty from 'lodash/isEmpty'; import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; @@ -8,37 +7,34 @@ import type {ListItem} from '@components/SelectionList/types'; import SelectionScreen from '@components/SelectionScreen'; import type {SelectorType} from '@components/SelectionScreen'; import Text from '@components/Text'; +import useDynamicBackPath from '@hooks/useDynamicBackPath'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {clearXeroErrorField} from '@libs/actions/Policy/Policy'; import {getLatestErrorField} from '@libs/ErrorUtils'; -import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; -import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; import {settingsPendingAction} from '@libs/PolicyUtils'; import Navigation from '@navigation/Navigation'; import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; import {updateXeroExportBillStatus} from '@userActions/connections/Xero'; import CONST from '@src/CONST'; -import ROUTES from '@src/ROUTES'; -import type SCREENS from '@src/SCREENS'; +import {DYNAMIC_ROUTES} from '@src/ROUTES'; type MenuListItem = ListItem & { value: ValueOf; }; -function XeroPurchaseBillStatusSelectorPage({policy}: WithPolicyConnectionsProps) { +function DynamicXeroPurchaseBillStatusSelectorPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const policyID = policy?.id; const styles = useThemeStyles(); const {config} = policy?.connections?.xero ?? {}; const invoiceStatus = config?.export?.billStatus?.purchase; - const route = useRoute>(); - const backTo = route.params?.backTo; + const backPath = useDynamicBackPath(DYNAMIC_ROUTES.POLICY_ACCOUNTING_XERO_BILL_STATUS_SELECTOR.path); const goBack = useCallback(() => { - Navigation.goBack(backTo ?? (policyID && ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID))); - }, [policyID, backTo]); + Navigation.goBack(backPath); + }, [backPath]); const data: MenuListItem[] = Object.values(CONST.XERO_CONFIG.INVOICE_STATUS).map((status) => ({ value: status, @@ -98,4 +94,4 @@ function XeroPurchaseBillStatusSelectorPage({policy}: WithPolicyConnectionsProps ); } -export default withPolicyConnections(XeroPurchaseBillStatusSelectorPage); +export default withPolicyConnections(DynamicXeroPurchaseBillStatusSelectorPage); diff --git a/src/pages/workspace/accounting/xero/export/XeroExportConfigurationPage.tsx b/src/pages/workspace/accounting/xero/export/XeroExportConfigurationPage.tsx index f5df2c155496..1dac10be101d 100644 --- a/src/pages/workspace/accounting/xero/export/XeroExportConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/export/XeroExportConfigurationPage.tsx @@ -5,6 +5,7 @@ import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute'; import Navigation from '@libs/Navigation/Navigation'; import {areSettingsInErrorFields, getCurrentXeroOrganizationName, settingsPendingAction} from '@libs/PolicyUtils'; import goBackFromExportConnection from '@navigation/helpers/goBackFromExportConnection'; @@ -13,7 +14,7 @@ import type {SettingsNavigatorParamList} from '@navigation/types'; import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; import CONST from '@src/CONST'; -import ROUTES from '@src/ROUTES'; +import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; function XeroExportConfigurationPage({policy}: WithPolicyConnectionsProps) { @@ -65,7 +66,7 @@ function XeroExportConfigurationPage({policy}: WithPolicyConnectionsProps) { }, { description: translate('workspace.xero.advancedConfig.purchaseBillStatusTitle'), - onPress: !policyID ? undefined : () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_BILL_STATUS_SELECTOR.getRoute(policyID, Navigation.getActiveRoute())), + onPress: !policyID ? undefined : () => Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.POLICY_ACCOUNTING_XERO_BILL_STATUS_SELECTOR.path)), title: exportConfiguration?.billStatus?.purchase ? translate(`workspace.xero.invoiceStatus.values.${exportConfiguration.billStatus.purchase}`) : undefined, subscribedSettings: [CONST.XERO_CONFIG.BILL_STATUS], }, @@ -85,7 +86,7 @@ function XeroExportConfigurationPage({policy}: WithPolicyConnectionsProps) { }, { description: translate('workspace.xero.xeroBankAccount'), - onPress: () => (!policyID ? undefined : Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT_BANK_ACCOUNT_SELECT.getRoute(policyID, Navigation.getActiveRoute()))), + onPress: () => (!policyID ? undefined : Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.POLICY_ACCOUNTING_XERO_EXPORT_BANK_ACCOUNT_SELECT.path))), title: selectedBankAccountName, subscribedSettings: [CONST.XERO_CONFIG.NON_REIMBURSABLE_ACCOUNT], },