@eifi1/ui-kit 0.28.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/README.md +22 -4
  2. package/dist/auth/accept-invitation.d.ts +90 -0
  3. package/dist/auth/accept-invitation.js +117 -0
  4. package/dist/auth/accept-invitation.js.map +1 -0
  5. package/dist/auth/auth-errors.d.ts +60 -0
  6. package/dist/auth/auth-errors.js +32 -0
  7. package/dist/auth/auth-errors.js.map +1 -0
  8. package/dist/auth/complete-name-dialog.d.ts +71 -0
  9. package/dist/auth/complete-name-dialog.js +168 -0
  10. package/dist/auth/complete-name-dialog.js.map +1 -0
  11. package/dist/auth/email-tag.d.ts +60 -0
  12. package/dist/auth/email-tag.js +23 -0
  13. package/dist/auth/email-tag.js.map +1 -0
  14. package/dist/auth/forgot-password-form.d.ts +79 -0
  15. package/dist/auth/forgot-password-form.js +120 -0
  16. package/dist/auth/forgot-password-form.js.map +1 -0
  17. package/dist/auth/form-rules.d.ts +27 -0
  18. package/dist/auth/form-rules.js +23 -0
  19. package/dist/auth/form-rules.js.map +1 -0
  20. package/dist/auth/new-password-fields.d.ts +38 -0
  21. package/dist/auth/new-password-fields.js +54 -0
  22. package/dist/auth/new-password-fields.js.map +1 -0
  23. package/dist/auth/not-found-page.d.ts +57 -0
  24. package/dist/auth/not-found-page.js +40 -0
  25. package/dist/auth/not-found-page.js.map +1 -0
  26. package/dist/auth/register-form.d.ts +86 -0
  27. package/dist/auth/register-form.js +268 -0
  28. package/dist/auth/register-form.js.map +1 -0
  29. package/dist/auth/reset-password-form.d.ts +124 -0
  30. package/dist/auth/reset-password-form.js +164 -0
  31. package/dist/auth/reset-password-form.js.map +1 -0
  32. package/dist/auth/sign-in-form.d.ts +243 -0
  33. package/dist/auth/sign-in-form.js +345 -0
  34. package/dist/auth/sign-in-form.js.map +1 -0
  35. package/dist/auth/status-parts.d.ts +78 -0
  36. package/dist/auth/status-parts.js +83 -0
  37. package/dist/auth/status-parts.js.map +1 -0
  38. package/dist/auth/verify-email.d.ts +121 -0
  39. package/dist/auth/verify-email.js +207 -0
  40. package/dist/auth/verify-email.js.map +1 -0
  41. package/dist/chart.d.ts +17 -2
  42. package/dist/components/amount-input.d.ts +18 -2
  43. package/dist/components/button-group.d.ts +18 -2
  44. package/dist/components/calculator.d.ts +18 -2
  45. package/dist/components/confirm-dialog.d.ts +18 -2
  46. package/dist/components/copy-button.d.ts +18 -2
  47. package/dist/components/danger-confirm.d.ts +18 -2
  48. package/dist/components/facing-pair.d.ts +18 -2
  49. package/dist/components/file-button.d.ts +18 -2
  50. package/dist/components/file-dropzone.d.ts +18 -2
  51. package/dist/components/form-actions.d.ts +18 -2
  52. package/dist/components/iban-input.d.ts +18 -2
  53. package/dist/components/language-select.d.ts +18 -9
  54. package/dist/components/legal-page.d.ts +26 -4
  55. package/dist/components/legal-page.js +24 -5
  56. package/dist/components/legal-page.js.map +1 -1
  57. package/dist/components/legal.d.ts +18 -2
  58. package/dist/components/legal.js +49 -5
  59. package/dist/components/legal.js.map +1 -1
  60. package/dist/components/money-field.d.ts +18 -2
  61. package/dist/components/number-field.d.ts +18 -2
  62. package/dist/components/number-input.d.ts +18 -2
  63. package/dist/components/numpad-sheet.d.ts +18 -2
  64. package/dist/components/phone-input.d.ts +18 -2
  65. package/dist/components/series-chart.d.ts +18 -2
  66. package/dist/components/settings-fields.d.ts +15 -2
  67. package/dist/components/share-card.d.ts +18 -2
  68. package/dist/components/text-link.d.ts +18 -2
  69. package/dist/components/time-input.d.ts +18 -2
  70. package/dist/components/ui.d.ts +17 -1
  71. package/dist/components/user-avatar.d.ts +16 -2
  72. package/dist/components/user-avatar.js +7 -3
  73. package/dist/components/user-avatar.js.map +1 -1
  74. package/dist/feedback/feedback-attachment.d.ts +18 -2
  75. package/dist/feedback/feedback-context.d.ts +18 -2
  76. package/dist/feedback/feedback-crash.d.ts +18 -2
  77. package/dist/feedback/feedback-dialog.d.ts +18 -2
  78. package/dist/feedback/feedback-inbox.d.ts +18 -2
  79. package/dist/feedback/feedback-labels.d.ts +18 -2
  80. package/dist/feedback/feedback-menu.d.ts +18 -2
  81. package/dist/feedback/feedback-record.d.ts +18 -2
  82. package/dist/feedback/feedback-row-detail.d.ts +18 -2
  83. package/dist/feedback/feedback-status-undo.d.ts +18 -2
  84. package/dist/feedback/feedback-submit.d.ts +18 -2
  85. package/dist/feedback/feedback-swipe.d.ts +18 -2
  86. package/dist/feedback/feedback-table.d.ts +18 -2
  87. package/dist/feedback/feedback-thread.d.ts +18 -2
  88. package/dist/feedback.d.ts +18 -2
  89. package/dist/hooks/use-file-drop.d.ts +18 -2
  90. package/dist/i18n/defaults.d.ts +18 -2
  91. package/dist/i18n/defaults.js +18 -0
  92. package/dist/i18n/defaults.js.map +1 -1
  93. package/dist/i18n/german.d.ts +18 -2
  94. package/dist/i18n/german.js +145 -0
  95. package/dist/i18n/german.js.map +1 -1
  96. package/dist/i18n/kit-labels.d.ts +18 -2
  97. package/dist/i18n/kit-labels.js.map +1 -1
  98. package/dist/i18n/languages.d.ts +13 -201
  99. package/dist/i18n/locales/de-CH.d.ts +18 -2
  100. package/dist/i18n/locales/en.d.ts +18 -2
  101. package/dist/i18n/locales/es.d.ts +18 -2
  102. package/dist/i18n/locales/es.js +147 -3
  103. package/dist/i18n/locales/es.js.map +1 -1
  104. package/dist/i18n/locales/fr.d.ts +18 -2
  105. package/dist/i18n/locales/fr.js +147 -0
  106. package/dist/i18n/locales/fr.js.map +1 -1
  107. package/dist/i18n/locales/hu.d.ts +18 -2
  108. package/dist/i18n/locales/hu.js +149 -3
  109. package/dist/i18n/locales/hu.js.map +1 -1
  110. package/dist/i18n/locales/it.d.ts +18 -2
  111. package/dist/i18n/locales/it.js +146 -1
  112. package/dist/i18n/locales/it.js.map +1 -1
  113. package/dist/i18n/locales/zh.d.ts +18 -2
  114. package/dist/i18n/locales/zh.js +146 -1
  115. package/dist/i18n/locales/zh.js.map +1 -1
  116. package/dist/i18n/review.d.ts +18 -2
  117. package/dist/i18n/review.js +17 -7
  118. package/dist/i18n/review.js.map +1 -1
  119. package/dist/index.d.ts +13 -2
  120. package/dist/index.js +49 -1
  121. package/dist/index.js.map +1 -1
  122. package/dist/lib/person-name.d.ts +69 -0
  123. package/dist/lib/person-name.js +65 -0
  124. package/dist/lib/person-name.js.map +1 -0
  125. package/dist/{kit-labels-SBN0biPl.d.ts → register-form-V1OeNlMr.d.ts} +423 -6
  126. package/dist/rhf/fields.d.ts +18 -2
  127. package/dist/rhf/form.d.ts +18 -2
  128. package/dist/rhf.d.ts +18 -2
  129. package/dist/shell/app-shell.d.ts +18 -2
  130. package/dist/shell/company-switcher.d.ts +59 -0
  131. package/dist/shell/company-switcher.js +85 -0
  132. package/dist/shell/company-switcher.js.map +1 -0
  133. package/dist/shell/top-bar-brand.d.ts +18 -2
  134. package/dist/shell/topbar-action-menu.d.ts +1 -0
  135. package/dist/shell.d.ts +12 -2
  136. package/dist/wizard/stepper-nav.d.ts +18 -2
  137. package/dist/wizard.d.ts +18 -2
  138. package/package.json +1 -1
  139. package/src/auth/accept-invitation.tsx +227 -0
  140. package/src/auth/auth-errors.ts +105 -0
  141. package/src/auth/complete-name-dialog.tsx +253 -0
  142. package/src/auth/email-tag.ts +75 -0
  143. package/src/auth/forgot-password-form.tsx +213 -0
  144. package/src/auth/form-rules.ts +40 -0
  145. package/src/auth/new-password-fields.tsx +85 -0
  146. package/src/auth/not-found-page.tsx +98 -0
  147. package/src/auth/register-form.tsx +459 -0
  148. package/src/auth/reset-password-form.tsx +337 -0
  149. package/src/auth/sign-in-form.tsx +687 -0
  150. package/src/auth/status-parts.tsx +138 -0
  151. package/src/auth/verify-email.tsx +358 -0
  152. package/src/components/legal-page.tsx +35 -0
  153. package/src/components/legal.tsx +93 -7
  154. package/src/components/user-avatar.tsx +22 -4
  155. package/src/i18n/defaults.ts +18 -0
  156. package/src/i18n/german.ts +153 -0
  157. package/src/i18n/kit-labels.tsx +27 -0
  158. package/src/i18n/locales/es.ts +156 -3
  159. package/src/i18n/locales/fr.ts +157 -0
  160. package/src/i18n/locales/hu.ts +159 -3
  161. package/src/i18n/locales/it.ts +154 -1
  162. package/src/i18n/locales/zh.ts +149 -1
  163. package/src/i18n/review.ts +15 -6
  164. package/src/index.ts +63 -1
  165. package/src/lib/person-name.ts +157 -0
  166. package/src/shell/company-switcher.tsx +140 -0
