Skip to content

Commit

Permalink
unify sage intacct and netsuite flows
Browse files Browse the repository at this point in the history
  • Loading branch information
war-in committed Jul 31, 2024
1 parent d2cdfaf commit d069182
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
import React, {useEffect, useState} from 'react';
import * as Expensicons from '@components/Icon/Expensicons';
import PopoverMenu from '@components/PopoverMenu';
import useLocalize from '@hooks/useLocalize';
import useWindowDimensions from '@hooks/useWindowDimensions';
import {getAdminPoliciesConnectedToNetSuite} from '@libs/actions/Policy/Policy';
import Navigation from '@libs/Navigation/Navigation';
import {useAccountingContext} from '@pages/workspace/accounting/AccountingContext';
import type {AnchorPosition} from '@styles/index';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {ConnectToNetSuiteFlowProps} from './types';
import type {Route} from '@src/ROUTES';
import type {AnchorPosition} from '@src/styles';
import * as Expensicons from './Icon/Expensicons';
import PopoverMenu from './PopoverMenu';

function ConnectToNetSuiteFlow({policyID}: ConnectToNetSuiteFlowProps) {
type ConnectToIntegrationWithReconnectFeatureFlowProps = {
hasPoliciesConnectedToIntegration: boolean;
integrationNewConnectionRoute: Route;
integrationExistingConnectionsRoute: Route;
};

function ConnectToIntegrationWithReconnectFeatureFlow({
hasPoliciesConnectedToIntegration,
integrationNewConnectionRoute,
integrationExistingConnectionsRoute,
}: ConnectToIntegrationWithReconnectFeatureFlowProps) {
const {translate} = useLocalize();

const hasPoliciesConnectedToNetSuite = !!getAdminPoliciesConnectedToNetSuite()?.length;
const {isSmallScreenWidth} = useWindowDimensions();
const [isReuseConnectionsPopoverOpen, setIsReuseConnectionsPopoverOpen] = useState(false);
const [reuseConnectionPopoverPosition, setReuseConnectionPopoverPosition] = useState<AnchorPosition>({horizontal: 0, vertical: 0});
const {integrationRefs} = useAccountingContext();

const threeDotsMenuContainerRef = integrationRefs?.current?.[CONST.POLICY.CONNECTIONS.NAME.NETSUITE];
const {activeIntegration, integrationRefs} = useAccountingContext();
const threeDotsMenuContainerRef = integrationRefs?.current?.[activeIntegration?.name ?? '-1'];

const connectionOptions = [
{
icon: Expensicons.LinkCopy,
text: translate('workspace.common.createNewConnection'),
onSelected: () => {
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID));
Navigation.navigate(integrationNewConnectionRoute);
setIsReuseConnectionsPopoverOpen(false);
},
},
{
icon: Expensicons.Copy,
text: translate('workspace.common.reuseExistingConnection'),
onSelected: () => {
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_EXISTING_CONNECTIONS.getRoute(policyID));
Navigation.navigate(integrationExistingConnectionsRoute);
setIsReuseConnectionsPopoverOpen(false);
},
},
];

useEffect(() => {
if (!hasPoliciesConnectedToNetSuite) {
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID));
if (!hasPoliciesConnectedToIntegration) {
Navigation.navigate(integrationNewConnectionRoute);
return;
}
setIsReuseConnectionsPopoverOpen(true);
Expand Down Expand Up @@ -83,4 +89,4 @@ function ConnectToNetSuiteFlow({policyID}: ConnectToNetSuiteFlowProps) {
}
}

export default ConnectToNetSuiteFlow;
export default ConnectToIntegrationWithReconnectFeatureFlow;
10 changes: 0 additions & 10 deletions src/components/ConnectToNetSuiteFlow/types.ts

This file was deleted.

88 changes: 0 additions & 88 deletions src/components/ConnectToSageIntacctFlow/index.tsx

This file was deleted.

16 changes: 10 additions & 6 deletions src/pages/workspace/accounting/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import ConnectToNetSuiteFlow from '@components/ConnectToNetSuiteFlow';
import ConnectToIntegrationWithReconnectFeatureFlow from '@components/ConnectToIntegrationWithReconnectFeatureFlow';
import ConnectToQuickbooksOnlineFlow from '@components/ConnectToQuickbooksOnlineFlow';
import ConnectToSageIntacctFlow from '@components/ConnectToSageIntacctFlow';
import ConnectToXeroFlow from '@components/ConnectToXeroFlow';
import * as Expensicons from '@components/Icon/Expensicons';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import Navigation from '@navigation/Navigation';
import {getTrackingCategories} from '@userActions/connections/ConnectToXero';
import {getAdminPoliciesConnectedToNetSuite, getAdminPoliciesConnectedToSageIntacct} from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {Policy} from '@src/types/onyx';
Expand Down Expand Up @@ -70,9 +70,11 @@ function getAccountingIntegrationData(
title: translate('workspace.accounting.netsuite'),
icon: Expensicons.NetSuiteSquare,
setupConnectionFlow: (
<ConnectToNetSuiteFlow
policyID={policyID}
<ConnectToIntegrationWithReconnectFeatureFlow
key={key}
hasPoliciesConnectedToIntegration={!!getAdminPoliciesConnectedToNetSuite().length}
integrationNewConnectionRoute={ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID)}
integrationExistingConnectionsRoute={ROUTES.POLICY_ACCOUNTING_NETSUITE_EXISTING_CONNECTIONS.getRoute(policyID)}
/>
),
onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_IMPORT.getRoute(policyID)),
Expand All @@ -86,9 +88,11 @@ function getAccountingIntegrationData(
title: translate('workspace.accounting.intacct'),
icon: Expensicons.IntacctSquare,
setupConnectionFlow: (
<ConnectToSageIntacctFlow
policyID={policyID}
<ConnectToIntegrationWithReconnectFeatureFlow
key={key}
hasPoliciesConnectedToIntegration={!!getAdminPoliciesConnectedToSageIntacct().length}
integrationNewConnectionRoute={ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREREQUISITES.getRoute(policyID)}
integrationExistingConnectionsRoute={ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXISTING_CONNECTIONS.getRoute(policyID)}
/>
),
onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_IMPORT.getRoute(policyID)),
Expand Down

0 comments on commit d069182

Please sign in to comment.