Skip to content

Commit e830214

Browse files
committed
refactor(ui): single-source the enterprise connection query in ConfigureSSO
- Hoist the __internal_useUserEnterpriseConnections call to ConfigureSSOCardContent so the provider receives the data and the create mutation as props instead of calling the hook a second time - Drop the unused isLoading from the provider surface; the load gate upstream already consumes it - Rename ConfigureSSOFlowProvider → ConfigureSSOProvider, useConfigureSSOFlow → useConfigureSSO, drop the leftover "Flow" suffix
1 parent 70b5e4b commit e830214

4 files changed

Lines changed: 29 additions & 32 deletions

File tree

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ProfileCard } from '@/elements/ProfileCard';
1010
import { ExclamationTriangle } from '@/icons';
1111
import { Route, Switch } from '@/router';
1212

13-
import { ConfigureSSOFlowProvider, useConfigureSSOFlow } from './ConfigureSSOContext';
13+
import { ConfigureSSOProvider, useConfigureSSO } from './ConfigureSSOContext';
1414
import { ConfigureSSOHeader } from './ConfigureSSOHeader';
1515
import { ConfigureSSONavbar } from './ConfigureSSONavbar';
1616
import { ConfigureSSOSkeleton } from './ConfigureSSOSkeleton';
@@ -64,8 +64,11 @@ const AuthenticatedContent = withCoreUserGuard(() => {
6464
});
6565

6666
const ConfigureSSOCardContent = () => {
67-
const { data: enterpriseConnections, isLoading } = __internal_useUserEnterpriseConnections({ enabled: true });
68-
67+
const {
68+
data: enterpriseConnections,
69+
isLoading,
70+
createEnterpriseConnection,
71+
} = __internal_useUserEnterpriseConnections({ enabled: true });
6972
// Currently FAPI only supports one enterprise connection per user
7073
const enterpriseConnection = enterpriseConnections?.[0];
7174

@@ -74,17 +77,17 @@ const ConfigureSSOCardContent = () => {
7477
}
7578

7679
return (
77-
<ConfigureSSOFlowProvider
80+
<ConfigureSSOProvider
7881
enterpriseConnection={enterpriseConnection}
79-
isLoading={isLoading}
82+
createEnterpriseConnection={createEnterpriseConnection}
8083
>
8184
<ConfigureSSOSteps />
82-
</ConfigureSSOFlowProvider>
85+
</ConfigureSSOProvider>
8386
);
8487
};
8588

