Skip to content

Commit ffa739c

Browse files
refactor(mosaic): draw the sign-in enterprise connection picker as a choice step
1 parent a04c587 commit ffa739c

10 files changed

Lines changed: 188 additions & 88 deletions

File tree

‎packages/mosaic/src/features/sign-in/sign-in.messages.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ export const signInMessages = {
117117
continue: 'Continue with SSO',
118118
pending: 'Redirecting to SSO',
119119
bypass: 'Can’t use SSO?',
120-
chooseTitle: 'Choose an account',
121-
chooseDescription: 'Select an enterprise account to continue.',
120+
},
121+
enterpriseConnections: {
122+
title: 'Choose an account',
123+
description: 'Select an enterprise account to continue.',
122124
},
123125
ssoBypass: {
124126
notice: 'Your organization requires single sign-on. Continuing without it is recorded.',

‎packages/mosaic/src/features/sign-in/sign-in.types.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export type SignInStep =
3434
provider?: string;
3535
}
3636
| { kind: 'choice'; purpose: 'methods' | 'reset-methods'; options: readonly SignInFactor[] }
37+
| { kind: 'choice'; purpose: 'enterprise-connections'; options: readonly SignInSocialProvider[] }
3738
| { kind: 'notice'; purpose: 'help' }
3839
| { kind: 'notice'; purpose: 'forgot-password'; identifier: string }
39-
| { kind: 'notice'; purpose: 'no-methods' | 'password-compromised' }
40-
| { kind: 'notice'; purpose: 'enterprise-sso'; connections?: readonly SignInSocialProvider[] }
40+
| { kind: 'notice'; purpose: 'no-methods' | 'password-compromised' | 'enterprise-sso' }
4141
| { kind: 'notice'; purpose: 'action-blocked'; details?: SignInActionBlockedDetails }
4242
| { kind: 'notice'; purpose: 'email-link'; identifier: string }
4343
| { kind: 'new-password'; reason: 'forgot' }

‎packages/mosaic/src/features/sign-in/sign-in.view.tsx‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ function choiceCopy(
4545
step: Extract<SignInStep, { kind: 'choice' }>,
4646
m: Messages,
4747
): { title: string; description: string } {
48-
return step.purpose === 'reset-methods'
49-
? { title: m.resetMethods.title, description: m.resetMethods.description }
50-
: { title: m.alternativeMethods.title, description: m.alternativeMethods.description };
48+
switch (step.purpose) {
49+
case 'methods':
50+
return { title: m.alternativeMethods.title, description: m.alternativeMethods.description };
51+
case 'reset-methods':
52+
return { title: m.resetMethods.title, description: m.resetMethods.description };
53+
case 'enterprise-connections':
54+
return { title: m.enterpriseConnections.title, description: m.enterpriseConnections.description };
55+
}
5156
}
5257

