Skip to content

Commit 4cdc54f

Browse files
committed
refactor(ui): shrink ConfigureSSO context to shared state only
Drop createConnection from the context surface and the createEnterpriseConnection prop on ConfigureSSOProvider. The provider now only owns shared wizard state (enterpriseConnection, provider, setProvider, initialStepId). Create logic moves into the Select Provider step in a follow-up commit.
1 parent 5ed546f commit 4cdc54f

2 files changed

Lines changed: 4 additions & 48 deletions

File tree

packages/ui/src/components/ConfigureSSO/ConfigureSSO.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ const AuthenticatedContent = withCoreUserGuard(() => {
6464
});
6565

6666
const ConfigureSSOCardContent = () => {
67-
const {
68-
data: enterpriseConnections,
69-
isLoading,
70-
createEnterpriseConnection,
71-
} = __internal_useUserEnterpriseConnections({ enabled: true });
67+
const { data: enterpriseConnections, isLoading } = __internal_useUserEnterpriseConnections({ enabled: true });
7268

7369
// Currently FAPI only supports one enterprise connection per user
7470
const enterpriseConnection = enterpriseConnections?.[0];
@@ -78,10 +74,7 @@ const ConfigureSSOCardContent = () => {
7874
}
7975

8076
return (
81-
<ConfigureSSOProvider
82-
enterpriseConnection={enterpriseConnection}
83-
createEnterpriseConnection={createEnterpriseConnection}
84-
>
77+
<ConfigureSSOProvider enterpriseConnection={enterpriseConnection}>
8578
<ConfigureSSOSteps />
8679
</ConfigureSSOProvider>
8780
);

packages/ui/src/components/ConfigureSSO/ConfigureSSOContext.tsx

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { useReverification, useSession, useUser } from '@clerk/shared/react';
2-
import type { CreateMeEnterpriseConnectionParams, EnterpriseConnectionResource } from '@clerk/shared/types';
1+
import type { EnterpriseConnectionResource } from '@clerk/shared/types';
32
import React, { type PropsWithChildren } from 'react';
43

54
import { deriveInitialStep } from './deriveInitialStep';
@@ -25,69 +24,33 @@ export interface ConfigureSSOData {
2524
* connection has been created.
2625
*/
2726
setProvider: (provider: ProviderType) => void;
28-
/**
29-
* Creates the enterprise connection for the supplied provider, the user's
30-
* primary email domain, and the session's active organization. No-ops when
31-
* an enterprise connection already exists so callers can safely re-trigger.
32-
*/
33-
createConnection: (provider: ProviderType) => Promise<void>;
3427
}
3528

3629
interface ConfigureSSOProviderProps {
3730
enterpriseConnection: EnterpriseConnectionResource | undefined;
38-
createEnterpriseConnection: (
39-
params: CreateMeEnterpriseConnectionParams,
40-
) => Promise<EnterpriseConnectionResource | undefined>;
4131
}
4232

4333
const ConfigureSSOContext = React.createContext<ConfigureSSOData | null>(null);
4434
ConfigureSSOContext.displayName = 'ConfigureSSOContext';
4535

4636
export const ConfigureSSOProvider = ({
4737
enterpriseConnection,
48-
createEnterpriseConnection,
4938
children,
5039
}: PropsWithChildren<ConfigureSSOProviderProps>): JSX.Element => {
51-
const { user } = useUser();
52-
const { session } = useSession();
5340
const [provider, setProvider] = React.useState<ProviderType | undefined>(
5441
enterpriseConnection?.provider as ProviderType,
5542
);
5643

5744
const initialStepId = deriveInitialStep(enterpriseConnection);
5845

59-
const createConnectionFetcher = React.useCallback(
60-
async (selectedProvider: ProviderType) => {
61-
if (enterpriseConnection) {
62-
return;
63-
}
64-
if (!user?.primaryEmailAddress) {
65-
throw new Error('Primary email required');
66-
}
67-
68-
const emailDomain = user.primaryEmailAddress.emailAddress.split('@')[1];
69-
const organizationId = session?.lastActiveOrganizationId ?? null;
70-
71-
await createEnterpriseConnection({
72-
provider: selectedProvider,
73-
name: emailDomain,
74-
organizationId,
75-
});
76-
},
77-
[enterpriseConnection, user, session, createEnterpriseConnection],
78-
);
79-
80-
const createConnection = useReverification(createConnectionFetcher);
81-
8246
const value = React.useMemo<ConfigureSSOData>(
8347
() => ({
8448
initialStepId,
8549
enterpriseConnection,
8650
provider,
8751
setProvider,
88-
createConnection,
8952
}),
90-
[initialStepId, enterpriseConnection, provider, createConnection],
53+
[initialStepId, enterpriseConnection, provider],
9154
);
9255

9356
return <ConfigureSSOContext.Provider value={value}>{children}</ConfigureSSOContext.Provider>;

0 commit comments

Comments
 (0)