diff --git a/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx index 3411f524b7d4..98d9f680b32f 100644 --- a/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx @@ -1,5 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import React from 'react'; +import React, { useMemo } from 'react'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; @@ -16,6 +16,9 @@ import withPolicy from '@pages/workspace/withPolicy'; import type {WithPolicyProps} from '@pages/workspace/withPolicy'; import CONST from '@src/CONST'; import type SCREENS from '@src/SCREENS'; +import ROUTES from '@src/ROUTES'; +import { findCurrentXeroOrganization, getXeroTenants } from '@libs/PolicyUtils'; +import Navigation from '@libs/Navigation/Navigation'; type XeroOrganizationConfigurationPageProps = WithPolicyProps & StackScreenProps; function XeroOrganizationConfigurationPage({ @@ -26,6 +29,8 @@ function XeroOrganizationConfigurationPage({ }: XeroOrganizationConfigurationPageProps) { const {translate} = useLocalize(); const styles = useThemeStyles(); + const tenants = useMemo(() => getXeroTenants(policy ?? undefined), [policy]); + const currentXeroOrganization = findCurrentXeroOrganization(tenants, policy?.connections?.xero?.config?.tenantID); const policyID = policy?.id ?? ''; @@ -42,6 +47,7 @@ function XeroOrganizationConfigurationPage({ } updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, 'tenantID', keyForList); + Navigation.goBack(ROUTES.WORKSPACE_ACCOUNTING.getRoute(policyID)); }; return ( @@ -62,7 +68,7 @@ function XeroOrganizationConfigurationPage({ ListItem={RadioListItem} onSelectRow={saveSelection} sections={[{data: sections}]} - initiallyFocusedOptionKey={organizationID} + initiallyFocusedOptionKey={currentXeroOrganization?.id} />