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