Skip to content

Commit

Permalink
pass integrationToDisconnect and shouldDisconnectIntegrationBeforeCon…
Browse files Browse the repository at this point in the history
…necting to multi connection route
  • Loading branch information
s77rt committed Jan 21, 2025
1 parent 2de319c commit 580d6e4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
21 changes: 19 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,25 @@ const ROUTES = {
},
WORKSPACE_ACCOUNTING_MULTI_CONNECTION_SELECTOR: {
route: 'settings/workspaces/:policyID/accounting/:connection/connection-selector',
getRoute: (policyID: string, connection?: ValueOf<typeof CONST.POLICY.CONNECTIONS.ROUTE>) =>
`settings/workspaces/${policyID}/accounting/${connection as string}/connection-selector` as const,
getRoute: (
policyID: string,
connection: ValueOf<typeof CONST.POLICY.CONNECTIONS.ROUTE>,
integrationToDisconnect?: ConnectionName,
shouldDisconnectIntegrationBeforeConnecting?: boolean,
) => {
const searchParams = new URLSearchParams();

if (integrationToDisconnect) {
searchParams.append('integrationToDisconnect', integrationToDisconnect);
}
if (shouldDisconnectIntegrationBeforeConnecting !== undefined) {
searchParams.append('shouldDisconnectIntegrationBeforeConnecting', shouldDisconnectIntegrationBeforeConnecting.toString());
}

const queryParams = searchParams.size ? `?${searchParams}` : '';

Check failure on line 1047 in src/ROUTES.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Invalid type "URLSearchParams" of template literal expression

Check failure on line 1047 in src/ROUTES.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Invalid type "URLSearchParams" of template literal expression

return `settings/workspaces/${policyID}/accounting/${connection}/connection-selector${queryParams}` as const;
},
},
WORKSPACE_CATEGORIES: {
route: 'settings/workspaces/:policyID/categories',
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ type SettingsNavigatorParamList = {
[SCREENS.WORKSPACE.ACCOUNTING.MULTI_CONNECTION_SELECTOR]: {
policyID: string;
connection: ValueOf<typeof CONST.POLICY.CONNECTIONS.ROUTE>;
integrationToDisconnect?: ConnectionName;
shouldDisconnectIntegrationBeforeConnecting?: boolean;
};
[SCREENS.GET_ASSISTANCE]: {
backTo: Routes;
Expand Down
12 changes: 9 additions & 3 deletions src/pages/workspace/accounting/MultiConnectionSelectorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {getConnectionNameFromRouteParam} from '@libs/AccountingUtils';
import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
import CONST from '@src/CONST';
import {ConnectionName} from '@src/types/onyx/Policy';
import AccessOrNotFoundWrapper from '../AccessOrNotFoundWrapper';

Check warning on line 15 in src/pages/workspace/accounting/MultiConnectionSelectorPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Unexpected parent import '../AccessOrNotFoundWrapper'. Use '@pages/workspace/AccessOrNotFoundWrapper' instead

Check warning on line 15 in src/pages/workspace/accounting/MultiConnectionSelectorPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected parent import '../AccessOrNotFoundWrapper'. Use '@pages/workspace/AccessOrNotFoundWrapper' instead
import {AccountingContextProvider, useAccountingContext} from './AccountingContext';
import {MenuItemData} from './types';
Expand All @@ -20,13 +21,19 @@ type MultiConnectionSelectorPageProps = WithPolicyConnectionsProps & {
route: {
params: {
connection: ValueOf<typeof CONST.POLICY.CONNECTIONS.ROUTE>;
integrationToDisconnect?: ConnectionName;
shouldDisconnectIntegrationBeforeConnecting?: boolean;
};
};
};

function MultiConnectionSelectorPage({policy, route}: MultiConnectionSelectorPageProps) {
const policyID = policy?.id ?? '-1';

const multiConnectionName = getConnectionNameFromRouteParam(route.params.connection);
const integrationToDisconnect = route.params.integrationToDisconnect;
const shouldDisconnectIntegrationBeforeConnecting = route.params.shouldDisconnectIntegrationBeforeConnecting;

const {translate} = useLocalize();
const styles = useThemeStyles();

Expand All @@ -51,9 +58,8 @@ function MultiConnectionSelectorPage({policy, route}: MultiConnectionSelectorPag
onPress: () => {
startIntegrationFlow({
name: integration,
// s77rt
//integrationToDisconnect: connectedIntegration,
//shouldDisconnectIntegrationBeforeConnecting: true,
integrationToDisconnect,
shouldDisconnectIntegrationBeforeConnecting,
});
},
ref: (ref) => {
Expand Down
12 changes: 10 additions & 2 deletions src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,22 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
rightComponent: (
<Button
onPress={() => {
const shouldDisconnect = true;
if (shouldUseMultiConnectionSelector) {
Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_MULTI_CONNECTION_SELECTOR.getRoute(policyID, getRouteParamForConnection(designatedDisplayConnection)));
Navigation.navigate(
ROUTES.WORKSPACE_ACCOUNTING_MULTI_CONNECTION_SELECTOR.getRoute(
policyID,
getRouteParamForConnection(designatedDisplayConnection),
connectedIntegration,
shouldDisconnect,
),
);
return;
}
startIntegrationFlow({
name: integration,
integrationToDisconnect: connectedIntegration,
shouldDisconnectIntegrationBeforeConnecting: true,
shouldDisconnectIntegrationBeforeConnecting: shouldDisconnect,
});
}}
text={translate('workspace.accounting.setup')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function NetSuiteTokenInputPage({policy}: WithPolicyConnectionsProps) {

const handleBackButtonPress = () => {
if (screenIndex === 0) {
// s77rt use beta
Navigation.goBack(
ROUTES.WORKSPACE_ACCOUNTING_MULTI_CONNECTION_SELECTOR.getRoute(policyID, CONST.POLICY.CONNECTIONS.MULTI_CONNECTIONS_MAPPING[CONST.POLICY.CONNECTIONS.NAME.NETSUITE]),
);
Expand Down

0 comments on commit 580d6e4

Please sign in to comment.