SignUp
Creating an account: name, email and password, then the code that proves the email is theirs. Short, one task per step, and nothing that belongs to onboarding.
import { AuthLayout } from '@sypnia/ui/react'
On a desktop
Press «Create account» empty to see the summary. A password like «password1234» is refused as leaked. Any code but 000000 finishes.
Code
import { useState, type ReactNode } from 'react';
import {
AuthLayout, Button, Checkbox, EmailInput, EmptyState, Field, FieldError, Form, FormActions, Input, List, ListItem, Notice,
OtpInput, PasswordInput, Says, SkeletonOf, Stack, useSypnia, type FormProblem,
} from '@sypnia/ui/react';
// Sign up: name, email and password, then the code that proves the email is theirs. Whether an address already has an
// account is never said here: that person gets an email to sign in instead, so nobody can test addresses.
const en = {
title: 'Create your account', lead: 'Free to start. No card needed.',
name: 'Your name', email: 'Work email', password: 'Password', passwordHint: 'At least 12 characters. A short sentence works well.',
terms: 'I accept the terms and the privacy policy', submit: 'Create account', busy: 'Creating…',
noName: 'Write your name, as your team will see it.', noEmail: 'Write your email.', badEmail: 'Write a whole email address, like ana@northwind.io.',
short: 'Use 12 characters or more.', leaked: 'This password appears in known data leaks. Choose another one.', noTerms: 'Accept the terms to create the account.',
have: 'Already have an account?', signIn: 'Sign in',
verify: 'Check your email', verifyLead: (e: string) => `We sent a 6-digit code to ${e}. It works for 15 minutes.`,
code: 'Code from the email', wrongCode: 'That code is not right. Check the newest email from Sypnia.', resend: 'Send a new code', resent: 'A new code is on its way.',
change: 'Use another email',
done: 'Your account is ready', doneLead: 'Next, name your first project. It takes a minute.', start: 'Set up my first project',
closed: 'Sign-ups are closed here', closedBody: 'Northwind only lets people in by invitation. Ask someone on the team to invite you.', toSignIn: 'Go to sign in',
says: 'Every bug leaves a light on.', perks: ['Errors, traces and replays in one place', 'Your data stays in your region', 'Open source, MIT'],
termsLink: 'Terms', privacy: 'Privacy',
};
const es: typeof en = {
title: 'Crea tu cuenta', lead: 'Empezar es gratis. No necesitas tarjeta.',
name: 'Tu nombre', email: 'Correo de trabajo', password: 'Contraseña', passwordHint: 'Al menos 12 caracteres. Una frase corta funciona bien.',
terms: 'Acepto los términos y la política de privacidad', submit: 'Crear cuenta', busy: 'Creando…',
noName: 'Escribe tu nombre, como lo verá tu equipo.', noEmail: 'Escribe tu correo.', badEmail: 'Escribe un correo completo, como ana@northwind.io.',
short: 'Usa 12 caracteres o más.', leaked: 'Esta contraseña aparece en filtraciones de datos conocidas. Elige otra.', noTerms: 'Acepta los términos para crear la cuenta.',
have: '¿Ya tienes una cuenta?', signIn: 'Inicia sesión',
verify: 'Revisa tu correo', verifyLead: (e: string) => `Enviamos un código de 6 dígitos a ${e}. Sirve por 15 minutos.`,
code: 'Código del correo', wrongCode: 'Ese código no es correcto. Revisa el correo más reciente de Sypnia.', resend: 'Enviar un código nuevo', resent: 'Va en camino un código nuevo.',
change: 'Usar otro correo',
done: 'Tu cuenta está lista', doneLead: 'Ahora, ponle nombre a tu primer proyecto. Toma un minuto.', start: 'Preparar mi primer proyecto',
closed: 'Aquí no se abren cuentas', closedBody: 'Northwind solo deja entrar por invitación. Pídele a alguien del equipo que te invite.', toSignIn: 'Ir a iniciar sesión',
says: 'Cada error deja una luz encendida.', perks: ['Errores, trazas y repeticiones en un solo lugar', 'Tus datos se quedan en tu región', 'Código abierto, MIT'],
termsLink: 'Términos', privacy: 'Privacidad',
};
const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));
export default function SignUp({ state = 'ready' }: { state?: 'ready' | 'loading' | 'closed' }) {
const { locale } = useSypnia();
const c = locale.startsWith('es') ? es : en;
const [step, setStep] = useState<'form' | 'verify' | 'done'>('form');
const [email, setEmail] = useState('');
const [problems, setProblems] = useState<FormProblem[]>([]);
const [codeError, setCodeError] = useState<string>();
const [resent, setResent] = useState(false);
// Loading: while the app checks that sign-ups are open, the real form with its words; the fields and buttons wait in
// their own boxes.
const loading = state === 'loading';
const wait = (n: ReactNode) => (loading ? <SkeletonOf>{n}</SkeletonOf> : n);
const footer = <><a href="#terms">{c.termsLink}</a><a href="#privacy">{c.privacy}</a></>;
if (state === 'closed') {
return (
<AuthLayout plain brandHref="#" footer={footer}>
<EmptyState icon="lock" title={c.closed} actions={<Button variant="primary" href="#sign-in">{c.toSignIn}</Button>}>{c.closedBody}</EmptyState>
</AuthLayout>
);
}
const check = (v: FormData): FormProblem[] => {
const out: FormProblem[] = [];
const e = String(v.get('email') ?? '').trim(), p = String(v.get('password') ?? '');
if (!String(v.get('name') ?? '').trim()) out.push({ name: 'name', label: c.name, message: c.noName });
if (!e) out.push({ name: 'email', label: c.email, message: c.noEmail });
else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) out.push({ name: 'email', label: c.email, message: c.badEmail });
if (p.length < 12) out.push({ name: 'password', label: c.password, message: c.short });
if (!v.get('terms')) out.push({ name: 'terms', label: c.termsLink, message: c.noTerms });
return out;
};
const title = step === 'form' ? c.title : step === 'verify' ? c.verify : c.done;
const lead = step === 'form' ? c.lead : step === 'verify' ? c.verifyLead(email) : c.doneLead;
return (
<AuthLayout title={title} lead={lead} width="md" brandHref="#" footer={footer}
after={step === 'form' ? <>{c.have} <a href="#sign-in">{c.signIn}</a></> : undefined}
aside={<><Says size="lg">{c.says}</Says><List label={c.says}>{c.perks.map((p) => <ListItem key={p} icon="check" title={p} />)}</List></>}>
{step === 'form' && (
<Form label={c.title} validate={check} problems={problems} onSubmit={async (v) => {
await wait(900);
if (/password|123456|qwerty/i.test(String(v.get('password')))) { setProblems([{ name: 'password', label: c.password, message: c.leaked }]); return; }
setEmail(String(v.get('email'))); setStep('verify');
}}>
{({ errorFor }) => (
<>
<Field label={c.name} error={errorFor('name')}>{wait(<Input name="name" autoComplete="name" defaultValue="" />)}</Field>
<Field label={c.email} error={errorFor('email')}>{wait(<EmailInput name="email" defaultValue={email} />)}</Field>
<Field label={c.password} hint={c.passwordHint} error={errorFor('password')}>{wait(<PasswordInput name="password" autoComplete="new-password" onChange={() => setProblems([])} />)}</Field>
<div>{wait(<Checkbox name="terms" label={c.terms} aria-invalid={errorFor('terms') ? true : undefined} aria-describedby={errorFor('terms') ? 'terms-error' : undefined} />)}
{errorFor('terms') && <FieldError id="terms-error">{errorFor('terms')}</FieldError>}</div>
{wait(<FormActions submitLabel={c.submit} busyLabel={c.busy} />)}
</>
)}
</Form>
)}
{step === 'verify' && (
<Stack gap={5}>
<Field label={c.code} error={codeError}>
<OtpInput autoFocus onComplete={async (code) => { setCodeError(undefined); await wait(600); if (code === '000000') setCodeError(c.wrongCode); else setStep('done'); }} />
</Field>
{resent && <Notice tone="ok">{c.resent}</Notice>}
<Stack gap={2}>
<Button icon="mail" disabled={resent} onClick={() => setResent(true)}>{c.resend}</Button>
<Button variant="quiet" icon="arrow-left" onClick={() => { setStep('form'); setResent(false); }}>{c.change}</Button>
</Stack>
</Stack>
)}
{step === 'done' && <Button variant="primary" iconEnd="arrow-right" href="#onboarding">{c.start}</Button>}
</AuthLayout>
);
} On a phone
At 390 px the card becomes the page; the side panel goes, since nothing in it is needed.
Skeleton
While the app checks whether sign-ups are open: the real form with its words; the fields and buttons wait in their own boxes.
When sign-ups are closed
An organization that only lets people in by invitation: say so, say who can invite, and offer sign in.
Sign-ups are closed here
When to use it
Use it when
- The way to a new account for any Sypnia product, and for apps built on Sypnia Data.
- Rules for the password said before typing, in the hint, not discovered after sending.
Do not use it when
- Asking for the company, the role or the plan here: that is onboarding, after the account exists.
- Saying that an email already has an account: that person gets an email to sign in instead, so nobody can test addresses.
For everyone
- Every rule of a field is in its hint, read with the field; errors are tied to their field and listed in a summary that takes the focus.
- The terms checkbox carries its own message when it is missing.
- The code step moves the focus to its title; pasting the code fills every box.
Props
| AuthLayout | Type | Default |
|---|---|---|
afterOne line under the card: «New to Sypnia? Create an account». | ReactNode | |
asideBeside the card when the layout is wide enough (60rem and more): what the person gets, a quote. Hidden on narrower screens, so nothing in it may be needed to finish the task. | ReactNode | |
brandThe mark at the top. Defaults to the Sypnia logo. | ReactNode | |
brandHrefWhere the mark leads. Without it the mark is not a link. | string | |
className | string | |
footerThe bottom line: terms, privacy, help. | ReactNode | |
leadOne sentence under the title: what happens here, or what to do next. | ReactNode | |
plainNo card around the content: for error and not-found pages, which say one thing and offer a way out. | boolean | |
titleWhat this step is, in the voice: «Sign in to Sypnia», «Check your email». It is the page's only h1. | ReactNode | |
topThe end of the top bar: a LanguageSwitch, a way back to the site. | ReactNode | |
width`sm` (26rem) for one or two fields, `md` (34rem) for longer forms and step-by-step tasks. | "sm" | "md" | sm |