Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Show warning modal on POLICY_ACCOUNTING after workspace upgrade #48419

Merged
merged 7 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter is optional, so we need to check when combine string to avoid integrationToDisconnect & shouldDisconnectIntegrationBeforeConnecting=undefined

Suggested change
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',
Expand Down
10 changes: 9 additions & 1 deletion src/pages/workspace/accounting/AccountingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
31 changes: 30 additions & 1 deletion src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useEffect, useMemo, useRef, useState} from 'react';
import {useFocusEffect, useRoute} from '@react-navigation/native';
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';
Expand Down Expand Up @@ -31,6 +32,7 @@ import {
getCurrentXeroOrganizationName,
getIntegrationLastSuccessfulDate,
getXeroTenants,
isControlPolicy,
settingsPendingAction,
} from '@libs/PolicyUtils';
import Navigation from '@navigation/Navigation';
Expand All @@ -40,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 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';
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();
Expand All @@ -60,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 isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy);

const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME);
Expand Down Expand Up @@ -116,6 +131,20 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
[shouldShowEnterCredentials, translate, isOffline, policyID, connectedIntegration, startIntegrationFlow],
);

useFocusEffect(
useCallback(() => {
if (!newConnectionName || !isControlPolicy(policy)) {
return;
}

startIntegrationFlow({
name: newConnectionName,
integrationToDisconnect,
shouldDisconnectIntegrationBeforeConnecting,
});
}, [newConnectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting, policy, startIntegrationFlow]),
);

useEffect(() => {
if (successfulDate) {
setDateTimeToRelative(getDatetimeToRelative(successfulDate));
Expand Down
12 changes: 9 additions & 3 deletions src/pages/workspace/accounting/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
Loading