5358
export function SignInView({
@@ -197,7 +202,7 @@ export function SignInView({
197202
) : null}
198203
</Flow.Step>
199204

200-
<Flow.Step ids={['choice:methods', 'choice:reset-methods']}>
205+
<Flow.Step ids={['choice:methods', 'choice:reset-methods', 'choice:enterprise-connections']}>
201206
{current.kind === 'choice' ? (
202207
<ChoiceStep
203208
focusRef={focusRef}
@@ -213,6 +218,11 @@ export function SignInView({
213218
onSelectFactor={onSelectFactor}
214219
onShowHelp={onShowHelp}
215220
onBack={onBack}
221+
logo={applicationLogoUrl ? { src: applicationLogoUrl, alt: applicationName } : undefined}
222+
globalErrorMessage={globalErrorMessage}
223+
pendingProviderId={pendingProviderId}
224+
onSelectProvider={onSelectProvider}
225+
onCancel={onCancel}
216226
/>
217227
) : null}
218228
</Flow.Step>
@@ -243,8 +253,6 @@ export function SignInView({
243253
onEditIdentifier={onEditIdentifier}
244254
onForgotPassword={onForgotPassword}
245255
onCancel={onCancel}
246-
pendingProviderId={pendingProviderId}
247-
onSelectProvider={onSelectProvider}
248256
/>
249257
) : null}
250258
</Flow.Step>

‎packages/mosaic/src/features/sign-in/steps/choice-step.tsx‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { SecurityLockSquare } from '../../../icons/glyphs/security-lock-square';
99
import { SecurityPasskey } from '../../../icons/glyphs/security-passkey';
1010
import { SecurityPhone } from '../../../icons/glyphs/security-phone';
1111
import type { SignInFactor, SignInStep } from '../sign-in.types';
12+
import { SignInEnterpriseConnections } from './sign-in-enterprise-connections';
1213

1314
const factorIcon = {
1415
password: SecurityLockSquare,
@@ -29,6 +30,11 @@ interface ChoiceStepProps {
2930
onSelectFactor: (id: string) => void;
3031
onShowHelp: () => void;
3132
onBack: () => void;
33+
logo?: { src: string; alt: string };
34+
globalErrorMessage?: string;
35+
pendingProviderId?: string;
36+
onSelectProvider: (id: string) => void;
37+
onCancel?: () => void;
3238
focusRef?: Ref<HTMLElement>;
3339
}
3440

@@ -40,8 +46,29 @@ export function ChoiceStep({
4046
onSelectFactor,
4147
onShowHelp,
4248
onBack,
49+
logo,
50+
globalErrorMessage,
51+
pendingProviderId,
52+
onSelectProvider,
53+
onCancel,
4354
focusRef,
4455
}: ChoiceStepProps) {
56+
if (step.purpose === 'enterprise-connections') {
57+
return (
58+
<SignInEnterpriseConnections
59+
focusRef={focusRef}
60+
title={messages.title}
61+
description={messages.description}
62+
logo={logo}
63+
connections={step.options}
64+
globalErrorMessage={globalErrorMessage}
65+
pendingConnectionId={pendingProviderId}
66+
onSelectConnection={onSelectProvider}
67+
onCancel={onCancel}
68+
/>
69+
);
70+
}
71+
4572
return (
4673
<VerificationMethodPicker
4774
focusRef={focusRef}

‎packages/mosaic/src/features/sign-in/steps/notice-step.tsx‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ interface NoticeStepProps {
2121
onEmailSupport: () => void;
2222
onBack: () => void;
2323
onEditIdentifier: () => void;
24-
pendingProviderId?: string;
25-
onSelectProvider: (id: string) => void;
2624
onForgotPassword?: () => void;
2725
onCancel?: () => void;
2826
focusRef?: Ref<HTMLElement>;
@@ -41,8 +39,6 @@ export function NoticeStep({
4139
onEditIdentifier,
4240
onForgotPassword,
4341
onCancel,
44-
pendingProviderId,
45-
onSelectProvider,
4642
focusRef,
4743
}: NoticeStepProps) {
4844
const m = useMessages('signIn');
@@ -99,9 +95,6 @@ export function NoticeStep({
9995
return (
10096
<SignInEnterpriseSso
10197
focusRef={focusRef}
102-
connections={step.connections}
103-
pendingConnectionId={pendingProviderId}
104-
onSelectConnection={onSelectProvider}
10598
applicationName={applicationName}
10699
logo={logo}
107100
globalErrorMessage={globalErrorMessage}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { useMergeRefs } from '@floating-ui/react';
2+
import * as stylex from '@stylexjs/stylex';
3+
import type { Ref } from 'react';
4+
5+
import { Button } from '../../../components/button';
6+
import { Card } from '../../../components/card';
7+
import { useFlowAutoFocus } from '../../../components/flow';
8+
import { ProviderButton, ProviderButtonGroup } from '../../../components/provider-button';
9+
import { Text } from '../../../components/text';
10+
import { useMessages } from '../../../localization';
11+
import { styles } from '../sign-in.styles';
12+
import type { SignInSocialProvider } from '../sign-in.types';
13+
14+
interface SignInEnterpriseConnectionsProps {
15+
title: string;
16+
description: string;
17+
logo?: { src: string; alt: string };
18+
connections: readonly SignInSocialProvider[];
19+
globalErrorMessage?: string;
20+
pendingConnectionId?: string;
21+
onSelectConnection: (id: string) => void;
22+
onCancel?: () => void;
23+
focusRef?: Ref<HTMLElement>;
24+
}
25+
26+
export function SignInEnterpriseConnections({
27+
title,
28+
description,
29+
logo,
30+
connections,
31+
globalErrorMessage,
32+
pendingConnectionId,
33+
onSelectConnection,
34+
onCancel,
35+
focusRef,
36+
}: SignInEnterpriseConnectionsProps) {
37+
const m = useMessages('signIn');
38+
const firstRef = useMergeRefs<HTMLElement>([focusRef, useFlowAutoFocus<HTMLButtonElement>()]);
39+
const pending = Boolean(pendingConnectionId);
40+
41+
return (
42+
<>
43+
<Card.Header>
44+
{logo ? (
45+
<Card.Media>
46+
<img
47+
src={logo.src}
48+
alt={logo.alt}
49+
{...stylex.props(styles.logo)}
50+
/>
51+
</Card.Media>
52+
) : null}
53+
<Card.Title>{title}</Card.Title>
54+
<Card.Description>{description}</Card.Description>
55+
</Card.Header>
56+
<Card.Banner
57+
role='alert'
58+
color='negative'
59+
>
60+
{globalErrorMessage}
61+
</Card.Banner>
62+
<Card.Content>
63+
<ProviderButtonGroup
64+
layout='stacked'
65+
disabled={pending}
66+
>
67+
{connections.map((connection, index) => (
68+
<ProviderButton
69+
key={connection.id}
70+
ref={index === 0 ? firstRef : undefined}
71+
icon={
72+
<img
73+
src={connection.iconUrl}
74+
alt=''
75+
{...stylex.props(styles.providerIcon)}
76+
/>
77+
}
78+
longLabel={connection.name}
79+
shortLabel={connection.name}
80+
isPending={pendingConnectionId === connection.id}
81+
pendingLabel={m.enterpriseSso.pending}
82+
onClick={() => onSelectConnection(connection.id)}
83+
/>
84+
))}
85+
</ProviderButtonGroup>
86+
{onCancel ? (
87+
<Text
88+
size='sm'
89+
xstyle={styles.footerText}
90+
>
91+
<Button
92+
type='button'
93+
size='sm'
94+
variant='link'
95+
color='neutral'
96+
disabled={pending}
97+
onClick={onCancel}
98+
>
99+
{m.enterpriseSso.bypass}
100+
</Button>
101+
</Text>
102+
) : null}
103+
</Card.Content>
104+
</>
105+
);
106+
}

‎packages/mosaic/src/features/sign-in/steps/sign-in-enterprise-sso.tsx‎

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@ import type { Ref } from 'react';
55
import { Button, SubmitButton } from '../../../components/button';
66
import { Card } from '../../../components/card';
77
import { useFlowAutoFocus } from '../../../components/flow';
8-
import { ProviderButton, ProviderButtonGroup } from '../../../components/provider-button';
98
import { Text } from '../../../components/text';
109
import { fill, useMessages } from '../../../localization';
1110
import { styles } from '../sign-in.styles';
12-
import type { SignInSocialProvider } from '../sign-in.types';
1311

1412
interface SignInEnterpriseSsoProps {
1513
applicationName: string;
1614
logo?: { src: string; alt: string };
17-
connections?: readonly SignInSocialProvider[];
18-
pendingConnectionId?: string;
19-
onSelectConnection: (id: string) => void;
2015
globalErrorMessage?: string;
2116
isPending: boolean;
2217
onSubmit: () => void;
@@ -27,9 +22,6 @@ interface SignInEnterpriseSsoProps {
2722
export function SignInEnterpriseSso({
2823
applicationName,
2924
logo,
30-
connections = [],
31-
pendingConnectionId,
32-
onSelectConnection,
3325
globalErrorMessage,
3426
isPending,
3527
onSubmit,
@@ -38,8 +30,6 @@ export function SignInEnterpriseSso({
3830
}: SignInEnterpriseSsoProps) {
3931
const m = useMessages('signIn');
4032
const ref = useMergeRefs<HTMLElement>([focusRef, useFlowAutoFocus<HTMLButtonElement>()]);
41-
const choosing = connections.length > 1;
42-
const busy = isPending || Boolean(pendingConnectionId);
4333

4434
return (
4535
<>
@@ -53,8 +43,8 @@ export function SignInEnterpriseSso({
5343
/>
5444
</Card.Media>
5545
) : null}
56-
<Card.Title>{choosing ? m.enterpriseSso.chooseTitle : fill(m.start.title, { applicationName })}</Card.Title>
57-
<Card.Description>{choosing ? m.enterpriseSso.chooseDescription : m.start.description}</Card.Description>
46+
<Card.Title>{fill(m.start.title, { applicationName })}</Card.Title>
47+
<Card.Description>{m.start.description}</Card.Description>
5848
</Card.Header>
5949
<Card.Banner
6050
role='alert'
@@ -63,42 +53,16 @@ export function SignInEnterpriseSso({
6353
{globalErrorMessage}
6454
</Card.Banner>
6555
<Card.Content>
66-
{choosing ? (
67-
<ProviderButtonGroup
68-
layout='stacked'
69-
disabled={Boolean(pendingConnectionId)}
70-
>
71-
{connections.map((connection, index) => (
72-
<ProviderButton
73-
key={connection.id}
74-
ref={index === 0 ? ref : undefined}
75-
icon={
76-
<img
77-
src={connection.iconUrl}
78-
alt=''
79-
{...stylex.props(styles.providerIcon)}
80-
/>
81-
}
82-
longLabel={connection.name}
83-
shortLabel={connection.name}
84-
isPending={pendingConnectionId === connection.id}
85-
pendingLabel={m.enterpriseSso.pending}
86-
onClick={() => onSelectConnection(connection.id)}
87-
/>
88-
))}
89-
</ProviderButtonGroup>
90-
) : (
91-
<SubmitButton
92-
ref={ref}
93-
type='button'
94-
fullWidth
95-
isPending={isPending}
96-
pendingLabel={m.enterpriseSso.pending}
97-
onClick={onSubmit}
98-
>
99-
{m.enterpriseSso.continue}
100-
</SubmitButton>
101-
)}
56+
<SubmitButton
57+
ref={ref}
58+
type='button'
59+
fullWidth
60+
isPending={isPending}
61+
pendingLabel={m.enterpriseSso.pending}
62+
onClick={onSubmit}
63+
>
64+
{m.enterpriseSso.continue}
65+
</SubmitButton>
10266
{onCancel ? (
10367
<Text
10468
size='sm'
@@ -109,7 +73,7 @@ export function SignInEnterpriseSso({
10973
size='sm'
11074
variant='link'
11175
color='neutral'
112-
disabled={busy}
76+
disabled={isPending}
11377
onClick={onCancel}
11478
>
11579
{m.enterpriseSso.bypass}

0 commit comments

Comments
 (0)