Skip to content

Commit 8d541cd

Browse files
feat(mosaic): add the sign-in start over notice and required password reset
1 parent fb6a02a commit 8d541cd

12 files changed

Lines changed: 95 additions & 24 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

‎packages/mosaic/src/features/sign-in/__tests__/sign-in.utils.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ const stepsByKey: Record<SignInStepKey, SignInStep> = {
4545
'notice:enterprise-sso': { kind: 'notice', purpose: 'enterprise-sso' },
4646
'notice:email-link': { kind: 'notice', purpose: 'email-link', identifier: 'jane@acme.com' },
4747
'notice:email-link-status': { kind: 'notice', purpose: 'email-link-status', status: 'expired' },
48+
'notice:start-over': { kind: 'notice', purpose: 'start-over' },
4849
'new-password:forgot': { kind: 'new-password', reason: 'forgot' },
50+
'new-password:required': { kind: 'new-password', reason: 'required' },
4951
'sign-up': { kind: 'sign-up' },
5052
};
5153

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ export const signInMessages = {
6060
title: 'Cannot sign in',
6161
description: 'Cannot proceed with sign in. There’s no available authentication factor.',
6262
},
63+
startOver: {
64+
title: 'Something went wrong',
65+
description: 'We couldn’t continue signing you in. Start over to try again.',
66+
action: 'Start over',
67+
},
6368
actionBlocked: {
6469
title: 'We couldn’t complete this request',
6570
description: 'For your security, this request could not be completed.',
@@ -135,6 +140,7 @@ export const signInMessages = {
135140
passwordLabel: 'New password',
136141
confirmPasswordLabel: 'Confirm password',
137142
signOutOfOtherSessions: 'Sign out of all other devices',
143+
requiredMessage: 'For security reasons, it is required to reset your password.',
138144
submit: 'Reset password',
139145
pending: 'Resetting password',
140146
},

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ export type SignInStep =
4242
| { kind: 'choice'; purpose: 'wallets'; options: readonly SignInProvider[] }
4343
| { kind: 'notice'; purpose: 'help' }
4444
| { kind: 'notice'; purpose: 'forgot-password'; identifier: string }
45-
| { kind: 'notice'; purpose: 'no-methods' | 'password-compromised' | 'enterprise-sso' }
45+
| { kind: 'notice'; purpose: 'no-methods' | 'password-compromised' | 'enterprise-sso' | 'start-over' }
4646
| { kind: 'notice'; purpose: 'action-blocked'; details?: SignInActionBlockedDetails }
4747
| { kind: 'notice'; purpose: 'email-link'; identifier: string }
4848
| { kind: 'notice'; purpose: 'email-link-status'; status: SignInEmailLinkStatus }
49-
| { kind: 'new-password'; reason: 'forgot' }
49+
| { kind: 'new-password'; reason: 'forgot' | 'required' }
5050
| { kind: 'sign-up' };
5151

5252
export type SignInEmailLinkStatus =
@@ -123,6 +123,7 @@ export interface SignInViewProps {
123123
onCancel?: () => void;
124124
onShowHelp: () => void;
125125
onBack: () => void;
126+
onStartOver: () => void;
126127
onEmailSupport: () => void;
127128
pendingFactorId?: string;
128129
onSelectFactor: (id: string) => void;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ export const stepIds = {
3333
'notice:enterprise-sso',
3434
'notice:email-link',
3535
'notice:email-link-status',
36+
'notice:start-over',
3637
],
37-
newPassword: ['new-password:forgot'],
38+
newPassword: ['new-password:forgot', 'new-password:required'],
3839
signUp: ['sign-up'],
3940
} as const;
4041

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export function SignInView({
8585
onCancel,
8686
onShowHelp,
8787
onBack,
88+
onStartOver,
8889
onEmailSupport,
8990
pendingFactorId,
9091
onSelectFactor,
@@ -263,6 +264,7 @@ export function SignInView({
263264
onSubmit={() => onSubmit()}
264265
onEmailSupport={onEmailSupport}
265266
onBack={onBack}
267+
onStartOver={onStartOver}
266268
onEditIdentifier={onEditIdentifier}
267269
onForgotPassword={onForgotPassword}
268270
onCancel={onCancel}
@@ -271,14 +273,17 @@ export function SignInView({
271273
</Flow.Step>
272274

273275
<Flow.Step ids={stepIds.newPassword}>
274-
<NewPasswordStep
275-
focusRef={focusRef}
276-
form={form}
277-
isPending={isPending}
278-
onSubmit={onSubmit}
279-
passwordFeedback={newPasswordFeedback}
280-
onBack={onBack}
281-
/>
276+
{current.kind === 'new-password' ? (
277+
<NewPasswordStep
278+
focusRef={focusRef}
279+
required={current.reason === 'required'}
280+
form={form}
281+
isPending={isPending}
282+
onSubmit={onSubmit}
283+
passwordFeedback={newPasswordFeedback}
284+
onBack={onBack}
285+
/>
286+
) : null}
282287
</Flow.Step>
283288

284289
<Flow.Step ids={stepIds.signUp}>

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { styles } from '../sign-in.styles';
1616
import type { SignInSubmitEvent, SignInValues } from '../sign-in.types';
1717

1818
interface NewPasswordStepProps {
19+
required: boolean;
1920
form: UseFormResult<SignInValues>;
2021
isPending: boolean;
2122
onSubmit: (event: SignInSubmitEvent) => void;
@@ -25,6 +26,7 @@ interface NewPasswordStepProps {
2526
}
2627

2728
export function NewPasswordStep({
29+
required,
2830
form,
2931
isPending,
3032
onSubmit,
@@ -43,7 +45,7 @@ export function NewPasswordStep({
4345
role='alert'
4446
color='negative'
4547
>
46-
{form.error}
48+
{form.error ?? (required ? m.newPassword.requiredMessage : undefined)}
4749
</Card.Banner>
4850
<Card.Content
4951
render={
@@ -75,16 +77,18 @@ export function NewPasswordStep({
7577
label={m.newPassword.confirmPasswordLabel}
7678
disabled={isPending}
7779
/>
78-
<Field.Root
79-
orientation='horizontal'
80-
disabled={isPending}
81-
>
82-
<Checkbox
83-
checked={form.values.signOutOfOtherSessions}
84-
onChange={event => form.setValue('signOutOfOtherSessions', event.target.checked)}
85-
/>
86-
<Field.Label>{m.newPassword.signOutOfOtherSessions}</Field.Label>
87-
</Field.Root>
80+
{required ? null : (
81+
<Field.Root
82+
orientation='horizontal'
83+
disabled={isPending}
84+
>
85+
<Checkbox
86+
checked={form.values.signOutOfOtherSessions}
87+
onChange={event => form.setValue('signOutOfOtherSessions', event.target.checked)}
88+
/>
89+
<Field.Label>{m.newPassword.signOutOfOtherSessions}</Field.Label>
90+
</Field.Root>
91+
)}
8892
</div>
8993
</Card.Content>
9094
<Card.Footer>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { SignInEmailLinkStatus } from './sign-in-email-link-status';
1010
import { SignInEnterpriseSso } from './sign-in-enterprise-sso';
1111
import { SignInForgotPassword } from './sign-in-forgot-password';
1212
import { SignInPasswordCompromised } from './sign-in-password-compromised';
13+
import { SignInStartOver } from './sign-in-start-over';
1314

1415
interface NoticeStepProps {
1516
step: Extract<SignInStep, { kind: 'notice' }>;
@@ -21,6 +22,7 @@ interface NoticeStepProps {
2122
onSubmit: () => void;
2223
onEmailSupport: () => void;
2324
onBack: () => void;
25+
onStartOver: () => void;
2426
onEditIdentifier: () => void;
2527
onForgotPassword?: () => void;
2628
onCancel?: () => void;
@@ -37,6 +39,7 @@ export function NoticeStep({
3739
onSubmit,
3840
onEmailSupport,
3941
onBack,
42+
onStartOver,
4043
onEditIdentifier,
4144
onForgotPassword,
4245
onCancel,
@@ -116,6 +119,8 @@ export function NoticeStep({
116119
onCancel={onCancel}
117120
/>
118121
);
122+
case 'start-over':
123+
return <SignInStartOver onStartOver={onStartOver} />;
119124
case 'email-link-status':
120125
return (
121126
<SignInEmailLinkStatus
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Button } from '../../../components/button';
2+
import { Card } from '../../../components/card';
3+
import { useFlowAutoFocus } from '../../../components/flow';
4+
import { useMessages } from '../../../localization';
5+
6+
interface SignInStartOverProps {
7+
onStartOver: () => void;
8+
}
9+
10+
export function SignInStartOver({ onStartOver }: SignInStartOverProps) {
11+
const m = useMessages('signIn').startOver;
12+
13+
return (
14+
<>
15+
<Card.Header>
16+
<Card.Title>{m.title}</Card.Title>
17+
<Card.Description>{m.description}</Card.Description>
18+
</Card.Header>
19+
<Card.Footer>
20+
<Button
21+
ref={useFlowAutoFocus<HTMLButtonElement>()}
22+
type='button'
23+
fullWidth
24+
onClick={onStartOver}
25+
>
26+
{m.action}
27+
</Button>
28+
</Card.Footer>
29+
</>
30+
);
31+
}

‎packages/swingset/src/lib/registry.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ import {
373373
IdentifierProviderPending as SignInIdentifierProviderPending,
374374
IdentifierSignInOnly as SignInIdentifierSignInOnly,
375375
meta as signInMeta,
376+
NewPasswordRequired as SignInNewPasswordRequired,
376377
NewPasswordReset as SignInNewPasswordReset,
377378
NoticeActionBlocked as SignInNoticeActionBlocked,
378379
NoticeEmailLinkClientMismatch as SignInNoticeEmailLinkClientMismatch,
@@ -390,6 +391,7 @@ import {
390391
NoticeNoMethods as SignInNoticeNoMethods,
391392
NoticePasswordCompromised as SignInNoticePasswordCompromised,
392393
NoticePasswordCompromisedPending as SignInNoticePasswordCompromisedPending,
394+
NoticeStartOver as SignInNoticeStartOver,
393395
SignUpDetails as SignInSignUpDetails,
394396
} from '../stories/sign-in.stories';
395397
import {
@@ -1344,7 +1346,9 @@ const signInModule: StoryModule = {
13441346
NoticeEmailLinkExpired: SignInNoticeEmailLinkExpired,
13451347
NoticeEmailLinkInvalid: SignInNoticeEmailLinkInvalid,
13461348
NoticeEmailLinkClientMismatch: SignInNoticeEmailLinkClientMismatch,
1349+
NoticeStartOver: SignInNoticeStartOver,
13471350
NewPasswordReset: SignInNewPasswordReset,
1351+
NewPasswordRequired: SignInNewPasswordRequired,
13481352
SignUpDetails: SignInSignUpDetails,
13491353
};
13501354
const organizationProfileApiKeysPanelModule: StoryModule = {

0 commit comments

Comments
 (0)