Skip to content

Commit c33ba36

Browse files
committed
Improve loading state on connection click
1 parent 031fa4c commit c33ba36

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

packages/clerk-js/src/ui/common/ChooseEnterpriseConnectionCard.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useState } from 'react';
2+
13
import type { LocalizationKey } from '@/ui/customizables';
24
import { descriptors, Flex, Grid, SimpleButton, Spinner, Text } from '@/ui/customizables';
35
import { Card } from '@/ui/elements/Card';
@@ -8,7 +10,7 @@ import type { InternalTheme, PropsOfComponent } from '@/ui/styledSystem';
810
type ChooseEnterpriseConnectionCardProps = {
911
title: LocalizationKey;
1012
subtitle: LocalizationKey;
11-
onClick: (id: string) => void;
13+
onClick: (id: string) => Promise<void>;
1214
enterpriseConnections: Array<{ id: string; name: string }>;
1315
};
1416

@@ -41,8 +43,7 @@ export const ChooseEnterpriseConnectionCard = ({
4143
key={id}
4244
id={id}
4345
label={name}
44-
onClick={() => onClick(id)}
45-
isLoading={card.isLoading}
46+
onClick={onClick}
4647
/>
4748
))}
4849
</Grid>
@@ -53,15 +54,20 @@ export const ChooseEnterpriseConnectionCard = ({
5354
);
5455
};
5556

56-
type ChooseEnterpriseConnectionButtonProps = PropsOfComponent<typeof SimpleButton> & {
57+
type ChooseEnterpriseConnectionButtonProps = Omit<PropsOfComponent<typeof SimpleButton>, 'onClick'> & {
5758
id: string;
5859
label?: string;
59-
isLoading: boolean;
60-
onClick: () => void;
60+
onClick: (id: string) => Promise<void>;
6161
};
6262

6363
const ChooseEnterpriseConnectionButton = (props: ChooseEnterpriseConnectionButtonProps): JSX.Element => {
64-
const { isLoading, label, onClick, ...rest } = props;
64+
const { label, onClick, ...rest } = props;
65+
const [isLoading, setIsLoading] = useState(false);
66+
67+
const handleClick = () => {
68+
setIsLoading(true);
69+
void onClick(props.id).catch(() => setIsLoading(false));
70+
};
6571

6672
return (
6773
<SimpleButton
@@ -70,7 +76,7 @@ const ChooseEnterpriseConnectionButton = (props: ChooseEnterpriseConnectionButto
7076
block
7177
isLoading={isLoading}
7278
hoverAsFocus
73-
onClick={onClick}
79+
onClick={handleClick}
7480
{...rest}
7581
sx={(theme: InternalTheme) => [
7682
{

packages/clerk-js/src/ui/components/SignIn/SignInChooseEnterpriseConnection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const withEnterpriseConnectionsGuard = <P extends AvailableComponentProps>(Compo
6767
Component,
6868
() => !hasMultipleEnterpriseConnections(signIn.supportedFirstFactors),
6969
({ clerk }) => signInCtx.signInUrl || clerk.buildSignInUrl(),
70-
'There are no enterprise connections available to sign-in. Clerk is redirecting to the `signInUrl` URL instead.',
70+
'There are no enterprise connections available to sign-in. Clerk is redirecting to the `signInUrl` instead.',
7171
)(props);
7272
};
7373

packages/clerk-js/src/ui/components/SignUp/SignUpChooseEnterpriseConnection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const SignUpChooseEnterpriseConnectionInternal = () => {
2121
const redirectUrl = ctx.ssoCallbackUrl;
2222
const redirectUrlComplete = ctx.afterSignUpUrl || '/';
2323

24-
void signUp.authenticateWithRedirect({
24+
return signUp.authenticateWithRedirect({
2525
strategy: 'enterprise_sso',
2626
redirectUrl,
2727
redirectUrlComplete,

packages/types/src/signIn.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ export interface SignInResource extends ClerkResource {
7979
createEmailLinkFlow: () => CreateEmailLinkFlowReturn<SignInStartEmailLinkFlowParams, SignInResource>;
8080

8181
validatePassword: (password: string, callbacks?: ValidatePasswordCallbacks) => void;
82-
83-
/**
84-
* @experimental
85-
*/
86-
__experimental_getEnterpriseConnections: () => Promise<SignInEnterpriseConnectionResource[]>;
87-
8882
/**
8983
* @internal
9084
*/
@@ -112,8 +106,3 @@ export interface SignInJSON extends ClerkResourceJSON {
112106
second_factor_verification: VerificationJSON | null;
113107
created_session_id: string | null;
114108
}
115-
116-
export interface SignInEnterpriseConnectionResource {
117-
id: string;
118-
name: string;
119-
}

0 commit comments

Comments
 (0)