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 all 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
14 changes: 13 additions & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,19 @@ 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) => {
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
33 changes: 31 additions & 2 deletions 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, getSynchronizationErrorMessage} 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 @@ -61,6 +70,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 @@ -113,6 +128,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 Expand Up @@ -224,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 = [
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 @@ -17,7 +17,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 {isEmptyObject} from '@src/types/utils/EmptyObject';
import {
getImportCustomFieldsSettings,
Expand All @@ -43,6 +43,8 @@ function getAccountingIntegrationData(
translate: LocaleContextProps['translate'],
policy?: Policy,
key?: number,
integrationToDisconnect?: ConnectionName,
shouldDisconnectIntegrationBeforeConnecting?: boolean,
canUseNetSuiteUSATax?: boolean,
): AccountingIntegration | undefined {
const netsuiteConfig = policy?.connections?.netsuite?.options.config;
Expand Down Expand Up @@ -158,7 +160,9 @@ function getAccountingIntegrationData(
],
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),
},
pendingFields: {...netsuiteConfig?.pendingFields, ...policy?.connections?.netsuite?.config?.pendingFields},
errorFields: {...netsuiteConfig?.errorFields, ...policy?.connections?.netsuite?.config?.errorFields},
Expand Down Expand Up @@ -203,7 +207,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