Skip to content

Commit fecd7a4

Browse files
committed
refactor(ui): call __internal_useUserEnterpriseConnections directly in SubmitSamlConfigSubStep
Mirrors the same pattern Iago adopted for SelectProviderStep: ConfigureSSOProvider no longer plumbs the enterprise-connection mutation through. SubmitSamlConfigSubStep now calls __internal_useUserEnterpriseConnections itself, grabs updateEnterpriseConnection, and wraps it in a local useReverification(useCallback(...)). Drops updateConnection from ConfigureSSOData, drops updateEnterpriseConnection from ConfigureSSOProviderProps, and stops threading the function through ConfigureSSO.tsx. The provider keeps ownership of provider-selection state (provider, setProvider, createConnection) since SelectProviderStep's create-flow still expects that shape until it gets the same treatment next.
1 parent 3bfe4b0 commit fecd7a4

3 files changed

Lines changed: 23 additions & 40 deletions

File tree

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

Lines changed: 2 additions & 10 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-
updateEnterpriseConnection,
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,11 +74,7 @@ const ConfigureSSOCardContent = () => {
7874
}
7975

8076
return (
81-
<ConfigureSSOProvider
82-
enterpriseConnection={enterpriseConnection}
83-
updateEnterpriseConnection={updateEnterpriseConnection}
84-
>
85-
77+
<ConfigureSSOProvider enterpriseConnection={enterpriseConnection}>
8678
<ConfigureSSOSteps />
8779
</ConfigureSSOProvider>
8880
);

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

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { useReverification } from '@clerk/shared/react';
2-
import type { EnterpriseConnectionResource, UpdateMeEnterpriseConnectionParams } 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,29 +24,17 @@ export interface ConfigureSSOData {
2524
* connection has been created.
2625
*/
2726
setProvider: (provider: ProviderType) => void;
28-
/**
29-
* Updates the current enterprise connection with the supplied params. The id
30-
* is taken implicitly from `enterpriseConnection` in context, so callers do
31-
* not need to thread it through. Throws when no enterprise connection is
32-
* loaded yet.
33-
*/
34-
updateConnection: (params: UpdateMeEnterpriseConnectionParams) => Promise<EnterpriseConnectionResource | undefined>;
3527
}
3628

3729
interface ConfigureSSOProviderProps {
3830
enterpriseConnection: EnterpriseConnectionResource | undefined;
39-
updateEnterpriseConnection: (
40-
enterpriseConnectionId: string,
41-
params: UpdateMeEnterpriseConnectionParams,
42-
) => Promise<EnterpriseConnectionResource | undefined>;
4331
}
4432

4533
const ConfigureSSOContext = React.createContext<ConfigureSSOData | null>(null);
4634
ConfigureSSOContext.displayName = 'ConfigureSSOContext';
4735

4836
export const ConfigureSSOProvider = ({
4937
enterpriseConnection,
50-
updateEnterpriseConnection,
5138
children,
5239
}: PropsWithChildren<ConfigureSSOProviderProps>): JSX.Element => {
5340
const [provider, setProvider] = React.useState<ProviderType | undefined>(
@@ -56,28 +43,14 @@ export const ConfigureSSOProvider = ({
5643

5744
const initialStepId = deriveInitialStep(enterpriseConnection);
5845

59-
const updateConnectionFetcher = React.useCallback(
60-
async (params: UpdateMeEnterpriseConnectionParams) => {
61-
if (!enterpriseConnection) {
62-
throw new Error('Enterprise connection required');
63-
}
64-
65-
return updateEnterpriseConnection(enterpriseConnection.id, params);
66-
},
67-
[enterpriseConnection, updateEnterpriseConnection],
68-
);
69-
70-
const updateConnection = useReverification(updateConnectionFetcher);
71-
7246
const value = React.useMemo<ConfigureSSOData>(
7347
() => ({
7448
initialStepId,
7549
enterpriseConnection,
7650
provider,
7751
setProvider,
78-
updateConnection,
7952
}),
80-
[initialStepId, enterpriseConnection, provider, updateConnection],
53+
[initialStepId, enterpriseConnection, provider],
8154
);
8255

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

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { __internal_useUserEnterpriseConnections, useReverification } from '@clerk/shared/react';
2+
import type { UpdateMeEnterpriseConnectionParams } from '@clerk/shared/types';
3+
import React from 'react';
4+
15
import {
26
Badge,
37
Col,
@@ -744,7 +748,21 @@ export const AssignUsersSubStep = (): JSX.Element => {
744748
export const SubmitSamlConfigSubStep = (): JSX.Element => {
745749
const card = useCardState();
746750
const { goNext, goPrev, isFirstStep } = useWizard();
747-
const { enterpriseConnection, updateConnection } = useConfigureSSO();
751+
const { enterpriseConnection } = useConfigureSSO();
752+
const { updateEnterpriseConnection } = __internal_useUserEnterpriseConnections();
753+
754+
const updateConnection = useReverification(
755+
React.useCallback(
756+
async (params: UpdateMeEnterpriseConnectionParams) => {
757+
if (!enterpriseConnection) {
758+
throw new Error('Enterprise connection required');
759+
}
760+
761+
return updateEnterpriseConnection(enterpriseConnection.id, params);
762+
},
763+
[enterpriseConnection, updateEnterpriseConnection],
764+
),
765+
);
748766

749767
const metadataUrlField = useFormControl('idpMetadataUrl', '', {
750768
type: 'text',

0 commit comments

Comments
 (0)