8689
const ConfigureSSOSteps = () => {
87-
const { initialStepId } = useConfigureSSOFlow();
90+
const { initialStepId } = useConfigureSSO();
8891

8992
return (
9093
<Wizard initialStepId={initialStepId}>

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

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

55
import { deriveInitialStep } from './deriveInitialStep';
@@ -14,10 +14,6 @@ export interface ConfigureSSOData {
1414
* The enterprise connection from the user's primary email address domain
1515
*/
1616
enterpriseConnection: EnterpriseConnectionResource | undefined;
17-
/**
18-
* Whether the underlying enterprise connection data is still loading
19-
*/
20-
isLoading: boolean;
2117
/**
2218
* The provider selected for this configuration. Reads from the existing
2319
* enterprise connection when present, falling back to the local selection
@@ -37,27 +33,27 @@ export interface ConfigureSSOData {
3733
createConnection: (provider: ProviderType) => Promise<void>;
3834
}
3935

40-
interface ConfigureSSOFlowProviderProps {
36+
interface ConfigureSSOProviderProps {
4137
enterpriseConnection: EnterpriseConnectionResource | undefined;
42-
isLoading?: boolean;
38+
createEnterpriseConnection: (
39+
params: CreateMeEnterpriseConnectionParams,
40+
) => Promise<EnterpriseConnectionResource | undefined>;
4341
}
4442

45-
const ConfigureSSOFlowContext = React.createContext<ConfigureSSOData | null>(null);
46-
ConfigureSSOFlowContext.displayName = 'ConfigureSSOFlowContext';
43+
const ConfigureSSOContext = React.createContext<ConfigureSSOData | null>(null);
44+
ConfigureSSOContext.displayName = 'ConfigureSSOContext';
4745

48-
export const ConfigureSSOFlowProvider = ({
46+
export const ConfigureSSOProvider = ({
4947
enterpriseConnection,
50-
isLoading = false,
48+
createEnterpriseConnection,
5149
children,
52-
}: PropsWithChildren<ConfigureSSOFlowProviderProps>): JSX.Element => {
50+
}: PropsWithChildren<ConfigureSSOProviderProps>): JSX.Element => {
5351
const { user } = useUser();
5452
const { session } = useSession();
5553
const [provider, setProvider] = React.useState<ProviderType | undefined>(
5654
enterpriseConnection?.provider as ProviderType,
5755
);
5856

59-
const { createEnterpriseConnection } = __internal_useUserEnterpriseConnections();
60-
6157
const initialStepId = deriveInitialStep(enterpriseConnection);
6258

6359
const createConnectionFetcher = React.useCallback(
@@ -87,21 +83,20 @@ export const ConfigureSSOFlowProvider = ({
8783
() => ({
8884
initialStepId,
8985
enterpriseConnection,
90-
isLoading,
9186
provider,
9287
setProvider,
9388
createConnection,
9489
}),
95-
[initialStepId, enterpriseConnection, isLoading, provider, createConnection],
90+
[initialStepId, enterpriseConnection, provider, createConnection],
9691
);
9792

98-
return <ConfigureSSOFlowContext.Provider value={value}>{children}</ConfigureSSOFlowContext.Provider>;
93+
return <ConfigureSSOContext.Provider value={value}>{children}</ConfigureSSOContext.Provider>;
9994
};
10095

101-
export const useConfigureSSOFlow = (): ConfigureSSOData => {
102-
const ctx = React.useContext(ConfigureSSOFlowContext);
96+
export const useConfigureSSO = (): ConfigureSSOData => {
97+
const ctx = React.useContext(ConfigureSSOContext);
10398
if (!ctx) {
104-
throw new Error('useConfigureSSOFlow called outside <ConfigureSSOFlowProvider>.');
99+
throw new Error('useConfigureSSO called outside <ConfigureSSOProvider>.');
105100
}
106101
return ctx;
107102
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { useCardState } from '@/elements/contexts';
1717
import { Alert } from '@/ui/elements/Alert';
1818
import { handleError } from '@/utils/errorHandler';
1919

20-
import { useConfigureSSOFlow } from '../ConfigureSSOContext';
20+
import { useConfigureSSO } from '../ConfigureSSOContext';
2121
import { Step } from '../elements/Step';
2222
import { useWizard } from '../elements/Wizard';
2323
import type { ProviderType } from '../types';
@@ -44,7 +44,7 @@ const PROVIDER_GROUPS: ReadonlyArray<{
4444
export const SelectProviderStep = (): JSX.Element => {
4545
const card = useCardState();
4646
const { goNext, isLastStep } = useWizard();
47-
const { setProvider, createConnection } = useConfigureSSOFlow();
47+
const { setProvider, createConnection } = useConfigureSSO();
4848
const [selected, setSelected] = React.useState<ProviderType | null>(null);
4949

5050
const handleContinue = async () => {

packages/ui/src/components/ConfigureSSO/steps/__tests__/SelectProviderStep.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ const clearProvider = vi.fn();
3131
const createConnection = vi.fn();
3232

3333
vi.mock('../../ConfigureSSOContext', () => ({
34-
useConfigureSSOFlow: () => ({
34+
useConfigureSSO: () => ({
3535
enterpriseConnection: undefined,
36-
isLoading: false,
3736
provider: undefined,
3837
setProvider,
3938
clearProvider,

0 commit comments

Comments
 (0)