@@ -0,0 +1,459 @@
1
+ import { useEffect, useId, useRef, useState } from "react";
2
+ import type { ComponentPropsWithoutRef, FormEvent, ReactNode } from "react";
3
+
4
+ import { useKitLabels, useKitLocale } from "../i18n/kit-labels";
5
+ import { KIT_LANGUAGES, resolveLanguage } from "../i18n/languages";
6
+ import type { KitLanguageCode } from "../i18n/languages";
7
+ import { cn } from "../lib/cn";
8
+ import { AlertBanner } from "../components/alert-banner";
9
+ import { hasMessage } from "../components/choice-parts";
10
+ import { LanguageSelect } from "../components/language-select";
11
+ import { LegalAcceptCheckbox } from "../components/legal-page";
12
+ import { TextLink } from "../components/text-link";
13
+ import { Button, Input } from "../components/ui";
14
+ import { authErrorCode } from "./auth-errors";
15
+ import { emailParts, taggedEmail } from "./email-tag";
16
+ import { newPasswordProblem, personNameOk, PERSON_NAME_MAX_LENGTH } from "./form-rules";
17
+ import { NewPasswordFields } from "./new-password-fields";
18
+
19
+ /** What `RegisterForm` hands `onSubmit` — the core of `POST /auth/register` (§4.2). The
20
+ * app adds its own fields (kastlan's company, keksdose's currency) and the
21
+ * `invite_token` it read from the URL. */
22
+ export interface RegisterValues {
23
+ /** Trimmed, 1–120 characters. */
24
+ firstName: string;
25
+ /** Trimmed, 1–120 characters. */
26
+ lastName: string;
27
+ /** Trimmed. Lower-casing is the server's (§3.1); a tag is never stripped (§4.5). */
28
+ email: string;
29
+ /** As typed: at least 8 characters, at most 72 bytes. */
30
+ password: string;
31
+ /** The language picked — one of `languages` — for every mail to the user (§3.1). */
32
+ locale: KitLanguageCode;
33
+ }
34
+
35
+ /**
36
+ * Every string `RegisterForm` renders — the `register` namespace of `<UiKitProvider
37
+ * labels>`, overridable per instance through `labels`. keksdose's words where it has
38
+ * them. The terms checkbox speaks `legal.accept`, the strength meter `passwordStrength`.
39
+ */
40
+ export interface RegisterLabels {
41
+ firstName: string;
42
+ lastName: string;
43
+ email: string;
44
+ /** The address-tag button (§4.5), given the exact address it would use — and, with an
45
+ * invitation, the button back to the invited address. */
46
+ emailTagUse: (address: string) => string;
47
+ /** The line after the address-tag button. */
48
+ emailTagHint: string;
49
+ /** Under an invited (read-only) email field. */
50
+ invitedEmailHint: string;
51
+ /** Once the invitee took the tagged address: it is not the invited one, so it is
52
+ * confirmed by a mail of its own (§4.3). */
53
+ invitedTagNote: string;
54
+ password: string;
55
+ confirmPassword: string;
56
+ passwordMismatch: string;
57
+ language: string;
58
+ /** The submit button. */
59
+ submit: string;
60
+ /** Before the link to `signInHref`. */
61
+ haveAccount: string;
62
+ /** The link to `signInHref`. */
63
+ signIn: string;
64
+ /** `email_taken`, under the email field. */
65
+ emailTaken: string;
66
+ /** `registration_closed` — the gate refused the address (§4.3). */
67
+ registrationClosed: string;
68
+ /** `invitation_invalid` — the invitation link is unknown or spent. */
69
+ invitationInvalid: string;
70
+ /** `invitation_expired`. */
71
+ invitationExpired: string;
72
+ /** Any other failure. */
73
+ failed: string;
74
+ }
75
+
76
+ export const DEFAULT_REGISTER_LABELS: RegisterLabels = {
77
+ firstName: "First name",
78
+ lastName: "Last name",
79
+ email: "Email",
80
+ emailTagUse: (address) => `Use ${address}`,
81
+ emailTagHint:
82
+ "Many providers deliver name+tag@… to the same inbox, so mail from this app is easy to filter and trace. Check yours does before you rely on it: you would sign in with the tagged address.",
83
+ invitedEmailHint: "The address your invitation was sent to.",
84
+ invitedTagNote: "The tagged address gets a confirmation mail of its own.",
85
+ password: "Password",
86
+ confirmPassword: "Repeat password",
87
+ passwordMismatch: "The passwords don't match.",
88
+ language: "Language",
89
+ submit: "Create account",
90
+ haveAccount: "Already have an account?",
91
+ signIn: "Sign in",
92
+ emailTaken: "An account with this email address already exists.",
93
+ registrationClosed: "New accounts are by invitation only. Ask the operator to invite your email address.",
94
+ invitationInvalid: "This invitation link is not valid.",
95
+ invitationExpired: "This invitation has expired. Ask for a new one.",
96
+ failed: "Registration failed. Please try again.",
97
+ };
98
+
99
+ export interface RegisterFormProps extends Omit<ComponentPropsWithoutRef<"div">, "onSubmit" | "children"> {
100
+ /**
101
+ * The form was submitted with everything filled in. Send it (`POST /auth/register`,
102
+ * §4.2) and resolve once the user is signed in, or reject with the client's error:
103
+ * `email_taken` shows under the email field, `registration_closed` and the
104
+ * invitation codes above the button, anything else as "Registration failed". The form
105
+ * never sends a request itself (§8): keksdose must see the password on its way.
106
+ *
107
+ * On resolve the form stays busy while the app navigates.
108
+ */
109
+ onSubmit: (values: RegisterValues) => Promise<unknown>;
110
+ /**
111
+ * The app's address tag (`"kastlan"`, §4.5). Once the email is plausible, a button
112
+ * under it offers the tagged address — "Use ada+kastlan@example.com" — with a line on
113
+ * why; one click puts it in the field. Never applied on its own. Left out, no offer.
114
+ */
115
+ emailTag?: string;
116
+ /**
117
+ * The address of the invitation this sign-up comes from (§4.4): the field starts with
118
+ * it and is read-only. With `emailTag`, the invitee may still take the tagged form of
119
+ * it — the server accepts exactly that variant — and go back.
120
+ */
121
+ invitedEmail?: string;
122
+ /**
123
+ * The language field's value — controlled. Pass the app's UI language
124
+ * (`i18n.resolvedLanguage`) with `onLocaleChange` switching it, and the field IS the
125
+ * app's language switch, with no copy of its own to drift from a second switcher on
126
+ * the page (keksdose's register page has one in its header). Any tag; it shows (and
127
+ * submits) the offered code it resolves to. Left out, the form keeps its own, starting
128
+ * from `defaultLocale`, else the provider's language, else the browser's.
129
+ */
130
+ locale?: string;
131
+ /** The uncontrolled language field's start value. */
132
+ defaultLocale?: string;
133
+ /** A language was picked. */
134
+ onLocaleChange?: (code: KitLanguageCode) => void;
135
+ /** The languages to offer, in order. Default all seven. */
136
+ languages?: readonly KitLanguageCode[];
137
+ /**
138
+ * The app's own language field in place of the kit's select — keksdose's
139
+ * `LanguageSetting` bound to its i18n. `null` draws none (an app with one language);
140
+ * the submitted `locale` is then `locale`'s.
141
+ */
142
+ languageField?: ReactNode;
143
+ /** Above the form — keksdose's closed-beta banner. */
144
+ aboveForm?: ReactNode;
145
+ /** Under the email field and its tag offer — an app's own hint. */
146
+ underEmail?: ReactNode;
147
+ /** The app's sign-up fields (§4.1 item 7): kastlan's Company, keksdose's reporting
148
+ * currency. Their values are the app's; say whether they are complete with
149
+ * `appFieldsComplete`. */
150
+ appFields?: ReactNode;
151
+ /** After the app fields, before the terms — keksdose's privacy-mode note. */
152
+ afterFields?: ReactNode;
153
+ /** Whether the app fields are filled in as required — kastlan's Company without an
154
+ * invitation. The submit waits for it. Default `true`. */
155
+ appFieldsComplete?: boolean;
156
+ /** The terms checkbox's links. Default `/terms` and `/privacy`. */
157
+ termsHref?: string;
158
+ privacyHref?: string;
159
+ /** "Already have an account? Sign in" goes here — `/login`. Left out, no line. */
160
+ signInHref?: string;
161
+ /** The app's own words for a failure the kit cannot know (a throttled attempt), or
162
+ * `undefined` for the kit's. Asked first, for every failure. */
163
+ describeError?: (error: unknown) => ReactNode | undefined;
164
+ labels?: Partial<RegisterLabels>;
165
+ }
166
+
167
+ const ALL_CODES: readonly KitLanguageCode[] = KIT_LANGUAGES.map((language) => language.code);
168
+
169
+ /** The browser's languages, in its order — absent outside a browser. */
170
+ function browserLanguages(): readonly string[] {
171
+ if (typeof navigator === "undefined") return [];
172
+ return navigator.languages?.length ? navigator.languages : [navigator.language];
173
+ }
174
+
175
+ type Busy = "sending" | "done" | null;
176
+
177
+ /**
178
+ * Sign-up for every app (docs/auth-harmonization.md §4.1, §8): first and last name,
179
+ * email with the address-tag offer, password with the strength meter and its
180
+ * confirmation, language, the app's own fields in a slot, and the terms. keksdose's
181
+ * `RegisterPage` (features/auth/register-page.tsx) with its slots made props.
182
+ *
183
+ * **It never sends a request.** `onSubmit` gets the values; what the request carries
184
+ * besides them (kastlan's company, keksdose's currency, the `invite_token`) is the
185
+ * app's, as are the role and the associations, which never come from the form (§4.3).
186
+ *
187
+ * **The submit waits for a complete form**: both names (1–120 characters after
188
+ * trimming), a plausible address, a password of at least 8 characters and at most 72
189
+ * bytes, the same password again, the terms ticked, and `appFieldsComplete`. Nothing
190
+ * else is a rule — the strength checklist is advice (keksdose #124), and the kit adds
191
+ * none of its own (§8). So there is never a failed attempt for a missing field, and no
192
+ * field error to show for one.
193
+ *
194
+ * **The address tag** (§4.5) is offered under the email field as one click with the
195
+ * exact result on the button, never applied: sub-addressing is a convention the
196
+ * receiving server may or may not implement, and a silent rewrite would send the
197
+ * verification mail down a path nobody checked. With an invitation the field is fixed
198
+ * to the invited address; the invitee may still take its tagged form, and is told it
199
+ * will be confirmed by a mail of its own (§4.3).
200
+ *
201
+ * **Refusals** are read by code ({@link authErrorCode}): `email_taken` under the email
202
+ * field, which takes the focus; `registration_closed`, `invitation_invalid` and
203
+ * `invitation_expired` above the button; anything else as "Registration failed", unless
204
+ * `describeError` has the app's words.
205
+ *
206
+ * Laid out for a 390 px phone: the names sit side by side only where the form is at
207
+ * least 20rem wide (a container query), which the narrow `AuthLayout` card is on a
208
+ * desktop and a phone is not.
209
+ */
210
+ export function RegisterForm({
211
+ onSubmit,
212
+ emailTag,
213
+ invitedEmail,
214
+ locale: localeProp,
215
+ defaultLocale,
216
+ onLocaleChange,
217
+ languages = ALL_CODES,
218
+ languageField,
219
+ aboveForm,
220
+ underEmail,
221
+ appFields,
222
+ afterFields,
223
+ appFieldsComplete = true,
224
+ termsHref,
225
+ privacyHref,
226
+ signInHref,
227
+ describeError,
228
+ labels: labelsProp,
229
+ className,
230
+ ...rest
231
+ }: RegisterFormProps) {
232
+ const labels = useKitLabels("register", DEFAULT_REGISTER_LABELS, labelsProp);
233
+ const kitLocale = useKitLocale();
234
+ const invited = invitedEmail !== undefined;
235
+ const [firstName, setFirstName] = useState("");
236
+ const [lastName, setLastName] = useState("");
237
+ const [email, setEmail] = useState(invitedEmail ?? "");
238
+ const [password, setPassword] = useState("");
239
+ const [confirm, setConfirm] = useState("");
240
+ const [ownLocale, setOwnLocale] = useState<string>(
241
+ () => defaultLocale ?? resolveLanguage([kitLocale, ...browserLanguages()], languages),
242
+ );
243
+ const [accepted, setAccepted] = useState(false);
244
+ const [busy, setBusy] = useState<Busy>(null);
245
+ // `email_taken` belongs to the address it was answered for; another one clears it.
246
+ const [taken, setTaken] = useState<string | null>(null);
247
+ const [failure, setFailure] = useState<ReactNode>(null);
248
+ const emailRef = useRef<HTMLInputElement>(null);
249
+ const tagHintId = useId();
250
+
251
+ const mounted = useRef(true);
252
+ useEffect(() => {
253
+ mounted.current = true;
254
+ return () => {
255
+ mounted.current = false;
256
+ };
257
+ }, []);
258
+
259
+ // What the field shows is what is submitted: the offered code the value resolves to.
260
+ const locale = resolveLanguage([localeProp ?? ownLocale], languages);
261
+ const changeLocale = (code: KitLanguageCode) => {
262
+ if (localeProp === undefined) setOwnLocale(code);
263
+ onLocaleChange?.(code);
264
+ };
265
+
266
+ const working = busy !== null;
267
+ const suggestion = emailTag ? taggedEmail(email, emailTag) : null;
268
+ // The invitee took the tagged address: offer the way back to the invited one.
269
+ const backToInvited =
270
+ invitedEmail !== undefined && email.trim() !== invitedEmail.trim() ? invitedEmail.trim() : null;
271
+ const canSubmit =
272
+ personNameOk(firstName) &&
273
+ personNameOk(lastName) &&
274
+ emailParts(email) !== null &&
275
+ newPasswordProblem(password, confirm) === null &&
276
+ accepted &&
277
+ appFieldsComplete;
278
+
279
+ const submit = (e: FormEvent) => {
280
+ e.preventDefault();
281
+ if (!canSubmit || working) return;
282
+ const values: RegisterValues = {
283
+ firstName: firstName.trim(),
284
+ lastName: lastName.trim(),
285
+ email: email.trim(),
286
+ password,
287
+ locale,
288
+ };
289
+ setBusy("sending");
290
+ setFailure(null);
291
+ setTaken(null);
292
+ let result: Promise<unknown>;
293
+ try {
294
+ result = Promise.resolve(onSubmit(values));
295
+ } catch (error) {
296
+ result = Promise.reject(error);
297
+ }
298
+ result.then(
299
+ () => {
300
+ if (mounted.current) setBusy("done");
301
+ },
302
+ (error: unknown) => {
303
+ if (!mounted.current) return;
304
+ setBusy(null);
305
+ const own = describeError?.(error);
306
+ const code = authErrorCode(error);
307
+ if (code === "email_taken" && !hasMessage(own)) {
308
+ setTaken(values.email);
309
+ emailRef.current?.focus();
310
+ return;
311
+ }
312
+ setFailure(
313
+ hasMessage(own)
314
+ ? own
315
+ : code === "registration_closed"
316
+ ? labels.registrationClosed
317
+ : code === "invitation_invalid"
318
+ ? labels.invitationInvalid
319
+ : code === "invitation_expired"
320
+ ? labels.invitationExpired
321
+ : labels.failed,
322
+ );
323
+ },
324
+ );
325
+ };
326
+
327
+ return (
328
+ <div {...rest} className={cn("@container space-y-4", className)}>
329
+ {aboveForm}
330
+ <form className="space-y-3" noValidate onSubmit={submit}>
331
+ <div className="grid gap-3 @xs:grid-cols-2">
332
+ <Input
333
+ name="given-name"
334
+ autoComplete="given-name"
335
+ label={labels.firstName}
336
+ value={firstName}
337
+ onChange={(e) => setFirstName(e.target.value)}
338
+ maxLength={PERSON_NAME_MAX_LENGTH}
339
+ readOnly={working}
340
+ required
341
+ />
342
+ <Input
343
+ name="family-name"
344
+ autoComplete="family-name"
345
+ label={labels.lastName}
346
+ value={lastName}
347
+ onChange={(e) => setLastName(e.target.value)}
348
+ maxLength={PERSON_NAME_MAX_LENGTH}
349
+ readOnly={working}
350
+ required
351
+ />
352
+ </div>
353
+
354
+ <div>
355
+ <Input
356
+ ref={emailRef}
357
+ type="email"
358
+ name="email"
359
+ autoComplete="email"
360
+ label={labels.email}
361
+ value={email}
362
+ onChange={(e) => setEmail(e.target.value)}
363
+ readOnly={invited || working}
364
+ hint={invited ? labels.invitedEmailHint : undefined}
365
+ error={taken !== null && taken === email.trim() ? labels.emailTaken : undefined}
366
+ required
367
+ />
368
+ {/* The tag, offered rather than applied (§4.5): one click, the exact address
369
+ on the button, reversible by typing — or, invited, by the button back. */}
370
+ {suggestion && (
371
+ <p className="mt-1 text-xs text-[var(--text-muted)]">
372
+ <Button
373
+ type="button"
374
+ variant="link"
375
+ size="sm"
376
+ className="h-auto p-0 align-baseline"
377
+ disabled={working}
378
+ aria-describedby={tagHintId}
379
+ onClick={() => setEmail(suggestion)}
380
+ >
381
+ {labels.emailTagUse(suggestion)}
382
+ </Button>{" "}
383
+ <span id={tagHintId}>{labels.emailTagHint}</span>
384
+ </p>
385
+ )}
386
+ {backToInvited !== null && (
387
+ <p className="mt-1 text-xs text-[var(--text-muted)]">
388
+ <span>{labels.invitedTagNote}</span>{" "}
389
+ <Button
390
+ type="button"
391
+ variant="link"
392
+ size="sm"
393
+ className="h-auto p-0 align-baseline"
394
+ disabled={working}
395
+ onClick={() => setEmail(backToInvited)}
396
+ >
397
+ {labels.emailTagUse(backToInvited)}
398
+ </Button>
399
+ </p>
400
+ )}
401
+ {underEmail}
402
+ </div>
403
+
404
+ <NewPasswordFields
405
+ password={password}
406
+ confirm={confirm}
407
+ onPasswordChange={setPassword}
408
+ onConfirmChange={setConfirm}
409
+ busy={working}
410
+ text={{ password: labels.password, confirm: labels.confirmPassword, mismatch: labels.passwordMismatch }}
411
+ />
412
+
413
+ {languageField === undefined ? (
414
+ <LanguageSelect
415
+ name="locale"
416
+ label={labels.language}
417
+ value={locale}
418
+ codes={languages}
419
+ onChange={changeLocale}
420
+ disabled={working}
421
+ />
422
+ ) : (
423
+ languageField
424
+ )}
425
+
426
+ {appFields}
427
+ {afterFields}
428
+
429
+ {/* The kit's terms checkbox (legal contract §3.4). Never an error: an unticked
430
+ box keeps the submit disabled, so there is no failed attempt to explain. */}
431
+ <LegalAcceptCheckbox
432
+ checked={accepted}
433
+ onCheckedChange={setAccepted}
434
+ termsHref={termsHref}
435
+ privacyHref={privacyHref}
436
+ disabled={working}
437
+ />
438
+
439
+ {hasMessage(failure) && (
440
+ <AlertBanner tone="danger" size="sm" role="alert">
441
+ {failure}
442
+ </AlertBanner>
443
+ )}
444
+
445
+ <Button type="submit" className="w-full" disabled={!working && !canSubmit} pending={working}>
446
+ {labels.submit}
447
+ </Button>
448
+ </form>
449
+ {signInHref !== undefined && (
450
+ <p className="text-center text-sm text-[var(--text-secondary)]">
451
+ {labels.haveAccount}{" "}
452
+ <TextLink href={signInHref} tone="primary">
453
+ {labels.signIn}
454
+ </TextLink>
455
+ </p>
456
+ )}
457
+ </div>
458
+ );
459
+ }