Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/mosaic-sign-in-sign-up-fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
8 changes: 8 additions & 0 deletions packages/mosaic/src/components/card/card.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export const root = stylex.create({
// eslint-disable-next-line @stylexjs/no-lookahead-selectors -- every browser this package builds for supports `:has()`; an older one draws no footer divider.
[stylex.when.descendant(':where(*)', cardContentMarker)]: '1px',
},
'--_cl-card-header-padding-end': {
default: space['5'],
// eslint-disable-next-line @stylexjs/no-lookahead-selectors -- every browser this package builds for supports `:has()`; an older one pads under the header of a card that also has content.
[stylex.when.descendant(':where(*)', cardContentMarker)]: '0px',
// eslint-disable-next-line @stylexjs/no-lookahead-selectors -- as above, for a card whose header is followed by a footer.
[stylex.when.descendant(':where(*)', cardFooterMarker)]: '0px',
},
color: colorVars['--cl-color-foreground'],
containerName: 'card',
containerType: 'inline-size',
Expand Down Expand Up @@ -76,6 +83,7 @@ export const header = stylex.create({
columnGap: HEADER_COLUMN_GAP,
display: 'flex',
flexDirection: 'row-reverse',
paddingBlockEnd: 'var(--_cl-card-header-padding-end)',
paddingBlockStart: space['4'],
},
content: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
emailLinkStatusCopy,
httpsUrl,
identifierFieldCopy,
legalConsentLabel,
signUpFieldNames,
signUpHeading,
splitLastUsedProvider,
startPrompt,
stepIds,
Expand Down Expand Up @@ -44,11 +47,12 @@ const stepsByKey: Record<SignInStepKey, SignInStep> = {
'notice:password-compromised': { kind: 'notice', purpose: 'password-compromised' },
'notice:enterprise-sso': { kind: 'notice', purpose: 'enterprise-sso' },
'notice:email-link': { kind: 'notice', purpose: 'email-link', identifier: 'jane@acme.com' },
'notice:email-link-status': { kind: 'notice', purpose: 'email-link-status', status: 'expired' },
'notice:email-link-status': { kind: 'notice', purpose: 'email-link-status', status: 'expired', flow: 'sign-in' },
'notice:verify-email-link': { kind: 'notice', purpose: 'verify-email-link', identifier: 'new@acme.com' },
'notice:start-over': { kind: 'notice', purpose: 'start-over' },
'new-password:forgot': { kind: 'new-password', reason: 'forgot' },
'new-password:required': { kind: 'new-password', reason: 'required' },
'sign-up': { kind: 'sign-up' },
'sign-up': { kind: 'sign-up', fields: {} },
};

describe('stepKey', () => {
Expand All @@ -70,24 +74,43 @@ describe('emailLinkStatusCopy', () => {
const m = signInMessages;

it('tells the tab the link opened in to go back to the original tab', () => {
expect(emailLinkStatusCopy('signed-in', m)).toEqual({
expect(emailLinkStatusCopy({ status: 'signed-in', flow: 'sign-in' }, m)).toEqual({
title: 'Successfully signed in',
description: 'Return to original tab to continue',
});
expect(emailLinkStatusCopy('transferable', m).title).toBe('Email verified');
expect(emailLinkStatusCopy({ status: 'transferable', flow: 'sign-in' }, m).title).toBe('Email verified');
});

it('tells the original tab to go to the newly opened one', () => {
expect(emailLinkStatusCopy('signed-in-other-tab', m)).toEqual({
expect(emailLinkStatusCopy({ status: 'signed-in-other-tab', flow: 'sign-in' }, m)).toEqual({
title: 'Signed in on other tab',
description: 'Return to the newly opened tab to continue',
});
});

it('uses the sign-up wording where it differs, and the sign-in wording elsewhere', () => {
expect(emailLinkStatusCopy({ status: 'loading', flow: 'sign-up' }, m).title).toBe('Signing up...');
expect(emailLinkStatusCopy({ status: 'signed-in', flow: 'sign-up' }, m).title).toBe('Successfully signed up');
expect(emailLinkStatusCopy({ status: 'signed-in-other-tab', flow: 'sign-up' }, m)).toEqual({
title: 'Successfully verified email',
description: 'Return to previous tab to continue',
});
expect(emailLinkStatusCopy({ status: 'client-mismatch', flow: 'sign-up' }, m).description).toContain('sign-up');
expect(emailLinkStatusCopy({ status: 'expired', flow: 'sign-up' }, m)).toEqual(
emailLinkStatusCopy({ status: 'expired', flow: 'sign-in' }, m),
);
});

it('names what went wrong with the link', () => {
expect(emailLinkStatusCopy('expired', m).title).toBe('This verification link has expired');
expect(emailLinkStatusCopy('failed', m).title).toBe('This verification link is invalid');
expect(emailLinkStatusCopy('client-mismatch', m).title).toBe('Verification link is invalid for this device');
expect(emailLinkStatusCopy({ status: 'expired', flow: 'sign-in' }, m).title).toBe(
'This verification link has expired',
);
expect(emailLinkStatusCopy({ status: 'failed', flow: 'sign-in' }, m).title).toBe(
'This verification link is invalid',
);
expect(emailLinkStatusCopy({ status: 'client-mismatch', flow: 'sign-in' }, m).title).toBe(
'Verification link is invalid for this device',
);
});
});

Expand Down Expand Up @@ -243,3 +266,39 @@ describe('splitLastUsedProvider', () => {
});
});
});

describe('signUpFieldNames', () => {
it('lists the fields the sign-up asks for in the order the form shows them', () => {
expect(
signUpFieldNames({
password: { required: true },
username: { required: false },
firstName: { required: true },
phoneNumber: { required: false },
}),
).toEqual(['firstName', 'username', 'phoneNumber', 'password']);
expect(signUpFieldNames({})).toEqual([]);
});
});

describe('sign-up legal consent', () => {
const m = signInMessages;

it('names only the pages the instance links to', () => {
expect(legalConsentLabel({ termsUrl: 'https://acme.com/terms' }, m)).toBe(m.signUp.legalConsent.termsOnly);
expect(legalConsentLabel({ privacyPolicyUrl: 'https://acme.com/privacy' }, m)).toBe(
m.signUp.legalConsent.privacyOnly,
);
expect(
legalConsentLabel({ termsUrl: 'https://acme.com/terms', privacyPolicyUrl: 'https://acme.com/privacy' }, m),
).toBe(m.signUp.legalConsent.termsAndPrivacy);
});

it('titles the step for consent when consent is all that is missing', () => {
expect(signUpHeading({ kind: 'sign-up', fields: {}, legalConsent: {} }, m).title).toBe('Legal consent');
expect(
signUpHeading({ kind: 'sign-up', fields: { password: { required: true } }, legalConsent: {} }, m).title,
).toBe('Create your account');
expect(signUpHeading({ kind: 'sign-up', fields: {} }, m).title).toBe('Create your account');
});
});
3 changes: 3 additions & 0 deletions packages/mosaic/src/features/sign-in/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ export type {
SignInSubmitEvent,
SignInValues,
SignInViewProps,
SignUpFieldName,
SignUpFields,
SignUpLegalConsent,
} from './sign-in.types';
44 changes: 44 additions & 0 deletions packages/mosaic/src/features/sign-in/sign-in.messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const signInMessages = {
selectedCountry: 'Country, {country}',
chooseCountry: 'Choose a country',
searchCountries: 'Search countries',
countrySearchPlaceholder: 'Search',
noCountries: 'No countries found',
usePasskey: 'Use passkey instead',
signUpPrompt: 'Don’t have an account?',
signUpLink: 'Sign up',
Expand Down Expand Up @@ -114,6 +116,29 @@ export const signInMessages = {
'To continue, open the verification link on the device and browser from which you initiated the sign-in',
},
closeTab: 'You may close this tab',
signUp: {
loading: {
title: 'Signing up...',
description: 'You will be redirected soon',
},
signedIn: {
title: 'Successfully signed up',
description: 'Return to original tab to continue',
},
signedInOtherTab: {
title: 'Successfully verified email',
description: 'Return to previous tab to continue',
},
clientMismatch: {
title: 'Verification link is invalid for this device',
description:
'To continue, open the verification link on the device and browser from which you initiated the sign-up',
},
},
},
verifyEmailLink: {
title: 'Verify your email',
description: 'Use the verification link sent to your email address',
},
passkey: {
title: 'Use your passkey',
Expand Down Expand Up @@ -231,10 +256,29 @@ export const signInMessages = {
firstNamePlaceholder: 'First name',
lastNameLabel: 'Last name',
lastNamePlaceholder: 'Last name',
usernameLabel: 'Username',
usernamePlaceholder: 'Enter your username',
emailLabel: 'Email address',
emailPlaceholder: 'Enter your email address',
phoneLabel: 'Phone number',
phonePlaceholder: 'Enter your phone number',
selectedCountry: 'Country, {country}',
chooseCountry: 'Choose a country',
searchCountries: 'Search countries',
countrySearchPlaceholder: 'Search',
noCountries: 'No countries found',
optional: 'Optional',
useEmail: 'Use email instead',
usePhone: 'Use phone instead',
passwordLabel: 'Password',
passwordPlaceholder: 'Enter your password',
legalConsent: {
title: 'Legal consent',
description: 'Please read and accept the terms to continue',
termsAndPrivacy: 'I agree to the {#terms}Terms of Service{/terms} and {#privacy}Privacy Policy{/privacy}',
termsOnly: 'I agree to the {#terms}Terms of Service{/terms}',
privacyOnly: 'I agree to the {#privacy}Privacy Policy{/privacy}',
},
signInPrompt: 'Already have an account?',
signInLink: 'Sign in',
},
Expand Down
21 changes: 19 additions & 2 deletions packages/mosaic/src/features/sign-in/sign-in.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ export type SignInStep =
| { kind: 'notice'; purpose: 'no-methods' | 'password-compromised' | 'enterprise-sso' | 'start-over' }
| { kind: 'notice'; purpose: 'action-blocked'; details?: SignInActionBlockedDetails }
| { kind: 'notice'; purpose: 'email-link'; identifier: string }
| { kind: 'notice'; purpose: 'email-link-status'; status: SignInEmailLinkStatus }
| { kind: 'notice'; purpose: 'email-link-status'; status: SignInEmailLinkStatus; flow: 'sign-in' | 'sign-up' }
| { kind: 'notice'; purpose: 'verify-email-link'; identifier: string }
| { kind: 'new-password'; reason: 'forgot' | 'required' }
| { kind: 'sign-up' };
| {
kind: 'sign-up';
fields: SignUpFields;
nextField?: 'emailAddress' | 'phoneNumber';
legalConsent?: SignUpLegalConsent;
};

export type SignInEmailLinkStatus =
| 'loading'
Expand All @@ -58,6 +64,15 @@ export type SignInEmailLinkStatus =
| 'failed'
| 'client-mismatch';

export type SignUpFieldName = 'firstName' | 'lastName' | 'username' | 'emailAddress' | 'phoneNumber' | 'password';

export type SignUpFields = Partial<Record<SignUpFieldName, { required: boolean }>>;

export interface SignUpLegalConsent {
termsUrl?: string;
privacyPolicyUrl?: string;
}

export interface SignInActionBlockedDetails {
title?: string;
description?: string;
Expand Down Expand Up @@ -87,9 +102,11 @@ export interface SignInValues {
backupCode: string;
firstName: string;
lastName: string;
username: string;
newPassword: string;
confirmPassword: string;
signOutOfOtherSessions: boolean;
legalAccepted: boolean;
}

export interface SignInSubmitEvent {
Expand Down
61 changes: 52 additions & 9 deletions packages/mosaic/src/features/sign-in/sign-in.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { stringToFormattedPhoneString } from '@clerk/shared/phone';

import type { MosaicMessages } from '../../localization';
import { fill } from '../../localization';
import type { SignInEmailLinkStatus, SignInIdentifierField, SignInProvider, SignInStep } from './sign-in.types';
import type {
SignInIdentifierField,
SignInProvider,
SignInStep,
SignUpFieldName,
SignUpFields,
SignUpLegalConsent,
} from './sign-in.types';

export const stepIds = {
identifier: ['identifier'],
Expand Down Expand Up @@ -34,6 +41,7 @@ export const stepIds = {
'notice:email-link',
'notice:email-link-status',
'notice:start-over',
'notice:verify-email-link',
],
newPassword: ['new-password:forgot', 'new-password:required'],
signUp: ['sign-up'],
Expand Down Expand Up @@ -75,25 +83,28 @@ type Messages = MosaicMessages['signIn'];
type CodeStepData = Extract<SignInStep, { kind: 'code' }>;
type CodeResendCopy = Pick<Messages['emailCode'], 'resendText' | 'resend' | 'resendCountdown'>;

type EmailLinkStatusStep = Extract<SignInStep, { purpose: 'email-link-status' }>;

export function emailLinkStatusCopy(
status: SignInEmailLinkStatus,
{ status, flow }: Pick<EmailLinkStatusStep, 'status' | 'flow'>,
m: Messages,
): { title: string; description: string } {
const copy = flow === 'sign-up' ? { ...m.emailLink, ...m.emailLink.signUp } : m.emailLink;
switch (status) {
case 'loading':
return m.emailLink.loading;
return copy.loading;
case 'signed-in':
return m.emailLink.signedIn;
return copy.signedIn;
case 'signed-in-other-tab':
return m.emailLink.signedInOtherTab;
return copy.signedInOtherTab;
case 'transferable':
return m.emailLink.transferable;
return copy.transferable;
case 'expired':
return m.emailLink.expired;
return copy.expired;
case 'failed':
return m.emailLink.failed;
return copy.failed;
case 'client-mismatch':
return m.emailLink.clientMismatch;
return copy.clientMismatch;
}
}

Expand Down Expand Up @@ -271,3 +282,35 @@ export function splitLastUsedProvider(
const lastUsed = providers.find(provider => provider.id === lastUsedProviderId);
return { lastUsed, others: lastUsed ? providers.filter(provider => provider !== lastUsed) : providers };
}

const signUpFieldOrder: readonly SignUpFieldName[] = [
'firstName',
'lastName',
'username',
'emailAddress',
'phoneNumber',
'password',
];

export function signUpFieldNames(fields: SignUpFields): SignUpFieldName[] {
return signUpFieldOrder.filter(name => fields[name]);
}

export function signUpHeading(
step: Extract<SignInStep, { kind: 'sign-up' }>,
m: Messages,
): { title: string; description: string } {
return step.legalConsent && signUpFieldNames(step.fields).length === 0
? { title: m.signUp.legalConsent.title, description: m.signUp.legalConsent.description }
: { title: m.signUp.title, description: m.signUp.description };
}

export function legalConsentLabel({ termsUrl, privacyPolicyUrl }: SignUpLegalConsent, m: Messages) {
if (termsUrl && !privacyPolicyUrl) {
return m.signUp.legalConsent.termsOnly;
}
if (privacyPolicyUrl && !termsUrl) {
return m.signUp.legalConsent.privacyOnly;
}
return m.signUp.legalConsent.termsAndPrivacy;
}
Loading
Loading