From 6d5ca9150f2a9e72f478330d0c8ab6f6b322a2e4 Mon Sep 17 00:00:00 2001 From: I Nyoman Jyotisa Date: Tue, 3 Sep 2024 01:01:29 +0800 Subject: [PATCH 1/5] Fix: Show warning modal on POLICY_ACCOUNTING after workspace upgrade --- src/ROUTES.ts | 7 +++++- .../accounting/AccountingContext.tsx | 10 +++++++- .../accounting/PolicyAccountingPage.tsx | 24 +++++++++++++++++++ src/pages/workspace/accounting/utils.tsx | 12 +++++++--- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 231997e398bc..ae7f9d5256d5 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -703,7 +703,12 @@ const ROUTES = { }, POLICY_ACCOUNTING: { route: 'settings/workspaces/:policyID/accounting', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting` as const, + getRoute: (policyID: string, newConnectionName?: ConnectionName, integrationToDisconnect?: ConnectionName, shouldDisconnectIntegrationBeforeConnecting?: boolean) => + `settings/workspaces/${policyID}/accounting${ + newConnectionName + ? `?newConnectionName=${newConnectionName}&integrationToDisconnect=${integrationToDisconnect}&shouldDisconnectIntegrationBeforeConnecting=${shouldDisconnectIntegrationBeforeConnecting}` + : '' + }` as const, }, WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_ADVANCED: { route: 'settings/workspaces/:policyID/accounting/quickbooks-online/advanced', diff --git a/src/pages/workspace/accounting/AccountingContext.tsx b/src/pages/workspace/accounting/AccountingContext.tsx index ce5ac90fd2f1..a73287a10e33 100644 --- a/src/pages/workspace/accounting/AccountingContext.tsx +++ b/src/pages/workspace/accounting/AccountingContext.tsx @@ -58,7 +58,15 @@ function AccountingContextProvider({children, policy}: AccountingContextProvider const startIntegrationFlow = React.useCallback( (newActiveIntegration: ActiveIntegration) => { - const accountingIntegrationData = getAccountingIntegrationData(newActiveIntegration.name, policyID, translate); + const accountingIntegrationData = getAccountingIntegrationData( + newActiveIntegration.name, + policyID, + translate, + undefined, + undefined, + newActiveIntegration.integrationToDisconnect, + newActiveIntegration.shouldDisconnectIntegrationBeforeConnecting, + ); const workspaceUpgradeNavigationDetails = accountingIntegrationData?.workspaceUpgradeNavigationDetails; if (workspaceUpgradeNavigationDetails && !isControlPolicy(policy)) { Navigation.navigate( diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 107f64dd2dee..5a5d5925133f 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -1,3 +1,4 @@ +import {useRoute} from '@react-navigation/native'; import {differenceInMinutes, isValid, parseISO} from 'date-fns'; import React, {useEffect, useMemo, useRef, useState} from 'react'; import {ActivityIndicator, View} from 'react-native'; @@ -41,11 +42,18 @@ import type {AnchorPosition} from '@styles/index'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import {ConnectionName} from '@src/types/onyx/Policy'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import {AccountingContextProvider, useAccountingContext} from './AccountingContext'; import type {MenuItemData, PolicyAccountingPageProps} from './types'; import {getAccountingIntegrationData} from './utils'; +type RouteParams = { + newConnectionName?: ConnectionName; + integrationToDisconnect?: ConnectionName; + shouldDisconnectIntegrationBeforeConnecting?: boolean; +}; + function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy.id}`); const theme = useTheme(); @@ -61,6 +69,12 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { const {canUseWorkspaceFeeds} = usePermissions(); const {startIntegrationFlow, popoverAnchorRefs} = useAccountingContext(); + const route = useRoute(); + const params = route.params as RouteParams | undefined; + const newConnectionName = params?.newConnectionName; + const integrationToDisconnect = params?.integrationToDisconnect; + const shouldDisconnectIntegrationBeforeConnecting = params?.shouldDisconnectIntegrationBeforeConnecting; + const lastSyncProgressDate = parseISO(connectionSyncProgress?.timestamp ?? ''); const isSyncInProgress = !!connectionSyncProgress?.stageInProgress && @@ -122,6 +136,16 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { [shouldShowEnterCredentials, translate, isOffline, policyID, connectedIntegration, startIntegrationFlow], ); + useEffect(() => { + if (!!newConnectionName) { + startIntegrationFlow({ + name: newConnectionName, + integrationToDisconnect: integrationToDisconnect, + shouldDisconnectIntegrationBeforeConnecting: shouldDisconnectIntegrationBeforeConnecting, + }); + } + }, [newConnectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting, window.location.pathname]); + useEffect(() => { if (successfulDate) { setDateTimeToRelative(getDatetimeToRelative(successfulDate)); diff --git a/src/pages/workspace/accounting/utils.tsx b/src/pages/workspace/accounting/utils.tsx index 05ee41b85b9b..bd13d5fe2075 100644 --- a/src/pages/workspace/accounting/utils.tsx +++ b/src/pages/workspace/accounting/utils.tsx @@ -10,7 +10,7 @@ import {getTrackingCategories} from '@userActions/connections/Xero'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type {Policy} from '@src/types/onyx'; -import type {PolicyConnectionName} from '@src/types/onyx/Policy'; +import type {ConnectionName, PolicyConnectionName} from '@src/types/onyx/Policy'; import type {AccountingIntegration} from './types'; function getAccountingIntegrationData( @@ -19,6 +19,8 @@ function getAccountingIntegrationData( translate: LocaleContextProps['translate'], policy?: Policy, key?: number, + integrationToDisconnect?: ConnectionName, + shouldDisconnectIntegrationBeforeConnecting?: boolean, ): AccountingIntegration | undefined { switch (connectionName) { case CONST.POLICY.CONNECTIONS.NAME.QBO: @@ -83,7 +85,9 @@ function getAccountingIntegrationData( onAdvancedPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_ADVANCED.getRoute(policyID)), workspaceUpgradeNavigationDetails: { integrationAlias: CONST.UPGRADE_FEATURE_INTRO_MAPPING.netsuite.alias, - backToAfterWorkspaceUpgradeRoute: ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID), + backToAfterWorkspaceUpgradeRoute: !!integrationToDisconnect + ? ROUTES.POLICY_ACCOUNTING.getRoute(policyID, connectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting) + : ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID), }, }; case CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT: @@ -126,7 +130,9 @@ function getAccountingIntegrationData( ], workspaceUpgradeNavigationDetails: { integrationAlias: CONST.UPGRADE_FEATURE_INTRO_MAPPING.intacct.alias, - backToAfterWorkspaceUpgradeRoute: ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREREQUISITES.getRoute(policyID), + backToAfterWorkspaceUpgradeRoute: !!integrationToDisconnect + ? ROUTES.POLICY_ACCOUNTING.getRoute(policyID, connectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting) + : ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID), }, pendingFields: policy?.connections?.intacct?.config?.pendingFields, errorFields: policy?.connections?.intacct?.config?.errorFields, From e9fcb34c8d764389dab927f97cb4bb5fd21ce029 Mon Sep 17 00:00:00 2001 From: I Nyoman Jyotisa Date: Tue, 3 Sep 2024 11:25:41 +0800 Subject: [PATCH 2/5] lint fix and change useEffect to useFocusEffect --- .../accounting/PolicyAccountingPage.tsx | 27 ++++++++++--------- src/pages/workspace/accounting/utils.tsx | 4 +-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 5a5d5925133f..dfe09d0d3dfd 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -1,6 +1,6 @@ -import {useRoute} from '@react-navigation/native'; +import {useFocusEffect, useRoute} from '@react-navigation/native'; import {differenceInMinutes, isValid, parseISO} from 'date-fns'; -import React, {useEffect, useMemo, useRef, useState} from 'react'; +import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {ActivityIndicator, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; @@ -33,6 +33,7 @@ import { getCurrentXeroOrganizationName, getIntegrationLastSuccessfulDate, getXeroTenants, + isControlPolicy, settingsPendingAction, } from '@libs/PolicyUtils'; import Navigation from '@navigation/Navigation'; @@ -42,7 +43,7 @@ import type {AnchorPosition} from '@styles/index'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import {ConnectionName} from '@src/types/onyx/Policy'; +import type {ConnectionName} from '@src/types/onyx/Policy'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import {AccountingContextProvider, useAccountingContext} from './AccountingContext'; import type {MenuItemData, PolicyAccountingPageProps} from './types'; @@ -136,15 +137,17 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { [shouldShowEnterCredentials, translate, isOffline, policyID, connectedIntegration, startIntegrationFlow], ); - useEffect(() => { - if (!!newConnectionName) { - startIntegrationFlow({ - name: newConnectionName, - integrationToDisconnect: integrationToDisconnect, - shouldDisconnectIntegrationBeforeConnecting: shouldDisconnectIntegrationBeforeConnecting, - }); - } - }, [newConnectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting, window.location.pathname]); + useFocusEffect( + useCallback(() => { + if (newConnectionName && isControlPolicy(policy)) { + startIntegrationFlow({ + name: newConnectionName, + integrationToDisconnect, + shouldDisconnectIntegrationBeforeConnecting, + }); + } + }, [newConnectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting, isControlPolicy(policy), startIntegrationFlow]), + ); useEffect(() => { if (successfulDate) { diff --git a/src/pages/workspace/accounting/utils.tsx b/src/pages/workspace/accounting/utils.tsx index bd13d5fe2075..d7e67ab1e963 100644 --- a/src/pages/workspace/accounting/utils.tsx +++ b/src/pages/workspace/accounting/utils.tsx @@ -85,7 +85,7 @@ function getAccountingIntegrationData( onAdvancedPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_ADVANCED.getRoute(policyID)), workspaceUpgradeNavigationDetails: { integrationAlias: CONST.UPGRADE_FEATURE_INTRO_MAPPING.netsuite.alias, - backToAfterWorkspaceUpgradeRoute: !!integrationToDisconnect + backToAfterWorkspaceUpgradeRoute: integrationToDisconnect ? ROUTES.POLICY_ACCOUNTING.getRoute(policyID, connectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting) : ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID), }, @@ -130,7 +130,7 @@ function getAccountingIntegrationData( ], workspaceUpgradeNavigationDetails: { integrationAlias: CONST.UPGRADE_FEATURE_INTRO_MAPPING.intacct.alias, - backToAfterWorkspaceUpgradeRoute: !!integrationToDisconnect + backToAfterWorkspaceUpgradeRoute: integrationToDisconnect ? ROUTES.POLICY_ACCOUNTING.getRoute(policyID, connectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting) : ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID), }, From 1fe95cce36440b01c54df3ccce0317e153fa29b0 Mon Sep 17 00:00:00 2001 From: I Nyoman Jyotisa Date: Tue, 3 Sep 2024 11:51:51 +0800 Subject: [PATCH 3/5] lint fix --- .../accounting/PolicyAccountingPage.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 33beab4f437a..5a1abf431cfd 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -133,14 +133,16 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { useFocusEffect( useCallback(() => { - if (newConnectionName && isControlPolicy(policy)) { - startIntegrationFlow({ - name: newConnectionName, - integrationToDisconnect, - shouldDisconnectIntegrationBeforeConnecting, - }); + if (!newConnectionName || !isControlPolicy(policy)) { + return; } - }, [newConnectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting, isControlPolicy(policy), startIntegrationFlow]), + + startIntegrationFlow({ + name: newConnectionName, + integrationToDisconnect, + shouldDisconnectIntegrationBeforeConnecting, + }); + }, [newConnectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting, policy, startIntegrationFlow]), ); useEffect(() => { From d9930696b5a267f893744e593e1fedd11d6ec603 Mon Sep 17 00:00:00 2001 From: I Nyoman Jyotisa Date: Wed, 4 Sep 2024 17:17:08 +0800 Subject: [PATCH 4/5] minor fix --- src/ROUTES.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 601cd5917c86..b49baac2e7c1 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -704,12 +704,19 @@ const ROUTES = { }, POLICY_ACCOUNTING: { route: 'settings/workspaces/:policyID/accounting', - getRoute: (policyID: string, newConnectionName?: ConnectionName, integrationToDisconnect?: ConnectionName, shouldDisconnectIntegrationBeforeConnecting?: boolean) => - `settings/workspaces/${policyID}/accounting${ - newConnectionName - ? `?newConnectionName=${newConnectionName}&integrationToDisconnect=${integrationToDisconnect}&shouldDisconnectIntegrationBeforeConnecting=${shouldDisconnectIntegrationBeforeConnecting}` - : '' - }` as const, + getRoute: (policyID: string, newConnectionName?: ConnectionName, integrationToDisconnect?: ConnectionName, shouldDisconnectIntegrationBeforeConnecting?: boolean) => { + let queryParams = ''; + if (newConnectionName) { + queryParams += `?newConnectionName=${newConnectionName}`; + if (integrationToDisconnect) { + queryParams += `&integrationToDisconnect=${integrationToDisconnect}`; + } + if (shouldDisconnectIntegrationBeforeConnecting !== undefined) { + queryParams += `&shouldDisconnectIntegrationBeforeConnecting=${shouldDisconnectIntegrationBeforeConnecting}`; + } + } + return `settings/workspaces/${policyID}/accounting${queryParams}` as const; + }, }, WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_ADVANCED: { route: 'settings/workspaces/:policyID/accounting/quickbooks-online/advanced', From 3d5d0d2e704e852c94e51a327d8cd155082400bf Mon Sep 17 00:00:00 2001 From: I Nyoman Jyotisa Date: Thu, 5 Sep 2024 12:15:04 +0800 Subject: [PATCH 5/5] minor fix on integrationData --- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index c6ee182d388f..a8ca3fc2054f 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -253,7 +253,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { } const shouldShowSynchronizationError = !!synchronizationError; const shouldHideConfigurationOptions = isConnectionUnverified(policy, connectedIntegration); - const integrationData = getAccountingIntegrationData(connectedIntegration, policyID, translate, policy, undefined, canUseNetSuiteUSATax); + const integrationData = getAccountingIntegrationData(connectedIntegration, policyID, translate, policy, undefined, undefined, undefined, canUseNetSuiteUSATax); const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {}; const configurationOptions = [