@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,253 @@
1
+ import { useContext, useEffect, useId, useRef, useState } from "react";
2
+ import type { KeyboardEvent, ReactNode } from "react";
3
+
4
+ import { useKitLabels } from "../i18n/kit-labels";
5
+ import { usePromisePending } from "../components/danger-confirm";
6
+ import { DialogFrame } from "../components/dialog-frame";
7
+ import { ModalCloseContext } from "../components/modal";
8
+ import { Button, Input } from "../components/ui";
9
+ import { personNameOk, PERSON_NAME_MAX_LENGTH } from "./form-rules";
10
+
11
+ /** What `CompleteNameDialog` hands `onSave`: both names, trimmed, 1–120 characters —
12
+ * `PATCH /auth/me {first_name, last_name}` (§6.1). */
13
+ export interface CompleteNameValues {
14
+ firstName: string;
15
+ lastName: string;
16
+ }
17
+
18
+ /**
19
+ * Every string the dialog renders — the `completeName` namespace of `<UiKitProvider
20
+ * labels>`, overridable per instance through `labels`.
21
+ */
22
+ export interface CompleteNameLabels {
23
+ title: string;
24
+ description: string;
25
+ firstName: string;
26
+ lastName: string;
27
+ save: string;
28
+ /** Dismisses the dialog until the next sign-in. */
29
+ later: string;
30
+ /** Under the fields when `onSave` rejected and the app passed no `error`. */
31
+ failed: string;
32
+ }
33
+
34
+ export const DEFAULT_COMPLETE_NAME_LABELS: CompleteNameLabels = {
35
+ title: "Complete your name",
36
+ description: "First and last name are now asked for separately. Check what is filled in and add what is missing.",
37
+ firstName: "First name",
38
+ lastName: "Last name",
39
+ save: "Save",
40
+ later: "Later",
41
+ failed: "Your name could not be saved. Please try again.",
42
+ };
43
+
44
+ export interface CompleteNameDialogProps {
45
+ /** What the account holds now — after the migration, the old display name (§3.3). */
46
+ firstName?: string;
47
+ /** Usually empty: that is why the dialog is up. */
48
+ lastName?: string;
49
+ /**
50
+ * Save the names (`PATCH /auth/me`). Resolve and the dialog closes (`onClose(true)`);
51
+ * reject and it stays open with the names kept and `error` — or "Your name could not
52
+ * be saved" — under them.
53
+ */
54
+ onSave: (values: CompleteNameValues) => Promise<unknown>;
55
+ /**
56
+ * The dialog has closed: `true` after a resolved `onSave`, `false` for "Later", Escape,
57
+ * the backdrop and Back. `false` only DEFERS it: the app shows it again after the
58
+ * next sign-in while `/auth/me` still answers `name_incomplete: true`.
59
+ */
60
+ onClose: (saved: boolean) => void;
61
+ /** The app's words for the last failed save, instead of `labels.failed`. Hidden again
62
+ * once a name is edited. */
63
+ error?: ReactNode;
64
+ /** Kept-mounted mode, as on `Modal`: left out, the dialog is open while mounted. */
65
+ open?: boolean;
66
+ labels?: Partial<CompleteNameLabels>;
67
+ }
68
+
69
+ /**
70
+ * "Complete your name" — asked once after sign-in of a user whose name was migrated
71
+ * (docs/auth-harmonization.md §3.3). keksdose's and Kurvenschmiede's accounts had one
72
+ * `display_name`; it moved whole into `first_name`, `last_name` stayed empty, and
73
+ * nothing was split by guesswork (§2.4). The app shows this while `/auth/me` answers
74
+ * `name_incomplete: true` — never for a demo user.
75
+ *
76
+ * Both names prefilled with what is there; "Save" waits until both have 1–120
77
+ * characters after trimming. **"Later" only defers it**: nothing else waits on a
78
+ * complete name, no page is blocked, and the app asks again at the next sign-in.
79
+ *
80
+ * The promise handling is `ReauthDialog`'s: busy while `onSave` runs (the fields
81
+ * read-only, "Later" disabled, Escape held — a request that has left cannot be called
82
+ * back by closing the dialog), closed on resolve, kept open on reject. Save is a
83
+ * `commit` control, so a `WriteLockProvider` above it locks it with its reason.
84
+ *
85
+ * Focus starts in the first EMPTY field — the last name, as a rule — because filling it
86
+ * in is the whole of what the dialog is for.
87
+ */
88
+ export function CompleteNameDialog({
89
+ firstName: initialFirst = "",
90
+ lastName: initialLast = "",
91
+ onSave,
92
+ onClose,
93
+ error,
94
+ open,
95
+ labels: labelsProp,
96
+ }: CompleteNameDialogProps) {
97
+ const labels = useKitLabels("completeName", DEFAULT_COMPLETE_NAME_LABELS, labelsProp);
98
+ const [first, setFirst] = useState(initialFirst);
99
+ const [last, setLast] = useState(initialLast);
100
+ // A failed save describes the names that were sent; an edit makes it stale.
101
+ const [failed, setFailed] = useState(false);
102
+ const { pending, run } = usePromisePending();
103
+ const [done, setDone] = useState(false);
104
+ const saved = useRef(false);
105
+ const formId = useId();
106
+ const firstRef = useRef<HTMLInputElement>(null);
107
+ const lastRef = useRef<HTMLInputElement>(null);
108
+ const isOpen = open ?? true;
109
+
110
+ // Reopened (kept-mounted): start again from what the account holds. During render,
111
+ // as ReauthDialog wipes its password, so no frame shows the old draft.
112
+ const [wasOpen, setWasOpen] = useState(isOpen);
113
+ if (wasOpen !== isOpen) {
114
+ setWasOpen(isOpen);
115
+ if (isOpen) {
116
+ setFirst(initialFirst);
117
+ setLast(initialLast);
118
+ setFailed(false);
119
+ setDone(false);
120
+ }
121
+ }
122
+
123
+ // After Modal's own effect, so its trap has recorded the trigger before focus moves.
124
+ useEffect(() => {
125
+ if (!isOpen) return;
126
+ saved.current = false;
127
+ const target = firstRef.current?.value.trim() ? lastRef.current : firstRef.current;
128
+ target?.focus();
129
+ }, [isOpen]);
130
+
131
+ const canSave = personNameOk(first) && personNameOk(last);
132
+
133
+ const submit = () => {
134
+ if (pending || !canSave) return;
135
+ setFailed(false);
136
+ const values = { firstName: first.trim(), lastName: last.trim() };
137
+ let result: Promise<unknown>;
138
+ try {
139
+ result = Promise.resolve(onSave(values));
140
+ } catch (err) {
141
+ result = Promise.reject(err);
142
+ }
143
+ // A rejection must not go unhandled; usePromisePending clears `pending` on it.
144
+ result.catch(() => setFailed(true));
145
+ run(result, () => {
146
+ saved.current = true;
147
+ setDone(true);
148
+ });
149
+ };
150
+
151
+ const edit = (set: (value: string) => void) => (value: string) => {
152
+ set(value);
153
+ setFailed(false);
154
+ };
155
+
156
+ const message = failed ? (error ?? labels.failed) : undefined;
157
+
158
+ return (
159
+ <DialogFrame
160
+ open={open}
161
+ title={labels.title}
162
+ description={labels.description}
163
+ onClose={() => onClose(saved.current)}
164
+ onKeyDown={(e: KeyboardEvent<HTMLDivElement>) => {
165
+ if (pending && e.key === "Escape") e.preventDefault();
166
+ }}
167
+ aria-busy={pending || undefined}
168
+ actions={
169
+ <CompleteNameActions
170
+ formId={formId}
171
+ done={done}
172
+ busy={pending}
173
+ canSave={canSave}
174
+ laterLabel={labels.later}
175
+ saveLabel={labels.save}
176
+ />
177
+ }
178
+ >
179
+ <form
180
+ id={formId}
181
+ noValidate
182
+ className="grid gap-3 @container"
183
+ onSubmit={(e) => {
184
+ e.preventDefault();
185
+ submit();
186
+ }}
187
+ >
188
+ <div className="grid gap-3 @xs:grid-cols-2">
189
+ <Input
190
+ ref={firstRef}
191
+ name="given-name"
192
+ autoComplete="given-name"
193
+ label={labels.firstName}
194
+ value={first}
195
+ onChange={(e) => edit(setFirst)(e.target.value)}
196
+ maxLength={PERSON_NAME_MAX_LENGTH}
197
+ readOnly={pending}
198
+ required
199
+ />
200
+ <Input
201
+ ref={lastRef}
202
+ name="family-name"
203
+ autoComplete="family-name"
204
+ label={labels.lastName}
205
+ value={last}
206
+ onChange={(e) => edit(setLast)(e.target.value)}
207
+ maxLength={PERSON_NAME_MAX_LENGTH}
208
+ readOnly={pending}
209
+ required
210
+ />
211
+ </div>
212
+ {message !== undefined && (
213
+ <p role="alert" className="text-xs text-[var(--danger)]">
214
+ {message}
215
+ </p>
216
+ )}
217
+ </form>
218
+ </DialogFrame>
219
+ );
220
+ }
221
+
222
+ /** The actions row, inside the `Modal`, where its animated close is in context: a
223
+ * resolved save lowers the panel through it, as "Later" and Escape do. */
224
+ function CompleteNameActions({
225
+ formId,
226
+ done,
227
+ busy,
228
+ canSave,
229
+ laterLabel,
230
+ saveLabel,
231
+ }: {
232
+ formId: string;
233
+ done: boolean;
234
+ busy: boolean;
235
+ canSave: boolean;
236
+ laterLabel: string;
237
+ saveLabel: string;
238
+ }) {
239
+ const close = useContext(ModalCloseContext);
240
+ useEffect(() => {
241
+ if (done) close?.();
242
+ }, [done, close]);
243
+ return (
244
+ <>
245
+ <Button type="button" variant="ghost" disabled={busy} onClick={() => close?.()}>
246
+ {laterLabel}
247
+ </Button>
248
+ <Button type="submit" form={formId} commit disabled={!busy && !canSave} pending={busy}>
249
+ {saveLabel}
250
+ </Button>
251
+ </>
252
+ );
253
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The address tag: `you@example.com` → `you+kastlan@example.com`, the app's own name as
3
+ * a sub-address of the address a person types for themselves (docs/auth-harmonization.md
4
+ * §4.5, Marcel 2026-10-05). Lifted from keksdose (`features/auth/email-tag.ts`, feedback
5
+ * dev#481), where the tag was the constant `keksdose`; here it is the app's.
6
+ *
7
+ * **Structurally valid is not the same as deliverable.** `+` is an ordinary character in
8
+ * the local part under RFC 5322, and sub-addressing — `user+tag@host` delivered to
9
+ * `user@host` — is specified (RFC 5233). But it is specified as a convention the
10
+ * RECEIVING server may implement: Gmail, Outlook, iCloud, Fastmail and Proton do; many
11
+ * Exchange installs, small hosters and corporate filters do not, and some web forms
12
+ * refuse the character outright.
13
+ *
14
+ * Which is why every caller OFFERS the result and never applies it. Silently registering
15
+ * somebody as `you+kastlan@example.com` would send the verification mail — the one
16
+ * message the account depends on — down a delivery path nobody checked, and make the
17
+ * address they sign in with one they never typed. The tag is a convenience for the
18
+ * person who wants it: one click, with the exact resulting address on the button
19
+ * (`RegisterForm` does this with its `emailTag`).
20
+ *
21
+ * The tagged address is then the identity. The server trims and lower-cases an address
22
+ * at every entry and never strips a tag, so `you@…` and `you+kastlan@…` are two
23
+ * different accounts; sign-in stays exact (§4.5), which is why `SignInForm`'s hint after
24
+ * a failed sign-in names the tagged address rather than trying it.
25
+ *
26
+ * Offer it only where a person types an address FOR THEMSELVES — sign-up, a later email
27
+ * change in the profile — never in a field for someone else's (an invite dialog, a
28
+ * share), where the tag would be a guess about another person's mail server.
29
+ */
30
+
31
+ /** What a tag may be: the app's name, lower case — letters, digits, `.`, `_`, `-`. A
32
+ * space, `@` or `+` would make the result something other than a sub-address. */
33
+ const TAG_SHAPE = /^[a-z0-9][a-z0-9._-]*$/;
34
+
35
+ /**
36
+ * `taggedEmail("you@example.com", "kastlan")` → `"you+kastlan@example.com"`, or `null`
37
+ * when there is nothing to offer:
38
+ *
39
+ * - the address is not complete enough to split — no local part, no domain, or a
40
+ * domain without an inner dot (the shape the field's own `type="email"` accepts), so
41
+ * the offer cannot appear before the address is plausible or linger once it stops
42
+ * being one;
43
+ * - the address already carries a `+` — the person's own scheme wins, and stacking a
44
+ * second tag on it would be wrong;
45
+ * - the tag is empty or not a plain name (see `TAG_SHAPE`).
46
+ *
47
+ * The tag is the app's name in lower case (`keksdose`, `kastlan`, `kurvenschmiede`); it
48
+ * is trimmed and lower-cased here, so `"Kastlan"` gives the same answer. The address is
49
+ * trimmed and otherwise kept as typed — normalising it is the server's job (server-kit's
50
+ * `normalise_email`).
51
+ */
52
+ export function taggedEmail(email: string, tag: string): string | null {
53
+ const name = tag.trim().toLowerCase();
54
+ if (!TAG_SHAPE.test(name)) return null;
55
+ const parts = emailParts(email);
56
+ if (!parts || parts.local.includes("+")) return null;
57
+ return `${parts.local}+${name}@${parts.domain}`;
58
+ }
59
+
60
+ /**
61
+ * The trimmed address split at its last `@`, or `null` while it is not complete enough
62
+ * to split: no local part, no domain, or a domain without an inner dot — the shape the
63
+ * field's own `type="email"` accepts.
64
+ *
65
+ * @internal `RegisterForm` gates its submit on it; not part of the barrel.
66
+ */
67
+ export function emailParts(email: string): { local: string; domain: string } | null {
68
+ const trimmed = email.trim();
69
+ const at = trimmed.lastIndexOf("@");
70
+ if (at <= 0 || at === trimmed.length - 1) return null;
71
+ const local = trimmed.slice(0, at);
72
+ const domain = trimmed.slice(at + 1);
73
+ if (!domain.includes(".") || domain.startsWith(".") || domain.endsWith(".")) return null;
74
+ return { local, domain };
75
+ }
@@ -0,0 +1,229 @@
1
+ import { useId, useRef, useState } from "react";
2
+ import type { ComponentPropsWithoutRef, FormEvent, ReactNode } from "react";
3
+ import { MailCheck } from "lucide-react";
4
+ import { cn } from "../lib/cn";
5
+ import { useKitLabels } from "../i18n/kit-labels";
6
+ import { AlertBanner } from "../components/alert-banner";
7
+ import { TextLink } from "../components/text-link";
8
+ import { Button, Input } from "../components/ui";
9
+ import { englishRateLimited, isRateLimited, retryAfterSeconds } from "./auth-errors";
10
+ import { FORM_HEADING_CLASS, INTRO_CLASS, OutcomeMessage, isThenable, useFocusWhen } from "./status-parts";
11
+ import type { AuthHeadingLevel } from "./status-parts";
12
+
13
+ /* ── Labels ──────────────────────────────────────────────────────────────── */
14
+
15
+ /** Every string the form renders — the `forgotPassword` namespace. keksdose's words
16
+ * (`auth.forgot.*`), which kastlan took over unchanged. */
17
+ export interface ForgotPasswordLabels {
18
+ /** The heading. */
19
+ title: string;
20
+ /** Under the heading, before the field. */
21
+ intro: string;
22
+ /** The email field's label. */
23
+ email: string;
24
+ submit: string;
25
+ /** The one answer, whatever the server knows — given the address as typed. */
26
+ sent: (email: string) => string;
27
+ /** Under it: how long the link lives, and where else to look. */
28
+ sentHint: string;
29
+ /** The link back to the sign-in page, on both states. */
30
+ backToSignIn: string;
31
+ /** A request that did not go through: a throttle, an outage. Never "unknown
32
+ * address" — the endpoint does not say. */
33
+ error: string;
34
+ /** 0.30.0: the request was throttled — HTTP 429 ({@link isRateLimited}) — given the
35
+ * `Retry-After` wait in seconds, or `undefined` without one. OPTIONAL, like every key
36
+ * added to a shipped interface; the provider's `forgotPassword`, then English, fill
37
+ * it. */
38
+ rateLimited?: (seconds?: number) => string;
39
+ }
40
+
41
+ /** `Required`: every key, the 0.30 one included, has its English here. */
42
+ export const DEFAULT_FORGOT_PASSWORD_LABELS: Required<ForgotPasswordLabels> = {
43
+ title: "Forgot password",
44
+ intro: "Enter your account’s email address. We’ll send you a link to choose a new password.",
45
+ email: "Email",
46
+ submit: "Send the link",
47
+ sent: (email) => `If an account exists for ${email}, the link is on its way.`,
48
+ sentHint: "The link is valid for one hour and works exactly once. Check your spam folder too.",
49
+ backToSignIn: "Back to sign in",
50
+ error: "The request failed. Please try again later.",
51
+ rateLimited: englishRateLimited,
52
+ };
53
+
54
+ /* ── The form ────────────────────────────────────────────────────────────── */
55
+
56
+ export interface ForgotPasswordFormProps
57
+ extends Omit<ComponentPropsWithoutRef<"div">, "onSubmit" | "children" | "title"> {
58
+ /**
59
+ * The address was submitted, trimmed: send `POST /auth/password-reset/request`.
60
+ * Resolve when the server answered — whatever it answered: it is `204` whether or not
61
+ * an account exists. Reject only when the request did not go through (a throttle, an
62
+ * outage); the form then stays, with the address, and says so. The form never sends a
63
+ * request itself (§8).
64
+ */
65
+ onSubmit: (email: string) => Promise<unknown> | void;
66
+ /** "Back to sign in" — the app's `/login`. Default `/login`. */
67
+ signInHref?: string;
68
+ /** The field's start value — the address the sign-in form already had, so someone
69
+ * whose password just failed need not type it twice. */
70
+ defaultEmail?: string;
71
+ /**
72
+ * The app's words for a failed request ("Too many requests — try again in an hour"),
73
+ * or `undefined` for the kit's: `rateLimited` for a bare `429` (0.30.0), else `error`.
74
+ * The same hook as `SignInForm`'s.
75
+ */
76
+ describeError?: (error: unknown) => ReactNode | undefined;
77
+ /** App content under the intro — a notice, a support address. */
78
+ formContent?: ReactNode;
79
+ /** The heading. Default `labels.title`; `null` draws none, for a page that puts it
80
+ * in `AuthLayout`'s `title` instead. */
81
+ title?: ReactNode;
82
+ /** The heading's level. Default `h2`, under the page's `h1`. */
83
+ headingAs?: AuthHeadingLevel;
84
+ labels?: Partial<ForgotPasswordLabels>;
85
+ }
86
+
87
+ /**
88
+ * "I forgot my password" for every app (docs/auth-harmonization.md §7): one field, then
89
+ * the same sentence whatever the answer — keksdose's `ForgotPasswordPage`
90
+ * (features/auth/forgot-password-page.tsx), kastlan's copy of it, as one component.
91
+ *
92
+ * **It always ends on the same message**: "If an account exists for …, the link is on
93
+ * its way." The server answers `204` whether or not the address has an account — so the
94
+ * page cannot be used to find out who has one — and the page must not undo that by
95
+ * saying more than the server knows. Worded as a promise ("we sent you a link"), a typo
96
+ * would look like a mail-delivery problem and send the person waiting instead of trying
97
+ * their other address (keksdose #198). The address shown is the one they typed, so a
98
+ * typo is visible.
99
+ *
100
+ * The only failure it can show is a request that did not go through (throttled, the
101
+ * server down), never "unknown address". §4.5's fallback to a tagged address
102
+ * (`you+kastlan@…` when `you@…` has no account) is the server's and changes nothing here.
103
+ *
104
+ * The submit is not disabled while the field is empty — a browser that autofills
105
+ * withholds the value until the first interaction, and a disabled button would swallow
106
+ * that first click; the field's own `required` answers an empty submit instead. After a
107
+ * submit the confirmation takes focus, because the button that had it is gone with the
108
+ * form.
109
+ */
110
+ export function ForgotPasswordForm({
111
+ onSubmit,
112
+ signInHref = "/login",
113
+ defaultEmail = "",
114
+ describeError,
115
+ formContent,
116
+ title,
117
+ headingAs: Heading = "h2",
118
+ labels: labelsProp,
119
+ className,
120
+ ...rest
121
+ }: ForgotPasswordFormProps) {
122
+ const labels = useKitLabels("forgotPassword", DEFAULT_FORGOT_PASSWORD_LABELS, labelsProp);
123
+ const [email, setEmail] = useState(defaultEmail);
124
+ const [pending, setPending] = useState(false);
125
+ const [failure, setFailure] = useState<ReactNode>(null);
126
+ const [sentTo, setSentTo] = useState<string | null>(null);
127
+ const headingId = useId();
128
+ const sentRef = useRef<HTMLDivElement>(null);
129
+ useFocusWhen(sentTo !== null, sentRef);
130
+
131
+ const heading =
132
+ title === null ? null : (
133
+ <Heading id={headingId} className={FORM_HEADING_CLASS}>
134
+ {title ?? labels.title}
135
+ </Heading>
136
+ );
137
+ const back = (
138
+ <p className="text-center text-sm">
139
+ <TextLink href={signInHref} tone="primary">
140
+ {labels.backToSignIn}
141
+ </TextLink>
142
+ </p>
143
+ );
144
+
145
+ if (sentTo !== null) {
146
+ return (
147
+ <div {...rest} data-state="sent" className={cn("space-y-3", className)}>
148
+ {heading}
149
+ <OutcomeMessage icon={<MailCheck className="text-[var(--success)]" />} focusRef={sentRef}>
150
+ <p className={INTRO_CLASS}>{labels.sent(sentTo)}</p>
151
+ <p className="text-xs text-[var(--text-muted)]">{labels.sentHint}</p>
152
+ </OutcomeMessage>
153
+ {back}
154
+ </div>
155
+ );
156
+ }
157
+
158
+ // The app's words first, then the throttle's, then the kit's catch-all.
159
+ const failureFor = (error: unknown): ReactNode =>
160
+ describeError?.(error) ??
161
+ (isRateLimited(error)
162
+ ? (labels.rateLimited ?? DEFAULT_FORGOT_PASSWORD_LABELS.rateLimited)(retryAfterSeconds(error))
163
+ : labels.error);
164
+
165
+ const submit = (e: FormEvent) => {
166
+ e.preventDefault();
167
+ const address = email.trim();
168
+ if (pending || address === "") return;
169
+ setFailure(null);
170
+ let result: unknown;
171
+ try {
172
+ result = onSubmit(address);
173
+ } catch (error) {
174
+ setFailure(failureFor(error));
175
+ return;
176
+ }
177
+ if (!isThenable(result)) {
178
+ setSentTo(address);
179
+ return;
180
+ }
181
+ setPending(true);
182
+ result.then(
183
+ () => {
184
+ setPending(false);
185
+ setSentTo(address);
186
+ },
187
+ (error: unknown) => {
188
+ setPending(false);
189
+ setFailure(failureFor(error));
190
+ },
191
+ );
192
+ };
193
+
194
+ return (
195
+ <div {...rest} data-state="form" className={cn("space-y-3", className)}>
196
+ <form
197
+ className="space-y-3"
198
+ aria-labelledby={title === null ? undefined : headingId}
199
+ onSubmit={submit}
200
+ >
201
+ {heading}
202
+ <p className={INTRO_CLASS}>{labels.intro}</p>
203
+ {formContent}
204
+ <Input
205
+ type="email"
206
+ name="email"
207
+ autoComplete="email"
208
+ label={labels.email}
209
+ value={email}
210
+ onChange={(e) => {
211
+ setEmail(e.target.value);
212
+ if (failure) setFailure(null);
213
+ }}
214
+ readOnly={pending}
215
+ required
216
+ />
217
+ {failure != null && (
218
+ <AlertBanner tone="danger" size="sm" role="alert">
219
+ {failure}
220
+ </AlertBanner>
221
+ )}
222
+ <Button type="submit" className="w-full" pending={pending}>
223
+ {labels.submit}
224
+ </Button>
225
+ </form>
226
+ {back}
227
+ </div>
228
+ );
229
+ }
@@ -0,0 +1,40 @@
1
+ import { passwordByteLength } from "../components/password-strength";
2
+
3
+ /**
4
+ * The few hard rules of the sign-up and sign-in forms, in one place — and the only ones
5
+ * (docs/auth-harmonization.md §3.1, §8). The servers check the same; the kit adds no
6
+ * rule of its own, and everything the strength meter shows beyond these is advice.
7
+ *
8
+ * @internal Shared by RegisterForm, SignInForm and CompleteNameDialog; the coordinator
9
+ * decides whether the constants join the barrel.
10
+ */
11
+
12
+ /** At least 8 characters. */
13
+ export const PASSWORD_MIN_LENGTH = 8;
14
+
15
+ /** At most 72 BYTES — bcrypt reads no further, so a longer password would be silently
16
+ * cut. "ü" is two bytes, an emoji four. */
17
+ export const PASSWORD_MAX_BYTES = 72;
18
+
19
+ /** A first or last name: 1–120 characters after trimming — the old `display_name`
20
+ * limit, so a migrated name fits (§3.1). */
21
+ export const PERSON_NAME_MAX_LENGTH = 120;
22
+
23
+ /** 1–120 characters after trimming. */
24
+ export function personNameOk(value: string): boolean {
25
+ const length = value.trim().length;
26
+ return length >= 1 && length <= PERSON_NAME_MAX_LENGTH;
27
+ }
28
+
29
+ /**
30
+ * Why a new password and its confirmation may not be submitted yet, or `null` when they
31
+ * may — keksdose's `passwordPairError` (features/auth/password-fields.tsx). Characters
32
+ * are counted as code points, as the strength meter counts them: an emoji is one
33
+ * character to the person typing it.
34
+ */
35
+ export function newPasswordProblem(password: string, confirm: string): "length" | "bytes" | "mismatch" | null {
36
+ if ([...password].length < PASSWORD_MIN_LENGTH) return "length";
37
+ if (passwordByteLength(password) > PASSWORD_MAX_BYTES) return "bytes";
38
+ if (password !== confirm) return "mismatch";
39
+ return null;
40
+ }
@@ -0,0 +1,85 @@
1
+ import type { ReactNode, Ref } from "react";
2
+ import { PasswordStrengthMeter } from "../components/password-strength";
3
+ import { Input } from "../components/ui";
4
+ import { PASSWORD_MAX_BYTES, PASSWORD_MIN_LENGTH } from "./form-rules";
5
+
6
+ /** @internal The words the fields show — the host form's own labels. */
7
+ export interface NewPasswordFieldsText {
8
+ password: ReactNode;
9
+ confirm: ReactNode;
10
+ mismatch: ReactNode;
11
+ }
12
+
13
+ /** @internal */
14
+ export interface NewPasswordFieldsProps {
15
+ password: string;
16
+ confirm: string;
17
+ onPasswordChange: (value: string) => void;
18
+ onConfirmChange: (value: string) => void;
19
+ text: NewPasswordFieldsText;
20
+ /** A request is running: both fields `readOnly` (not `disabled`, which would drop
21
+ * the focus of the one being typed in). */
22
+ busy?: boolean;
23
+ passwordRef?: Ref<HTMLInputElement>;
24
+ }
25
+
26
+ /**
27
+ * "Choose a password": the field, the strength meter with its advisory checklist, and
28
+ * the confirmation — keksdose's `PasswordFields`, which its register form, its reset
29
+ * page and its forced-change step share so that every screen choosing a password does
30
+ * it under the same rules and the same feedback. Here `RegisterForm` and
31
+ * `SignInForm`'s set-a-new-password step share it.
32
+ *
33
+ * Both fields are `new-password`: a password manager offers to generate one and never
34
+ * fills in the current one. The confirmation carries the mismatch as its own `error`,
35
+ * attached with `aria-describedby`; the key is always passed, so the message coming and
36
+ * going never remounts the field under the typist.
37
+ *
38
+ * @internal Not part of the barrel; the forms are.
39
+ */
40
+ export function NewPasswordFields({
41
+ password,
42
+ confirm,
43
+ onPasswordChange,
44
+ onConfirmChange,
45
+ text,
46
+ busy = false,
47
+ passwordRef,
48
+ }: NewPasswordFieldsProps) {
49
+ const mismatch = confirm !== "" && confirm !== password;
50
+ return (
51
+ <>
52
+ <div>
53
+ <Input
54
+ ref={passwordRef}
55
+ type="password"
56
+ name="new-password"
57
+ autoComplete="new-password"
58
+ label={text.password}
59
+ value={password}
60
+ onChange={(e) => onPasswordChange(e.target.value)}
61
+ minLength={PASSWORD_MIN_LENGTH}
62
+ readOnly={busy}
63
+ required
64
+ />
65
+ {/* The 72-byte cap is passed because a SIGN-IN password has one (bcrypt); the
66
+ minimum is passed rather than left to the meter's own default 8, so the two
67
+ cannot drift apart. */}
68
+ <PasswordStrengthMeter value={password} minLength={PASSWORD_MIN_LENGTH} maxBytes={PASSWORD_MAX_BYTES} />
69
+ </div>
70
+ {/* A typo'd password costs a reset mail — and under keksdose's end-to-end
71
+ encryption, data (feedback #124) — so it is typed twice. */}
72
+ <Input
73
+ type="password"
74
+ name="confirm-password"
75
+ autoComplete="new-password"
76
+ label={text.confirm}
77
+ value={confirm}
78
+ onChange={(e) => onConfirmChange(e.target.value)}
79
+ readOnly={busy}
80
+ error={mismatch ? text.mismatch : undefined}
81
+ required
82
+ />
83
+ </>
84
+ );
85
+ }