Skip to content

Commit da96a61

Browse files
refactor(mosaic): Clean up shared screens between sign-up + sign-in (#10823)
1 parent 7d90373 commit da96a61

50 files changed

Lines changed: 1240 additions & 1035 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

‎packages/mosaic/AGENTS.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Most problems a feature hits already have a shared answer. Find the line for you
7575
- An action that may need step-up verification → `useReverificationFlow` (`src/features/reverification/`) in the model, passed to `useConfirmController`
7676
- A direct action that needs step-up verification → `useReverificationFlow` in the model, with `ReverificationDialog` (`src/blocks/reverification/`) in the view
7777
- A step that verifies a factor (a code, password, backup code or passkey, the method picker, help) → the steps in `src/blocks/verification/`, such as `VerificationCode`
78+
- A screen sign-in and sign-up both show (an email link and its status, a loading or protect-check notice, a blocked request, the wallet or enterprise connection picker, the alternative phone channel, the identity line, the captcha) → the steps in `src/blocks/auth/`, such as `AuthEmailLink`
7879
- Showing any error to the user → One of the owners above. They call `toLocalizableError` (or `toLocalizableErrors` for all errors) and resolve copy with `useErrorText`
7980
- Moving focus after a list row is removed → `useListRemovalFocus` (`src/hooks/`)
8081
- A debounced, abortable async check as the user types → `useDebouncedAsync` (`src/hooks/`)
@@ -85,6 +86,7 @@ Most problems a feature hits already have a shared answer. Find the line for you
8586
- An inline message row; height is undefined until measured → `useHeldMessage`, `useMessageHeight`, `FeedbackBody` (`src/utils/feedback.tsx`) + `src/styles/feedback.styles.ts`
8687
- Data read from a Clerk resource that should be cached across mounts → A query hook in `src/queries/`, called from the model (`src/queries/use-user-sessions-query.ts`)
8788
- The seconds left on a resend cooldown, for display → `useResendSeconds` (`src/hooks/`), from a `resendAvailableAt` time kept in the machine
89+
- The Resend link on a code or email link step, with its countdown → `verificationResend` (`src/blocks/verification/`), passed to the step as `resend`
8890
- An avatar or logo row: picker, drop target, crop dialog, Upload button or manage menu → `AvatarUpload` (`src/blocks/avatar-upload/`), laid out by the caller
8991
- Any other file picker or drop zone, such as a metadata or key file → `FileUpload` (`src/primitives/file-upload/`), see its `README.md`
9092
- Cropping an image to a square: pan, zoom, rotate, then draw the result → `ImageCropper` and `cropImage` (`src/primitives/image-cropper/`), see its `README.md`

‎packages/mosaic/docs/views.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ A block is a view fragment that owns one piece of state nothing outside it can u
124124
- `blocks/confirmation` (`Confirmation`) is a confirm step with no typed phrase.
125125
- `blocks/avatar-upload` (`AvatarUpload`) is an avatar or logo picker. Its parts share the file input, so the caller places them in its own layout.
126126
- `blocks/verification` holds the steps that verify a factor, such as `VerificationCode`. Each renders the inside of a card and takes its copy as `messages`, so reverification and sign-in show them with their own strings.
127+
- `blocks/auth` holds the screens sign-in and sign-up share, such as `AuthEmailLink`. Each renders the inside of a card and takes its copy as `messages`, so sign-up shows them with its own strings.
127128

128129
`Destructive` and `Confirmation` take a `controller` from `useConfirmController` (`blocks/confirm/`), which decides whether the dialog closes or explains itself. The hook runs in the wrapper or controller, never in the view. A dialog next to its button takes the button as `trigger`:
129130

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
import { httpsUrl } from '../auth.utils';
4+
5+
describe('httpsUrl', () => {
6+
it('keeps an https link and drops any other scheme or an unparsable value', () => {
7+
expect(httpsUrl('https://acme.com/support')).toBe('https://acme.com/support');
8+
expect(httpsUrl('javascript:alert(1)')).toBeUndefined();
9+
expect(httpsUrl('http://acme.com/support')).toBeUndefined();
10+
expect(httpsUrl('data:text/html,hi')).toBeUndefined();
11+
expect(httpsUrl('/support')).toBeUndefined();
12+
expect(httpsUrl(undefined)).toBeUndefined();
13+
});
14+
});
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { Card } from '../../components/card';
2+
import { CopyButton } from '../../components/copy-button';
3+
import { Field } from '../../components/field';
4+
import { InputGroup } from '../../components/input-group';
5+
import { Link } from '../../components/link';
6+
import type { AuthActionBlockedDetails } from './auth.types';
7+
import { httpsUrl } from './auth.utils';
8+
9+
export interface AuthActionBlockedMessages {
10+
title: string;
11+
description: string;
12+
traceIdLabel: string;
13+
copyTraceId: string;
14+
traceIdCopied: string;
15+
}
16+
17+
interface AuthActionBlockedProps {
18+
messages: AuthActionBlockedMessages;
19+
details?: AuthActionBlockedDetails;
20+
}
21+
22+
export function AuthActionBlocked({ messages, details }: AuthActionBlockedProps) {
23+
const href = httpsUrl(details?.linkUrl);
24+
25+
return (
26+
<>
27+
<Card.Header>
28+
<Card.Title>{details?.title ?? messages.title}</Card.Title>
29+
<Card.Description>{details?.description ?? messages.description}</Card.Description>
30+
{href ? (
31+
<Card.Description>
32+
<Link
33+
href={href}
34+
target='_blank'
35+
rel='noopener noreferrer'
36+
size='sm'
37+
>
38+
{details?.linkText ?? href}
39+
</Link>
40+
</Card.Description>
41+
) : null}
42+
</Card.Header>
43+
{details?.traceId ? (
44+
<Card.Content>
45+
<Field.Root>
46+
<Field.Label>{messages.traceIdLabel}</Field.Label>
47+
<InputGroup.Root>
48+
<InputGroup.Input
49+
value={details.traceId}
50+
readOnly
51+
/>
52+
<InputGroup.End>
53+
<CopyButton
54+
value={details.traceId}
55+
label={messages.copyTraceId}
56+
copiedLabel={messages.traceIdCopied}
57+
/>
58+
</InputGroup.End>
59+
</InputGroup.Root>
60+
</Field.Root>
61+
</Card.Content>
62+
) : null}
63+
</>
64+
);
65+
}

packages/mosaic/src/features/sign-in/steps/sign-in-alternative-channel.tsx renamed to packages/mosaic/src/blocks/auth/auth-alternative-channel.tsx

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,51 @@ import { useMergeRefs } from '@floating-ui/react';
22
import * as stylex from '@stylexjs/stylex';
33
import type { ReactNode, Ref } from 'react';
44

5-
import { Button, SubmitButton } from '../../../components/button';
6-
import { Card } from '../../../components/card';
7-
import { Field } from '../../../components/field';
8-
import { useFlowAutoFocus } from '../../../components/flow';
9-
import type { FieldFeedback, UseFormResult } from '../../../components/form';
10-
import { PhoneInput } from '../../../components/phone-input';
11-
import { fill, useMessages } from '../../../localization';
12-
import { Form } from '../../../primitives/form';
13-
import { styles } from '../sign-in.styles';
14-
import type { SignInProvider, SignInSubmitEvent, SignInValues } from '../sign-in.types';
15-
import { SignInCaptcha } from './sign-in-captcha';
5+
import { Button, SubmitButton } from '../../components/button';
6+
import { Card } from '../../components/card';
7+
import { Field } from '../../components/field';
8+
import { useFlowAutoFocus } from '../../components/flow';
9+
import type { FieldFeedback, UseFormResult } from '../../components/form';
10+
import { PhoneInput } from '../../components/phone-input';
11+
import { fill } from '../../localization';
12+
import { Form } from '../../primitives/form';
13+
import { styles } from './auth.styles';
14+
import type { AuthProvider } from './auth.types';
15+
import { AuthCaptcha } from './auth-captcha';
1616

17-
interface SignInAlternativeChannelProps {
18-
channel: SignInProvider;
17+
export interface AuthAlternativeChannelMessages {
18+
title: string;
19+
description: string;
20+
fieldLabel: string;
21+
phonePlaceholder: string;
22+
selectedCountry: string;
23+
chooseCountry: string;
24+
searchCountries: string;
25+
countrySearchPlaceholder: string;
26+
noCountries: string;
27+
secondaryActionLabel: string;
28+
primaryActionLabel: string;
29+
pendingLabel: string;
30+
}
31+
32+
interface AuthAlternativeChannelProps<TValues extends { phoneNumber: string }> {
33+
messages: AuthAlternativeChannelMessages;
34+
channel: AuthProvider;
1935
applicationName: string;
2036
logo?: { src: string; alt: string };
21-
form: UseFormResult<SignInValues>;
37+
form: UseFormResult<TValues>;
2238
errorMessage?: string;
2339
globalErrorMessage?: string;
2440
isPending: boolean;
2541
isDisabled: boolean;
26-
onSubmit: (event: SignInSubmitEvent) => void;
42+
onSubmit: (event: { preventDefault: () => void }) => void;
2743
onCancel?: () => void;
2844
focusRef?: Ref<HTMLElement>;
29-
copy?: { title: string; description: string; label: string };
3045
children?: ReactNode;
3146
}
3247

33-
export function SignInAlternativeChannel({
48+
export function AuthAlternativeChannel<TValues extends { phoneNumber: string }>({
49+
messages,
3450
channel,
3551
applicationName,
3652
logo,
@@ -42,15 +58,12 @@ export function SignInAlternativeChannel({
4258
onSubmit,
4359
onCancel,
4460
focusRef,
45-
copy: copyProp,
4661
children,
47-
}: SignInAlternativeChannelProps) {
48-
const m = useMessages('signIn');
62+
}: AuthAlternativeChannelProps<TValues>) {
4963
const { ref: phoneFieldRef, ...phone } = form.registerValue('phoneNumber');
5064
const phoneRef = useMergeRefs<HTMLElement>([phoneFieldRef, focusRef, useFlowAutoFocus<HTMLInputElement>()]);
5165
const feedback: FieldFeedback | undefined = errorMessage ? { type: 'error', message: errorMessage } : undefined;
5266
const provider = channel.name;
53-
const copy = copyProp ?? m.alternativeChannel;
5467

5568
return (
5669
<>
@@ -64,8 +77,8 @@ export function SignInAlternativeChannel({
6477
/>
6578
</Card.Media>
6679
) : null}
67-
<Card.Title>{fill(copy.title, { applicationName, provider })}</Card.Title>
68-
<Card.Description>{fill(copy.description, { provider })}</Card.Description>
80+
<Card.Title>{fill(messages.title, { applicationName, provider })}</Card.Title>
81+
<Card.Description>{fill(messages.description, { provider })}</Card.Description>
6982
</Card.Header>
7083
<Card.Banner
7184
role='alert'
@@ -85,24 +98,24 @@ export function SignInAlternativeChannel({
8598
disabled={isDisabled}
8699
focusableWhenDisabled
87100
>
88-
<Field.Label>{fill(copy.label, { provider })}</Field.Label>
101+
<Field.Label>{fill(messages.fieldLabel, { provider })}</Field.Label>
89102
<PhoneInput
90103
ref={phoneRef}
91104
autoComplete='tel'
92-
placeholder={m.start.phonePlaceholder}
93-
countryTriggerLabel={m.start.selectedCountry}
94-
countryPopupLabel={m.start.chooseCountry}
95-
countrySearchLabel={m.start.searchCountries}
96-
countrySearchPlaceholder={m.start.countrySearchPlaceholder}
97-
noResultsMessage={m.start.noCountries}
105+
placeholder={messages.phonePlaceholder}
106+
countryTriggerLabel={messages.selectedCountry}
107+
countryPopupLabel={messages.chooseCountry}
108+
countrySearchLabel={messages.searchCountries}
109+
countrySearchPlaceholder={messages.countrySearchPlaceholder}
110+
noResultsMessage={messages.noCountries}
98111
{...phone}
99112
/>
100113
<Field.Feedback feedback={feedback} />
101114
</Field.Root>
102115
{children}
103116
</div>
104117
</Form>
105-
<SignInCaptcha />
118+
<AuthCaptcha />
106119
</Card.Content>
107120
<Card.Footer>
108121
{onCancel ? (
@@ -114,16 +127,16 @@ export function SignInAlternativeChannel({
114127
disabled={isDisabled}
115128
onClick={onCancel}
116129
>
117-
{m.useAnotherMethod}
130+
{messages.secondaryActionLabel}
118131
</Button>
119132
) : null}
120133
<SubmitButton
121134
form={form.id}
122135
fullWidth
123136
isPending={isPending}
124-
pendingLabel={m.verifying}
137+
pendingLabel={messages.pendingLabel}
125138
>
126-
{m.continue}
139+
{messages.primaryActionLabel}
127140
</SubmitButton>
128141
</Card.Footer>
129142
</>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Captcha } from '../../components/captcha';
2+
import { useFlowStepActive } from '../../primitives/flow';
3+
import { styles } from './auth.styles';
4+
5+
interface AuthCaptchaProps {
6+
onInteractiveChange?: (interactive: boolean) => void;
7+
}
8+
9+
export function AuthCaptcha({ onInteractiveChange }: AuthCaptchaProps) {
10+
const isActive = useFlowStepActive();
11+
if (!isActive) {
12+
return null;
13+
}
14+
return (
15+
<Captcha
16+
xstyle={styles.captcha}
17+
onInteractiveChange={onInteractiveChange}
18+
/>
19+
);
20+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Card } from '../../components/card';
2+
import { Spinner } from '../../components/spinner';
3+
import { Text } from '../../components/text';
4+
import { styles } from './auth.styles';
5+
import type { AuthEmailLinkStatusValue as Status } from './auth.types';
6+
7+
interface StatusCopy {
8+
title: string;
9+
description: string;
10+
}
11+
12+
export interface AuthEmailLinkStatusMessages {
13+
loading: StatusCopy;
14+
signedIn: StatusCopy;
15+
signedInOtherTab: StatusCopy;
16+
transferable: StatusCopy;
17+
expired: StatusCopy;
18+
failed: StatusCopy;
19+
clientMismatch: StatusCopy;
20+
closeTab: string;
21+
}
22+
23+
const statusCopy = {
24+
loading: 'loading',
25+
'signed-in': 'signedIn',
26+
'signed-in-other-tab': 'signedInOtherTab',
27+
transferable: 'transferable',
28+
expired: 'expired',
29+
failed: 'failed',
30+
'client-mismatch': 'clientMismatch',
31+
} as const satisfies Record<Status, keyof AuthEmailLinkStatusMessages>;
32+
33+
interface AuthEmailLinkStatusProps {
34+
messages: AuthEmailLinkStatusMessages;
35+
status: Status;
36+
globalErrorMessage?: string;
37+
}
38+
39+
export function AuthEmailLinkStatus({ messages, status, globalErrorMessage }: AuthEmailLinkStatusProps) {
40+
const copy = messages[statusCopy[status]];
41+
42+
return (
43+
<>
44+
<Card.Header>
45+
<Card.Title>{copy.title}</Card.Title>
46+
<Card.Description>{copy.description}</Card.Description>
47+
</Card.Header>
48+
<Card.Banner
49+
role='alert'
50+
color='negative'
51+
>
52+
{globalErrorMessage}
53+
</Card.Banner>
54+
<Card.Content xstyle={styles.status}>
55+
{status === 'loading' ? <Spinner /> : <Text color='foreground-secondary'>{messages.closeTab}</Text>}
56+
</Card.Content>
57+
</>
58+
);
59+
}

0 commit comments

Comments
 (0)