@eifi1/ui-kit 0.29.0 → 0.31.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 (307) hide show
  1. package/README.md +65 -6
  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 +114 -0
  7. package/dist/account/data-export-setting.js.map +1 -0
  8. package/dist/account/delete-account-setting.d.ts +95 -0
  9. package/dist/account/delete-account-setting.js +200 -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 +278 -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 +147 -0
  16. package/dist/account/sessions-setting.js.map +1 -0
  17. package/dist/admin/admin-action-confirm.d.ts +95 -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 +95 -0
  27. package/dist/admin/invitations-panel.js +290 -0
  28. package/dist/admin/invitations-panel.js.map +1 -0
  29. package/dist/admin/reviewer-scope-editor.d.ts +95 -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 +95 -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 +95 -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 +95 -0
  39. package/dist/admin/user-roster.js +285 -0
  40. package/dist/admin/user-roster.js.map +1 -0
  41. package/dist/auth/auth-errors.d.ts +103 -6
  42. package/dist/auth/auth-errors.js +68 -2
  43. package/dist/auth/auth-errors.js.map +1 -1
  44. package/dist/auth/forgot-password-form.d.ts +10 -3
  45. package/dist/auth/forgot-password-form.js +6 -3
  46. package/dist/auth/forgot-password-form.js.map +1 -1
  47. package/dist/auth/register-form.d.ts +21 -12
  48. package/dist/auth/register-form.js +6 -4
  49. package/dist/auth/register-form.js.map +1 -1
  50. package/dist/auth/reset-password-form.d.ts +10 -3
  51. package/dist/auth/reset-password-form.js +6 -3
  52. package/dist/auth/reset-password-form.js.map +1 -1
  53. package/dist/auth/sign-in-form.d.ts +75 -9
  54. package/dist/auth/sign-in-form.js +105 -15
  55. package/dist/auth/sign-in-form.js.map +1 -1
  56. package/dist/auth/verify-email.d.ts +7 -2
  57. package/dist/auth/verify-email.js +44 -8
  58. package/dist/auth/verify-email.js.map +1 -1
  59. package/dist/chart.d.ts +20 -11
  60. package/dist/components/account-chips.d.ts +47 -7
  61. package/dist/components/account-chips.js +19 -3
  62. package/dist/components/account-chips.js.map +1 -1
  63. package/dist/components/account-settings-labels.d.ts +24 -1
  64. package/dist/components/account-settings-labels.js +6 -2
  65. package/dist/components/account-settings-labels.js.map +1 -1
  66. package/dist/components/account-settings.d.ts +69 -8
  67. package/dist/components/account-settings.js +133 -25
  68. package/dist/components/account-settings.js.map +1 -1
  69. package/dist/components/amount-input.d.ts +21 -12
  70. package/dist/components/button-group.d.ts +21 -12
  71. package/dist/components/calculator.d.ts +21 -12
  72. package/dist/components/confirm-dialog.d.ts +21 -12
  73. package/dist/components/copy-button.d.ts +18 -9
  74. package/dist/components/danger-confirm.d.ts +21 -12
  75. package/dist/components/data-table.js +8 -1
  76. package/dist/components/data-table.js.map +1 -1
  77. package/dist/components/date-picker.js +9 -4
  78. package/dist/components/date-picker.js.map +1 -1
  79. package/dist/components/facing-pair.d.ts +21 -12
  80. package/dist/components/file-button.d.ts +21 -12
  81. package/dist/components/file-dropzone.d.ts +21 -12
  82. package/dist/components/form-actions.d.ts +21 -12
  83. package/dist/components/iban-input.d.ts +21 -12
  84. package/dist/components/language-select.d.ts +21 -12
  85. package/dist/components/legal-page.d.ts +21 -12
  86. package/dist/components/legal.d.ts +21 -12
  87. package/dist/components/money-field.d.ts +21 -12
  88. package/dist/components/number-field.d.ts +21 -12
  89. package/dist/components/number-input.d.ts +21 -12
  90. package/dist/components/numpad-sheet.d.ts +21 -12
  91. package/dist/components/passkeys-setting.js +2 -1
  92. package/dist/components/passkeys-setting.js.map +1 -1
  93. package/dist/components/phone-input.d.ts +21 -12
  94. package/dist/components/series-chart.d.ts +21 -12
  95. package/dist/components/settings-fields.d.ts +55 -13
  96. package/dist/components/settings-fields.js +20 -1
  97. package/dist/components/settings-fields.js.map +1 -1
  98. package/dist/components/share-card.d.ts +20 -11
  99. package/dist/components/text-link.d.ts +21 -12
  100. package/dist/components/time-input.d.ts +21 -12
  101. package/dist/components/ui.d.ts +17 -8
  102. package/dist/{register-form-V1OeNlMr.d.ts → delete-account-setting-DCFS5Vof.d.ts} +6612 -5612
  103. package/dist/demo/demo-banner.d.ts +51 -0
  104. package/dist/demo/demo-banner.js +97 -0
  105. package/dist/demo/demo-banner.js.map +1 -0
  106. package/dist/demo/demo-countdown.d.ts +58 -0
  107. package/dist/demo/demo-countdown.js +79 -0
  108. package/dist/demo/demo-countdown.js.map +1 -0
  109. package/dist/demo/demo-ended.d.ts +45 -0
  110. package/dist/demo/demo-ended.js +42 -0
  111. package/dist/demo/demo-ended.js.map +1 -0
  112. package/dist/demo/demo-labels.d.ts +53 -0
  113. package/dist/demo/demo-labels.js +29 -0
  114. package/dist/demo/demo-labels.js.map +1 -0
  115. package/dist/demo/demo-session.d.ts +30 -0
  116. package/dist/demo/demo-session.js +8 -0
  117. package/dist/demo/demo-session.js.map +1 -0
  118. package/dist/demo/demo-start.d.ts +54 -0
  119. package/dist/demo/demo-start.js +68 -0
  120. package/dist/demo/demo-start.js.map +1 -0
  121. package/dist/feedback/feedback-attachment.d.ts +21 -12
  122. package/dist/feedback/feedback-context.d.ts +21 -12
  123. package/dist/feedback/feedback-crash.d.ts +21 -12
  124. package/dist/feedback/feedback-dialog.d.ts +21 -12
  125. package/dist/feedback/feedback-inbox.d.ts +21 -12
  126. package/dist/feedback/feedback-inbox.js +12 -2
  127. package/dist/feedback/feedback-inbox.js.map +1 -1
  128. package/dist/feedback/feedback-labels.d.ts +21 -12
  129. package/dist/feedback/feedback-labels.js +1 -0
  130. package/dist/feedback/feedback-labels.js.map +1 -1
  131. package/dist/feedback/feedback-menu.d.ts +21 -12
  132. package/dist/feedback/feedback-record.d.ts +21 -12
  133. package/dist/feedback/feedback-record.js +2 -0
  134. package/dist/feedback/feedback-record.js.map +1 -1
  135. package/dist/feedback/feedback-row-detail.d.ts +21 -12
  136. package/dist/feedback/feedback-row-detail.js +7 -0
  137. package/dist/feedback/feedback-row-detail.js.map +1 -1
  138. package/dist/feedback/feedback-status-undo.d.ts +21 -12
  139. package/dist/feedback/feedback-submit.d.ts +21 -12
  140. package/dist/feedback/feedback-swipe.d.ts +22 -13
  141. package/dist/feedback/feedback-swipe.js.map +1 -1
  142. package/dist/feedback/feedback-table.d.ts +18 -9
  143. package/dist/feedback/feedback-thread.d.ts +21 -12
  144. package/dist/feedback.d.ts +21 -12
  145. package/dist/hooks/use-anchored-panel.d.ts +6 -2
  146. package/dist/hooks/use-anchored-panel.js +2 -1
  147. package/dist/hooks/use-anchored-panel.js.map +1 -1
  148. package/dist/hooks/use-file-drop.d.ts +21 -12
  149. package/dist/i18n/defaults.d.ts +21 -12
  150. package/dist/i18n/defaults.js +28 -0
  151. package/dist/i18n/defaults.js.map +1 -1
  152. package/dist/i18n/german.d.ts +21 -12
  153. package/dist/i18n/german.js +298 -12
  154. package/dist/i18n/german.js.map +1 -1
  155. package/dist/i18n/kit-labels.d.ts +14 -5
  156. package/dist/i18n/kit-labels.js.map +1 -1
  157. package/dist/i18n/languages.d.ts +15 -6
  158. package/dist/i18n/locales/de-CH.d.ts +21 -12
  159. package/dist/i18n/locales/en.d.ts +21 -12
  160. package/dist/i18n/locales/es.d.ts +21 -12
  161. package/dist/i18n/locales/es.js +287 -10
  162. package/dist/i18n/locales/es.js.map +1 -1
  163. package/dist/i18n/locales/fr.d.ts +21 -12
  164. package/dist/i18n/locales/fr.js +290 -7
  165. package/dist/i18n/locales/fr.js.map +1 -1
  166. package/dist/i18n/locales/hu.d.ts +21 -12
  167. package/dist/i18n/locales/hu.js +288 -12
  168. package/dist/i18n/locales/hu.js.map +1 -1
  169. package/dist/i18n/locales/it.d.ts +21 -12
  170. package/dist/i18n/locales/it.js +289 -7
  171. package/dist/i18n/locales/it.js.map +1 -1
  172. package/dist/i18n/locales/zh.d.ts +21 -12
  173. package/dist/i18n/locales/zh.js +279 -7
  174. package/dist/i18n/locales/zh.js.map +1 -1
  175. package/dist/i18n/review.d.ts +21 -12
  176. package/dist/i18n/review.js +50 -1
  177. package/dist/i18n/review.js.map +1 -1
  178. package/dist/index.d.ts +31 -4
  179. package/dist/index.js +148 -0
  180. package/dist/index.js.map +1 -1
  181. package/dist/landing/access.d.ts +48 -0
  182. package/dist/landing/access.js +38 -0
  183. package/dist/landing/access.js.map +1 -0
  184. package/dist/landing/landing-actions.d.ts +138 -0
  185. package/dist/landing/landing-actions.js +39 -0
  186. package/dist/landing/landing-actions.js.map +1 -0
  187. package/dist/landing/landing-labels.d.ts +43 -0
  188. package/dist/landing/landing-labels.js +23 -0
  189. package/dist/landing/landing-labels.js.map +1 -0
  190. package/dist/landing/landing-sections.d.ts +218 -0
  191. package/dist/landing/landing-sections.js +167 -0
  192. package/dist/landing/landing-sections.js.map +1 -0
  193. package/dist/landing/page-seo.d.ts +99 -0
  194. package/dist/landing/page-seo.js +121 -0
  195. package/dist/landing/page-seo.js.map +1 -0
  196. package/dist/landing/public-header.d.ts +148 -0
  197. package/dist/landing/public-header.js +49 -0
  198. package/dist/landing/public-header.js.map +1 -0
  199. package/dist/landing/routing.d.ts +218 -0
  200. package/dist/landing/routing.js +81 -0
  201. package/dist/landing/routing.js.map +1 -0
  202. package/dist/rhf/fields.d.ts +21 -12
  203. package/dist/rhf/form.d.ts +21 -12
  204. package/dist/rhf.d.ts +21 -12
  205. package/dist/settings/settings-catalogue.d.ts +84 -0
  206. package/dist/settings/settings-catalogue.js +47 -0
  207. package/dist/settings/settings-catalogue.js.map +1 -0
  208. package/dist/settings/settings-context.d.ts +31 -0
  209. package/dist/settings/settings-context.js +11 -0
  210. package/dist/settings/settings-context.js.map +1 -0
  211. package/dist/settings/settings-heading.d.ts +50 -0
  212. package/dist/settings/settings-heading.js +27 -0
  213. package/dist/settings/settings-heading.js.map +1 -0
  214. package/dist/settings/settings-labels.d.ts +41 -0
  215. package/dist/settings/settings-labels.js +38 -0
  216. package/dist/settings/settings-labels.js.map +1 -0
  217. package/dist/settings/settings-layout.d.ts +77 -0
  218. package/dist/settings/settings-layout.js +242 -0
  219. package/dist/settings/settings-layout.js.map +1 -0
  220. package/dist/settings/settings-section.d.ts +133 -0
  221. package/dist/settings/settings-section.js +63 -0
  222. package/dist/settings/settings-section.js.map +1 -0
  223. package/dist/settings/use-account-language.d.ts +83 -0
  224. package/dist/settings/use-account-language.js +62 -0
  225. package/dist/settings/use-account-language.js.map +1 -0
  226. package/dist/settings/use-settings-focus.d.ts +34 -0
  227. package/dist/settings/use-settings-focus.js +77 -0
  228. package/dist/settings/use-settings-focus.js.map +1 -0
  229. package/dist/settings/use-settings-route.d.ts +118 -0
  230. package/dist/settings/use-settings-route.js +120 -0
  231. package/dist/settings/use-settings-route.js.map +1 -0
  232. package/dist/shell/app-shell.d.ts +27 -12
  233. package/dist/shell/app-shell.js +3 -2
  234. package/dist/shell/app-shell.js.map +1 -1
  235. package/dist/shell/top-bar-brand.d.ts +21 -12
  236. package/dist/shell.d.ts +25 -6
  237. package/dist/shell.js +56 -0
  238. package/dist/shell.js.map +1 -1
  239. package/dist/wizard/stepper-nav.d.ts +21 -12
  240. package/dist/wizard.d.ts +21 -12
  241. package/package.json +2 -1
  242. package/src/account/account-parts.ts +67 -0
  243. package/src/account/data-export-setting.tsx +219 -0
  244. package/src/account/delete-account-setting.tsx +363 -0
  245. package/src/account/email-change-setting.tsx +454 -0
  246. package/src/account/sessions-setting.tsx +284 -0
  247. package/src/admin/admin-action-confirm.tsx +495 -0
  248. package/src/admin/admin-action-log.tsx +297 -0
  249. package/src/admin/admin-parts.ts +82 -0
  250. package/src/admin/invitations-panel.tsx +523 -0
  251. package/src/admin/reviewer-scope-editor.tsx +234 -0
  252. package/src/admin/role-select.tsx +286 -0
  253. package/src/admin/transfer-ownership-dialog.tsx +172 -0
  254. package/src/admin/user-roster.tsx +573 -0
  255. package/src/auth/auth-errors.ts +196 -8
  256. package/src/auth/forgot-password-form.tsx +21 -5
  257. package/src/auth/register-form.tsx +24 -6
  258. package/src/auth/reset-password-form.tsx +19 -5
  259. package/src/auth/sign-in-form.tsx +241 -38
  260. package/src/auth/verify-email.tsx +59 -8
  261. package/src/components/account-chips.tsx +64 -7
  262. package/src/components/account-settings-labels.ts +28 -1
  263. package/src/components/account-settings.tsx +231 -34
  264. package/src/components/data-table.tsx +8 -0
  265. package/src/components/date-picker.tsx +9 -4
  266. package/src/components/passkeys-setting.tsx +2 -1
  267. package/src/components/settings-fields.tsx +50 -1
  268. package/src/demo/demo-banner.tsx +159 -0
  269. package/src/demo/demo-countdown.ts +141 -0
  270. package/src/demo/demo-ended.tsx +89 -0
  271. package/src/demo/demo-labels.ts +78 -0
  272. package/src/demo/demo-session.ts +32 -0
  273. package/src/demo/demo-start.tsx +150 -0
  274. package/src/feedback/feedback-inbox.tsx +21 -8
  275. package/src/feedback/feedback-labels.ts +2 -1
  276. package/src/feedback/feedback-record.ts +10 -7
  277. package/src/feedback/feedback-row-detail.tsx +28 -4
  278. package/src/feedback/feedback-swipe.tsx +1 -1
  279. package/src/hooks/use-anchored-panel.ts +14 -3
  280. package/src/i18n/defaults.ts +28 -0
  281. package/src/i18n/german.ts +327 -5
  282. package/src/i18n/kit-labels.tsx +42 -0
  283. package/src/i18n/locales/es.ts +313 -3
  284. package/src/i18n/locales/fr.ts +316 -0
  285. package/src/i18n/locales/hu.ts +308 -5
  286. package/src/i18n/locales/it.ts +313 -0
  287. package/src/i18n/locales/zh.ts +286 -0
  288. package/src/i18n/review.ts +49 -0
  289. package/src/index.ts +184 -0
  290. package/src/landing/access.ts +97 -0
  291. package/src/landing/landing-actions.tsx +92 -0
  292. package/src/landing/landing-labels.ts +59 -0
  293. package/src/landing/landing-sections.tsx +337 -0
  294. package/src/landing/page-seo.ts +251 -0
  295. package/src/landing/public-header.tsx +120 -0
  296. package/src/landing/routing.tsx +209 -0
  297. package/src/settings/settings-catalogue.ts +132 -0
  298. package/src/settings/settings-context.ts +33 -0
  299. package/src/settings/settings-heading.tsx +65 -0
  300. package/src/settings/settings-labels.ts +75 -0
  301. package/src/settings/settings-layout.tsx +379 -0
  302. package/src/settings/settings-section.tsx +108 -0
  303. package/src/settings/use-account-language.ts +146 -0
  304. package/src/settings/use-settings-focus.ts +120 -0
  305. package/src/settings/use-settings-route.ts +258 -0
  306. package/src/shell/app-shell.tsx +10 -2
  307. package/src/shell.ts +45 -0
@@ -0,0 +1,200 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { isValidElement, useRef, useState } from "react";
4
+ import { UserX } from "lucide-react";
5
+ import { useKitLabels, useKitLocale } from "../i18n/kit-labels.js";
6
+ import { cn } from "../lib/cn.js";
7
+ import { AlertBanner } from "../components/alert-banner.js";
8
+ import { hasMessage } from "../components/choice-parts.js";
9
+ import {
10
+ CurrentPasswordInput,
11
+ DangerConfirm,
12
+ DEFAULT_DANGER_CONFIRM_LABELS,
13
+ TypedConfirmField,
14
+ typedMatches
15
+ } from "../components/danger-confirm.js";
16
+ import { Card } from "../components/ui.js";
17
+ import { authErrorCode, englishRateLimited, isRateLimited, retryAfterSeconds } from "../auth/auth-errors.js";
18
+ import { useFocusWhen } from "../auth/status-parts.js";
19
+ import { CARD_DESCRIPTION_CLASS, refusalCompanies, settle, useMounted } from "./account-parts.js";
20
+ import { SettingsCardTitle } from "../settings/settings-heading.js";
21
+ const DEFAULT_DELETE_ACCOUNT_LABELS = {
22
+ title: "Delete account",
23
+ afterDays: (days) => days === 1 ? "Your account is deactivated at once and erased for good 1 day later." : `Your account is deactivated at once and erased for good ${days} days later.`,
24
+ operator: "Your account is deactivated at once, and an operator will erase it for good.",
25
+ arm: "Delete account\u2026",
26
+ prompt: "You will be signed out on every device, and your account can no longer be used.",
27
+ handOver: (count) => count === 1 ? "1 item others can see will pass to an administrator." : `${count} items others can see will pass to an administrator.`,
28
+ confirm: "Delete my account",
29
+ done: "Your account is deactivated. You are being signed out.",
30
+ wrongPassword: "The password is incorrect.",
31
+ confirmationMismatch: "This is not your account\u2019s address.",
32
+ lastAdmin: "You are the last administrator. Make someone else an administrator first.",
33
+ lastAdminOf: (companies) => `You are the last administrator of ${companies}. Make someone else an administrator there first.`,
34
+ householdHasMembers: "Your household has other members, so the account can\u2019t be deleted here. Please write to the operator.",
35
+ rateLimited: englishRateLimited,
36
+ failed: "Your account could not be deleted. Please try again."
37
+ };
38
+ function isConsequence(item) {
39
+ return typeof item === "object" && item !== null && !isValidElement(item) && "text" in item;
40
+ }
41
+ function DeleteAccountSetting({
42
+ email,
43
+ mode,
44
+ days = 30,
45
+ consequences,
46
+ handOverCount,
47
+ onRequest,
48
+ describeError,
49
+ labels: labelsProp,
50
+ className,
51
+ ...rest
52
+ }) {
53
+ const labels = useKitLabels("deleteAccount", DEFAULT_DELETE_ACCOUNT_LABELS, labelsProp);
54
+ const guardLabels = useKitLabels("dangerConfirm", DEFAULT_DANGER_CONFIRM_LABELS);
55
+ const locale = useKitLocale();
56
+ const [typed, setTyped] = useState("");
57
+ const [password, setPassword] = useState("");
58
+ const [busy, setBusy] = useState(false);
59
+ const [fieldError, setFieldError] = useState(null);
60
+ const [failure, setFailure] = useState(null);
61
+ const [done, setDone] = useState(false);
62
+ const mounted = useMounted();
63
+ const typedRef = useRef(null);
64
+ const passwordRef = useRef(null);
65
+ const doneRef = useRef(null);
66
+ useFocusWhen(done, doneRef);
67
+ const modeSentence = mode === "operator" ? labels.operator : labels.afterDays(days);
68
+ const lines = (consequences ?? []).filter((item) => item !== null && item !== void 0 && item !== false && item !== "").map((item, index) => isConsequence(item) ? item : { key: `app-${index}`, text: item });
69
+ if (handOverCount !== void 0 && handOverCount > 0) {
70
+ lines.push({ key: "hand-over", text: labels.handOver(handOverCount) });
71
+ }
72
+ const held = !typedMatches(typed, email, "caseless") ? typeof guardLabels.needsPhrase === "function" ? guardLabels.needsPhrase(email) : guardLabels.needsPhrase : password === "" ? guardLabels.needsPassword : void 0;
73
+ const present = (error) => {
74
+ const own = describeError?.(error);
75
+ if (hasMessage(own)) {
76
+ setFailure(own);
77
+ return;
78
+ }
79
+ if (isRateLimited(error)) {
80
+ setFailure(labels.rateLimited(retryAfterSeconds(error)));
81
+ return;
82
+ }
83
+ const code = authErrorCode(error);
84
+ if (code === "password_incorrect" || code === "invalid_credentials") {
85
+ setFieldError("password");
86
+ passwordRef.current?.focus();
87
+ return;
88
+ }
89
+ if (code === "confirmation_mismatch" || code === "confirmation_required") {
90
+ setFieldError("email");
91
+ typedRef.current?.focus();
92
+ return;
93
+ }
94
+ if (code === "last_admin") {
95
+ const companies = refusalCompanies(error);
96
+ setFailure(
97
+ companies ? labels.lastAdminOf(new Intl.ListFormat(locale, { type: "conjunction" }).format(companies)) : labels.lastAdmin
98
+ );
99
+ return;
100
+ }
101
+ setFailure(code === "household_has_members" ? labels.householdHasMembers : labels.failed);
102
+ };
103
+ const confirm = () => {
104
+ setFailure(null);
105
+ setFieldError(null);
106
+ setBusy(true);
107
+ const values = { password, confirmEmail: typed.trim() };
108
+ return settle(() => onRequest(values)).then(
109
+ () => {
110
+ if (!mounted.current) return;
111
+ setBusy(false);
112
+ setDone(true);
113
+ },
114
+ (error) => {
115
+ if (mounted.current) {
116
+ setBusy(false);
117
+ present(error);
118
+ }
119
+ throw error;
120
+ }
121
+ );
122
+ };
123
+ const disarmed = (armed) => {
124
+ if (armed) return;
125
+ setTyped("");
126
+ setPassword("");
127
+ setFieldError(null);
128
+ setFailure(null);
129
+ };
130
+ return /* @__PURE__ */ jsxs(
131
+ Card,
132
+ {
133
+ ...rest,
134
+ "data-state": done ? "done" : "form",
135
+ tone: "danger",
136
+ className: cn("p-4 space-y-3", className),
137
+ children: [
138
+ /* @__PURE__ */ jsxs("div", { children: [
139
+ /* @__PURE__ */ jsx(SettingsCardTitle, { children: labels.title }),
140
+ /* @__PURE__ */ jsx("div", { className: CARD_DESCRIPTION_CLASS, children: modeSentence })
141
+ ] }),
142
+ done ? /* @__PURE__ */ jsxs("div", { ref: doneRef, tabIndex: -1, role: "status", className: "flex items-start gap-2 text-sm outline-none", children: [
143
+ /* @__PURE__ */ jsx(UserX, { "aria-hidden": true, className: "mt-0.5 size-4 shrink-0 text-[var(--text-muted)]" }),
144
+ /* @__PURE__ */ jsx("span", { children: labels.done })
145
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
146
+ /* @__PURE__ */ jsxs(
147
+ DangerConfirm,
148
+ {
149
+ commit: true,
150
+ armLabel: labels.arm,
151
+ prompt: labels.prompt,
152
+ consequences: lines,
153
+ confirmLabel: labels.confirm,
154
+ confirmDisabledReason: held,
155
+ busy,
156
+ onArmedChange: disarmed,
157
+ onConfirm: confirm,
158
+ children: [
159
+ /* @__PURE__ */ jsx(
160
+ TypedConfirmField,
161
+ {
162
+ ref: typedRef,
163
+ target: email,
164
+ match: "caseless",
165
+ value: typed,
166
+ onValueChange: (next) => {
167
+ setTyped(next);
168
+ if (fieldError === "email") setFieldError(null);
169
+ },
170
+ error: fieldError === "email" ? labels.confirmationMismatch : void 0,
171
+ busy
172
+ }
173
+ ),
174
+ /* @__PURE__ */ jsx(
175
+ CurrentPasswordInput,
176
+ {
177
+ ref: passwordRef,
178
+ value: password,
179
+ onValueChange: (next) => {
180
+ setPassword(next);
181
+ if (fieldError === "password") setFieldError(null);
182
+ },
183
+ error: fieldError === "password" ? labels.wrongPassword : void 0,
184
+ busy
185
+ }
186
+ )
187
+ ]
188
+ }
189
+ ),
190
+ hasMessage(failure) && /* @__PURE__ */ jsx(AlertBanner, { tone: "danger", size: "sm", role: "alert", children: failure })
191
+ ] })
192
+ ]
193
+ }
194
+ );
195
+ }
196
+ export {
197
+ DEFAULT_DELETE_ACCOUNT_LABELS,
198
+ DeleteAccountSetting
199
+ };
200
+ //# sourceMappingURL=delete-account-setting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/account/delete-account-setting.tsx"],"sourcesContent":["import { isValidElement, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport { UserX } from \"lucide-react\";\n\nimport { useKitLabels, useKitLocale } from \"../i18n/kit-labels\";\nimport { cn } from \"../lib/cn\";\nimport { AlertBanner } from \"../components/alert-banner\";\nimport { hasMessage } from \"../components/choice-parts\";\nimport {\n CurrentPasswordInput,\n DangerConfirm,\n DEFAULT_DANGER_CONFIRM_LABELS,\n TypedConfirmField,\n typedMatches,\n} from \"../components/danger-confirm\";\nimport type { DangerConsequence } from \"../components/danger-confirm\";\nimport { Card } from \"../components/ui\";\nimport { authErrorCode, englishRateLimited, isRateLimited, retryAfterSeconds } from \"../auth/auth-errors\";\nimport { useFocusWhen } from \"../auth/status-parts\";\nimport { CARD_DESCRIPTION_CLASS, refusalCompanies, settle, useMounted } from \"./account-parts\";\nimport { SettingsCardTitle } from \"../settings/settings-heading\";\n\n/* ── Labels ──────────────────────────────────────────────────────────────── */\n\n/**\n * Every string {@link DeleteAccountSetting} renders — the `deleteAccount` namespace of\n * `<UiKitProvider labels>`, overridable per instance through `labels`. The confirm's\n * Cancel, \"Password\" and \"Type … to confirm\" are `dangerConfirm`'s.\n */\nexport interface DeleteAccountLabels {\n /** The card's title. */\n title: string;\n /** Mode `after_days`, given the days: what happens and when. */\n afterDays: (days: number) => string;\n /** Mode `operator`: what happens, and who erases it. */\n operator: string;\n /** The button that opens the confirm. */\n arm: string;\n /** The confirm's warning, over the consequences. */\n prompt: string;\n /** The line in the consequences when `handOverCount` is given (Kurvenschmiede, §2.7),\n * given the count. */\n handOver: (count: number) => string;\n /** The button that sends it. */\n confirm: string;\n /** Said once the request is accepted — the app signs out next. */\n done: string;\n /** `password_incorrect` (server-kit's `400` for a wrong current password), under the\n * password field. */\n wrongPassword: string;\n /** `confirmation_mismatch` — the server did not take the typed address as the\n * account's — under the address field. */\n confirmationMismatch: string;\n /** `last_admin` — the account is the last active admin. */\n lastAdmin: string;\n /** `last_admin` naming the companies (kastlan checks per company), given them as one\n * list in the reader's language (\"Example AG and Sample GmbH\"). */\n lastAdminOf: (companies: string) => string;\n /** `household_has_members` — keksdose's guard (§6.4). */\n householdHasMembers: string;\n /** A request was throttled — HTTP 429 — given its `Retry-After` wait in seconds, or\n * `undefined` without one. */\n rateLimited: (seconds?: number) => string;\n /** Any other failure. */\n failed: string;\n}\n\nexport const DEFAULT_DELETE_ACCOUNT_LABELS: DeleteAccountLabels = {\n title: \"Delete account\",\n afterDays: (days) =>\n days === 1\n ? \"Your account is deactivated at once and erased for good 1 day later.\"\n : `Your account is deactivated at once and erased for good ${days} days later.`,\n operator: \"Your account is deactivated at once, and an operator will erase it for good.\",\n arm: \"Delete account…\",\n prompt: \"You will be signed out on every device, and your account can no longer be used.\",\n handOver: (count) =>\n count === 1\n ? \"1 item others can see will pass to an administrator.\"\n : `${count} items others can see will pass to an administrator.`,\n confirm: \"Delete my account\",\n done: \"Your account is deactivated. You are being signed out.\",\n wrongPassword: \"The password is incorrect.\",\n confirmationMismatch: \"This is not your account’s address.\",\n lastAdmin: \"You are the last administrator. Make someone else an administrator first.\",\n lastAdminOf: (companies) =>\n `You are the last administrator of ${companies}. Make someone else an administrator there first.`,\n householdHasMembers:\n \"Your household has other members, so the account can’t be deleted here. Please write to the operator.\",\n rateLimited: englishRateLimited,\n failed: \"Your account could not be deleted. Please try again.\",\n};\n\n/* ── Props ───────────────────────────────────────────────────────────────── */\n\n/** What happens after the deactivation (§2.1, §6.4) — the app's setting. */\nexport type DeletionMode = \"after_days\" | \"operator\";\n\n/** What {@link DeleteAccountSettingProps.onRequest} gets: the `POST /auth/me/deletion`\n * body. */\nexport interface DeleteAccountValues {\n /** As typed. */\n password: string;\n /** The address as TYPED, trimmed — the server re-checks it against the account\n * (server-kit's `confirm_email_matches`), as keksdose's admin actions do. */\n confirmEmail: string;\n}\n\n/** One line of the consequences: a node of the app's, or a {@link DangerConsequence}\n * for a key of its own and the `severe` mark. */\nexport type DeleteAccountConsequence = ReactNode | DangerConsequence;\n\nexport interface DeleteAccountSettingProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"children\"> {\n /** The account's address — the text to type. */\n email: string;\n /** `\"after_days\"` (keksdose, Kurvenschmiede: erased by a scheduled job) or\n * `\"operator\"` (kastlan: company data is involved, an operator erases it). */\n mode: DeletionMode;\n /** With `after_days`: how many. Default 30 (§2.1). */\n days?: number;\n /**\n * What goes, in the app's words (§6.4: \"the app's own list\") — derived from the\n * account's own facts where it can be: keksdose's \"Budget X will be deleted; its 2\n * guests are told\", rather than the worst case for everybody.\n */\n consequences?: readonly DeleteAccountConsequence[];\n /** Kurvenschmiede (§2.7): how many owned items others can see — they pass to the\n * first active admin at erasure. A line of its own in the consequences; 0 or left\n * out, none. */\n handOverCount?: number;\n /**\n * The confirm was answered: send `POST /auth/me/deletion {password, confirm_email}`.\n * Resolve once it is accepted — the card says \"You are being signed out\" — and then\n * sign the user out: the server ended every session with the deactivation. Reject\n * with the client's error: `password_incorrect` under the password,\n * `confirmation_mismatch` under the address, `last_admin` (with kastlan's\n * `companies`) and `household_has_members` above the buttons, a 429 as\n * `rateLimited`, anything else (a demo account's 403, an app's own code) through\n * `describeError`, else `failed`. The confirm stays open with what was typed, for a\n * retry.\n */\n onRequest: (values: DeleteAccountValues) => Promise<unknown> | void;\n /** The app's own words for a failure, or `undefined` for the kit's. Asked first, for\n * every failure — kastlan's `last_admin` names the companies. */\n describeError?: (error: unknown) => ReactNode | undefined;\n labels?: Partial<DeleteAccountLabels>;\n}\n\n/** Whether an item is a `{ text }` line rather than a node — a React element is an\n * object too, and so would a `{ text }` lookalike be, so the element test comes first. */\nfunction isConsequence(item: DeleteAccountConsequence): item is DangerConsequence {\n return typeof item === \"object\" && item !== null && !isValidElement(item) && \"text\" in item;\n}\n\n/**\n * Deleting one's own account (docs/user-admin-harmonization.md §6.4, §2.1): what it does,\n * the password, the typed address — then the app signs out.\n *\n * **Two stages, said before the button.** The request DEACTIVATES the account at once\n * (no sign-in, every session ended, marked for deletion); the erasure follows per the\n * app's `mode` — \"erased for good 30 days later\" (`after_days`, a scheduled job) or \"an\n * operator will erase it\" (`operator`, kastlan, where company records are involved).\n * The sentence is under the title, so it is read before anything is pressed.\n *\n * **The confirm is a {@link DangerConfirm}** with the two guards of every \"type the\n * address\" rule in the apps: the address typed (compared caseless, as in all of them)\n * and the password. They are the tile's own {@link TypedConfirmField} and\n * {@link CurrentPasswordInput}, drawn in its fields slot and held by\n * `confirmDisabledReason` with the tile's own sentences, rather than its built-in\n * `phrase` / `requirePassword` — those have no error of their own, and a wrong password\n * belongs under the password. Its consequences are the app's list, plus\n * Kurvenschmiede's hand-over line (`handOverCount`, §2.7: shared work goes to an\n * administrator, never a refusal). The typed address goes to `onRequest` as typed, so\n * the server re-checks it (`confirm_email_matches`).\n *\n * **Refusals** (§6.4) are read by code ({@link authErrorCode}): `password_incorrect` (a\n * `400`, so an app's 401 handling never signs the person out over a typo) under the\n * password, `confirmation_mismatch` under the address, `last_admin` — naming kastlan's\n * companies when the answer lists them — and keksdose's `household_has_members` guard\n * above the buttons; a 429; and the rest in the app's words. The confirm stays open with\n * what was typed, for a retry; Cancel wipes it.\n *\n * **After success** the card says the account is deactivated and the person is being\n * signed out — the app's to do, since the kit sends nothing (auth §8).\n */\nexport function DeleteAccountSetting({\n email,\n mode,\n days = 30,\n consequences,\n handOverCount,\n onRequest,\n describeError,\n labels: labelsProp,\n className,\n ...rest\n}: DeleteAccountSettingProps) {\n const labels = useKitLabels(\"deleteAccount\", DEFAULT_DELETE_ACCOUNT_LABELS, labelsProp);\n // The guards speak the tile's words, so \"Type “…” to confirm\" and \"Enter your password\n // to confirm\" are translated once, in `dangerConfirm`.\n const guardLabels = useKitLabels(\"dangerConfirm\", DEFAULT_DANGER_CONFIRM_LABELS);\n const locale = useKitLocale();\n const [typed, setTyped] = useState(\"\");\n const [password, setPassword] = useState(\"\");\n const [busy, setBusy] = useState(false);\n const [fieldError, setFieldError] = useState<\"email\" | \"password\" | null>(null);\n const [failure, setFailure] = useState<ReactNode>(null);\n const [done, setDone] = useState(false);\n const mounted = useMounted();\n const typedRef = useRef<HTMLInputElement>(null);\n const passwordRef = useRef<HTMLInputElement>(null);\n const doneRef = useRef<HTMLDivElement>(null);\n // The tile went with the press; the answer takes the focus, so it is read out.\n useFocusWhen(done, doneRef);\n\n const modeSentence = mode === \"operator\" ? labels.operator : labels.afterDays(days);\n\n const lines: (string | DangerConsequence)[] = (consequences ?? [])\n // `{cond && \"…\"}` lines that came out empty are no lines.\n .filter((item) => item !== null && item !== undefined && item !== false && item !== \"\")\n .map((item, index) => (isConsequence(item) ? item : { key: `app-${index}`, text: item }));\n if (handOverCount !== undefined && handOverCount > 0) {\n lines.push({ key: \"hand-over\", text: labels.handOver(handOverCount) });\n }\n\n // The first guard still open, in the order the fields are drawn — DangerConfirm's rule.\n const held = !typedMatches(typed, email, \"caseless\")\n ? typeof guardLabels.needsPhrase === \"function\"\n ? guardLabels.needsPhrase(email)\n : guardLabels.needsPhrase\n : password === \"\"\n ? guardLabels.needsPassword\n : undefined;\n\n const present = (error: unknown) => {\n const own = describeError?.(error);\n if (hasMessage(own)) {\n setFailure(own);\n return;\n }\n if (isRateLimited(error)) {\n setFailure(labels.rateLimited(retryAfterSeconds(error)));\n return;\n }\n const code = authErrorCode(error);\n // `invalid_credentials` too, for a server that answered a wrong password so before\n // server-kit 0.4.0 named `password_incorrect`.\n if (code === \"password_incorrect\" || code === \"invalid_credentials\") {\n setFieldError(\"password\");\n passwordRef.current?.focus();\n return;\n }\n if (code === \"confirmation_mismatch\" || code === \"confirmation_required\") {\n setFieldError(\"email\");\n typedRef.current?.focus();\n return;\n }\n if (code === \"last_admin\") {\n const companies = refusalCompanies(error);\n setFailure(\n companies\n ? labels.lastAdminOf(new Intl.ListFormat(locale, { type: \"conjunction\" }).format(companies))\n : labels.lastAdmin,\n );\n return;\n }\n setFailure(code === \"household_has_members\" ? labels.householdHasMembers : labels.failed);\n };\n\n const confirm = () => {\n setFailure(null);\n setFieldError(null);\n setBusy(true);\n const values: DeleteAccountValues = { password, confirmEmail: typed.trim() };\n return settle(() => onRequest(values)).then(\n () => {\n if (!mounted.current) return;\n setBusy(false);\n setDone(true);\n },\n (error: unknown) => {\n if (mounted.current) {\n setBusy(false);\n present(error);\n }\n // Rejected again, so DangerConfirm stays armed with what was typed.\n throw error;\n },\n );\n };\n\n // A disarmed tile holds no password — DangerConfirm's own rule, for the fields it\n // does not own here.\n const disarmed = (armed: boolean) => {\n if (armed) return;\n setTyped(\"\");\n setPassword(\"\");\n setFieldError(null);\n setFailure(null);\n };\n\n return (\n <Card\n {...rest}\n data-state={done ? \"done\" : \"form\"}\n tone=\"danger\"\n className={cn(\"p-4 space-y-3\", className)}\n >\n <div>\n <SettingsCardTitle>{labels.title}</SettingsCardTitle>\n <div className={CARD_DESCRIPTION_CLASS}>{modeSentence}</div>\n </div>\n {done ? (\n <div ref={doneRef} tabIndex={-1} role=\"status\" className=\"flex items-start gap-2 text-sm outline-none\">\n <UserX aria-hidden className=\"mt-0.5 size-4 shrink-0 text-[var(--text-muted)]\" />\n <span>{labels.done}</span>\n </div>\n ) : (\n <>\n <DangerConfirm\n commit\n armLabel={labels.arm}\n prompt={labels.prompt}\n consequences={lines}\n confirmLabel={labels.confirm}\n confirmDisabledReason={held}\n busy={busy}\n onArmedChange={disarmed}\n onConfirm={confirm}\n >\n <TypedConfirmField\n ref={typedRef}\n target={email}\n match=\"caseless\"\n value={typed}\n onValueChange={(next) => {\n setTyped(next);\n if (fieldError === \"email\") setFieldError(null);\n }}\n error={fieldError === \"email\" ? labels.confirmationMismatch : undefined}\n busy={busy}\n />\n <CurrentPasswordInput\n ref={passwordRef}\n value={password}\n onValueChange={(next) => {\n setPassword(next);\n if (fieldError === \"password\") setFieldError(null);\n }}\n error={fieldError === \"password\" ? labels.wrongPassword : undefined}\n busy={busy}\n />\n </DangerConfirm>\n {hasMessage(failure) && (\n <AlertBanner tone=\"danger\" size=\"sm\" role=\"alert\">\n {failure}\n </AlertBanner>\n )}\n </>\n )}\n </Card>\n );\n}\n"],"mappings":";AAoTM,SAUE,UATA,KADF;AApTN,SAAS,gBAAgB,QAAQ,gBAAgB;AAEjD,SAAS,aAAa;AAEtB,SAAS,cAAc,oBAAoB;AAC3C,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,YAAY;AACrB,SAAS,eAAe,oBAAoB,eAAe,yBAAyB;AACpF,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB,kBAAkB,QAAQ,kBAAkB;AAC7E,SAAS,yBAAyB;AA+C3B,MAAM,gCAAqD;AAAA,EAChE,OAAO;AAAA,EACP,WAAW,CAAC,SACV,SAAS,IACL,yEACA,2DAA2D,IAAI;AAAA,EACrE,UAAU;AAAA,EACV,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,UAAU,CAAC,UACT,UAAU,IACN,yDACA,GAAG,KAA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,oBACA,OAAO,eAAe,UAAU,OAAO,uBAAuB;AAAA,oBAC9D;AAAA;AAAA,gBACF;AAAA,gBACA;AAAA,kBAAC;AAAA;AAAA,oBACC,KAAK;AAAA,oBACL,OAAO;AAAA,oBACP,eAAe,CAAC,SAAS;AACvB,kCAAY,IAAI;AAChB,0BAAI,eAAe,WAAY,eAAc,IAAI;AAAA,oBACnD;AAAA,oBACA,OAAO,eAAe,aAAa,OAAO,gBAAgB;AAAA,oBAC1D;AAAA;AAAA,gBACF;AAAA;AAAA;AAAA,UACF;AAAA,UACC,WAAW,OAAO,KACjB,oBAAC,eAAY,MAAK,UAAS,MAAK,MAAK,MAAK,SACvC,mBACH;AAAA,WAEJ;AAAA;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
@@ -0,0 +1,136 @@
1
+ import * as react from 'react';
2
+ import { ComponentPropsWithoutRef, ReactNode } from 'react';
3
+
4
+ /** Every string {@link EmailChangeSetting} renders — the `emailChange` namespace of
5
+ * `<UiKitProvider labels>`, overridable per instance through `labels`. */
6
+ interface EmailChangeLabels {
7
+ /** The card's title. */
8
+ title: string;
9
+ /** Names the address the account has now: "Current address: ada@example.com". */
10
+ current: string;
11
+ /** The new address's field. */
12
+ newEmail: string;
13
+ /** The password field. */
14
+ password: string;
15
+ /** Under the password field: why it is asked again. */
16
+ passwordHint: string;
17
+ /** The address-tag button (auth §4.5), given the exact address it would use. */
18
+ emailTagUse: (address: string) => string;
19
+ /** The line after the address-tag button. */
20
+ emailTagHint: string;
21
+ /** The submit button. */
22
+ submit: string;
23
+ /** Under the new address while it is the current one. */
24
+ sameAsCurrent: string;
25
+ /** `email_taken`, under the new address. */
26
+ emailTaken: string;
27
+ /** `password_incorrect`, under the password. */
28
+ wrongPassword: string;
29
+ /** The pending state, given the new address the link went to. */
30
+ pending: (newEmail: string) => string;
31
+ /** Under it, given the current address — which still signs in until the link is
32
+ * confirmed. */
33
+ pendingHint: (currentEmail: string) => string;
34
+ /** Mails the link again. */
35
+ resend: string;
36
+ /** Said once it went. */
37
+ resent: string;
38
+ /** Drops the change; the current address stays. */
39
+ cancel: string;
40
+ /** The done state (`confirmed`), given the address the account has now. */
41
+ confirmed: (email: string) => string;
42
+ /** Under it (`passkeyNote`): a passkey's label in the authenticator keeps the old
43
+ * address (§6.2). */
44
+ passkeyNote: string;
45
+ /** A request was throttled — HTTP 429 — given its `Retry-After` wait in seconds, or
46
+ * `undefined` without one. */
47
+ rateLimited: (seconds?: number) => string;
48
+ /** Any other failure, of any of the three requests. */
49
+ failed: string;
50
+ }
51
+ declare const DEFAULT_EMAIL_CHANGE_LABELS: EmailChangeLabels;
52
+ /** What {@link EmailChangeSettingProps.onRequest} gets: the `POST /auth/me/email` body. */
53
+ interface EmailChangeValues {
54
+ /** Trimmed. A `+tag` stays (auth §4.5); lower-casing is the server's. */
55
+ newEmail: string;
56
+ /** As typed. */
57
+ password: string;
58
+ }
59
+ /** Which request failed — {@link EmailChangeSettingProps.describeError}'s second
60
+ * argument. */
61
+ type EmailChangeAction = "request" | "resend" | "cancel";
62
+ interface EmailChangeSettingProps extends Omit<ComponentPropsWithoutRef<"div">, "children" | "onSubmit"> {
63
+ /** The account's address now. */
64
+ currentEmail: string;
65
+ /**
66
+ * The address a change waits on, from the app's server state — so a reload, or
67
+ * another tab, shows the pending state. `null`: none, whatever the card did. Left out
68
+ * (`undefined`), the card keeps its own: pending from a resolved `onRequest` until a
69
+ * resolved `onCancel`.
70
+ */
71
+ pendingEmail?: string | null;
72
+ /**
73
+ * The form was submitted: send `POST /auth/me/email {new_email, password}` (§6.2).
74
+ * Resolve once the link is mailed — refresh `pendingEmail` first if the app passes
75
+ * it — and the card shows "Confirm the link we sent to …". Reject with the client's
76
+ * error: `email_taken` shows under the new address, `password_incorrect` (server-kit's
77
+ * `400` for a wrong current password; an older `invalid_credentials` too) under the
78
+ * password, a 429 as `rateLimited`, anything else as `failed` unless `describeError`
79
+ * has the app's words.
80
+ */
81
+ onRequest: (values: EmailChangeValues) => Promise<unknown> | void;
82
+ /** Mail the link again. Left out, no button. */
83
+ onResend?: () => Promise<unknown> | void;
84
+ /** Drop the pending change. Left out, no button. */
85
+ onCancel?: () => Promise<unknown> | void;
86
+ /**
87
+ * The change was just confirmed — the app's confirm route (`POST /auth/me/email/confirm`)
88
+ * came back here. Says "Your email address is now …" over the form, with
89
+ * `passkeyNote`.
90
+ */
91
+ confirmed?: boolean;
92
+ /** With `confirmed`: say that a passkey's label keeps the old address (§6.2). Default
93
+ * `true`; `false` for an account without passkeys. */
94
+ passkeyNote?: boolean;
95
+ /**
96
+ * The app's address tag (`"kastlan"`, auth §4.5): once the new address is plausible a
97
+ * button under it offers the tagged form — the rule of `RegisterForm`, since this is
98
+ * the person's own address. Never applied on its own. Left out, no offer.
99
+ */
100
+ emailTag?: string;
101
+ /** The app's own words for a failure, or `undefined` for the kit's. Asked first, for
102
+ * every failure (a demo account's 403, the device offline). */
103
+ describeError?: (error: unknown, action: EmailChangeAction) => ReactNode | undefined;
104
+ labels?: Partial<EmailChangeLabels>;
105
+ }
106
+ /**
107
+ * Changing the account's email address (docs/user-admin-harmonization.md §6.2, §2.5):
108
+ * the current address, the new one, the password — then a pending state until the new
109
+ * address confirms its link.
110
+ *
111
+ * **The new address must confirm before it takes effect.** The server mails a one-time
112
+ * link to the NEW address (and a notice to the old one); until it is opened, the account
113
+ * keeps the old address and signs in with it. So the card's answer to a request is not
114
+ * "changed" but "Confirm the link we sent to …", with "Send the link again" and "Cancel
115
+ * the change". The state is the server's: pass `pendingEmail` and a reload shows it too.
116
+ *
117
+ * **The password is asked again** because the address is the identity: whoever holds the
118
+ * session must not move the account to a mailbox of their own. It is a
119
+ * {@link CurrentPasswordInput}, so a password manager fills it and offers no new one.
120
+ *
121
+ * **The `+tag` offer** (`emailTag`) is RegisterForm's: the address is the person's own,
122
+ * so `you+kastlan@…` is offered under the field, applied only on a click.
123
+ *
124
+ * **It never sends a request** (auth §8): `onRequest`, `onResend` and `onCancel` are the
125
+ * app's, and their refusals are read by code — `email_taken` and `password_incorrect`
126
+ * under their fields, which take the focus; a 429 as "Too many attempts". A wrong
127
+ * password is a `400 password_incorrect`, never a 401: an app's client reads a 401 on a
128
+ * signed-in route as an ended session, and would sign the person out for a typo.
129
+ *
130
+ * **Done** (`confirmed`): "Your email address is now …" and, unless `passkeyNote` is
131
+ * off, that a passkey keeps its old label in the device's list — the authenticator
132
+ * stored the name it was given, and only a new passkey carries the new one.
133
+ */
134
+ declare function EmailChangeSetting({ currentEmail, pendingEmail, onRequest, onResend, onCancel, confirmed, passkeyNote, emailTag, describeError, labels: labelsProp, className, ...rest }: EmailChangeSettingProps): react.JSX.Element;
135
+
136
+ export { DEFAULT_EMAIL_CHANGE_LABELS, type EmailChangeAction, type EmailChangeLabels, EmailChangeSetting, type EmailChangeSettingProps, type EmailChangeValues };
@@ -0,0 +1,278 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useId, useRef, useState } from "react";
4
+ import { MailCheck } from "lucide-react";
5
+ import { DEFAULT_COMMON_LABELS, useKitLabels } from "../i18n/kit-labels.js";
6
+ import { cn } from "../lib/cn.js";
7
+ import { AlertBanner } from "../components/alert-banner.js";
8
+ import { hasMessage } from "../components/choice-parts.js";
9
+ import { CurrentPasswordInput } from "../components/danger-confirm.js";
10
+ import { Button, Card, Input } from "../components/ui.js";
11
+ import { authErrorCode, englishRateLimited, isRateLimited, retryAfterSeconds } from "../auth/auth-errors.js";
12
+ import { emailParts, taggedEmail } from "../auth/email-tag.js";
13
+ import { CARD_DESCRIPTION_CLASS, settle, useMounted } from "./account-parts.js";
14
+ import { SettingsCardTitle } from "../settings/settings-heading.js";
15
+ const DEFAULT_EMAIL_CHANGE_LABELS = {
16
+ title: "Email address",
17
+ current: "Current address",
18
+ newEmail: "New email address",
19
+ password: "Current password",
20
+ passwordHint: "Your address is how you sign in, so changing it takes your password.",
21
+ emailTagUse: (address) => `Use ${address}`,
22
+ emailTagHint: "Many providers deliver name+tag@\u2026 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.",
23
+ submit: "Change email address",
24
+ sameAsCurrent: "This is already your address.",
25
+ emailTaken: "An account with this email address already exists.",
26
+ wrongPassword: "The password is incorrect.",
27
+ pending: (newEmail) => `Confirm the link we sent to ${newEmail}.`,
28
+ pendingHint: (currentEmail) => `Until you do, you keep signing in with ${currentEmail}. Check your spam folder too.`,
29
+ resend: "Send the link again",
30
+ resent: "We sent the link again.",
31
+ cancel: "Cancel the change",
32
+ confirmed: (email) => `Your email address is now ${email}.`,
33
+ passkeyNote: "Your passkeys keep working. Your device may still list them under your old address.",
34
+ rateLimited: englishRateLimited,
35
+ failed: "That didn\u2019t work. Please try again."
36
+ };
37
+ function EmailChangeSetting({
38
+ currentEmail,
39
+ pendingEmail,
40
+ onRequest,
41
+ onResend,
42
+ onCancel,
43
+ confirmed,
44
+ passkeyNote = true,
45
+ emailTag,
46
+ describeError,
47
+ labels: labelsProp,
48
+ className,
49
+ ...rest
50
+ }) {
51
+ const labels = useKitLabels("emailChange", DEFAULT_EMAIL_CHANGE_LABELS, labelsProp);
52
+ const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
53
+ const [newEmail, setNewEmail] = useState("");
54
+ const [password, setPassword] = useState("");
55
+ const [ownPending, setOwnPending] = useState(null);
56
+ const [busy, setBusy] = useState(null);
57
+ const [failure, setFailure] = useState(null);
58
+ const [taken, setTaken] = useState(null);
59
+ const [wrongPassword, setWrongPassword] = useState(false);
60
+ const [resent, setResent] = useState(false);
61
+ const mounted = useMounted();
62
+ const titleId = useId();
63
+ const tagHintId = useId();
64
+ const emailRef = useRef(null);
65
+ const passwordRef = useRef(null);
66
+ const pendingRef = useRef(null);
67
+ const pending = pendingEmail !== void 0 ? pendingEmail : ownPending;
68
+ const isPending = pending !== null && pending !== "";
69
+ const focusNext = useRef(null);
70
+ useEffect(() => {
71
+ const target = focusNext.current;
72
+ if (target === "pending" && isPending) {
73
+ focusNext.current = null;
74
+ pendingRef.current?.focus();
75
+ } else if (target === "form" && !isPending) {
76
+ focusNext.current = null;
77
+ emailRef.current?.focus();
78
+ }
79
+ }, [isPending]);
80
+ const messageFor = (error, action) => {
81
+ const own = describeError?.(error, action);
82
+ if (hasMessage(own)) return own;
83
+ return isRateLimited(error) ? labels.rateLimited(retryAfterSeconds(error)) : labels.failed;
84
+ };
85
+ if (isPending) {
86
+ const run = (action, call) => {
87
+ if (busy) return;
88
+ setBusy(action);
89
+ setFailure(null);
90
+ setResent(false);
91
+ settle(call).then(
92
+ () => {
93
+ if (!mounted.current) return;
94
+ setBusy(null);
95
+ if (action === "resend") {
96
+ setResent(true);
97
+ return;
98
+ }
99
+ focusNext.current = "form";
100
+ setOwnPending(null);
101
+ },
102
+ (error) => {
103
+ if (!mounted.current) return;
104
+ setBusy(null);
105
+ setFailure({ action, message: messageFor(error, action) });
106
+ }
107
+ );
108
+ };
109
+ return /* @__PURE__ */ jsxs(Card, { ...rest, "data-state": "pending", className: cn("p-4 space-y-3", className), children: [
110
+ /* @__PURE__ */ jsxs("div", { children: [
111
+ /* @__PURE__ */ jsx(SettingsCardTitle, { id: titleId, children: labels.title }),
112
+ /* @__PURE__ */ jsx("div", { className: cn(CARD_DESCRIPTION_CLASS, "break-all"), children: common.fieldValue(labels.current, currentEmail) })
113
+ ] }),
114
+ /* @__PURE__ */ jsxs("div", { ref: pendingRef, tabIndex: -1, className: "flex gap-2 outline-none", children: [
115
+ /* @__PURE__ */ jsx(MailCheck, { "aria-hidden": true, className: "mt-0.5 size-4 shrink-0 text-[var(--success)]" }),
116
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 space-y-1", children: [
117
+ /* @__PURE__ */ jsx("p", { className: "break-words text-sm", children: labels.pending(pending) }),
118
+ /* @__PURE__ */ jsx("p", { className: CARD_DESCRIPTION_CLASS, children: labels.pendingHint(currentEmail) })
119
+ ] })
120
+ ] }),
121
+ (onResend || onCancel) && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
122
+ onResend && /* @__PURE__ */ jsx(
123
+ Button,
124
+ {
125
+ type: "button",
126
+ variant: "secondary",
127
+ size: "sm",
128
+ commit: true,
129
+ pending: busy === "resend",
130
+ disabled: busy === "cancel",
131
+ onClick: () => run("resend", onResend),
132
+ children: labels.resend
133
+ }
134
+ ),
135
+ onCancel && /* @__PURE__ */ jsx(
136
+ Button,
137
+ {
138
+ type: "button",
139
+ variant: "ghost",
140
+ size: "sm",
141
+ commit: true,
142
+ pending: busy === "cancel",
143
+ disabled: busy === "resend",
144
+ onClick: () => run("cancel", onCancel),
145
+ children: labels.cancel
146
+ }
147
+ ),
148
+ /* @__PURE__ */ jsx("span", { role: "status", className: "text-xs text-[var(--success)]", children: resent ? labels.resent : null })
149
+ ] }),
150
+ failure && /* @__PURE__ */ jsx(AlertBanner, { tone: "danger", size: "sm", role: "alert", children: failure.message })
151
+ ] });
152
+ }
153
+ const typed = newEmail.trim();
154
+ const same = typed !== "" && typed.toLowerCase() === currentEmail.trim().toLowerCase();
155
+ const working = busy !== null;
156
+ const canSubmit = emailParts(newEmail) !== null && !same && password !== "";
157
+ const suggestion = emailTag ? taggedEmail(newEmail, emailTag) : null;
158
+ const emailError = same ? labels.sameAsCurrent : taken !== null && taken === typed ? labels.emailTaken : void 0;
159
+ const submit = (e) => {
160
+ e.preventDefault();
161
+ if (!canSubmit || working) return;
162
+ const values = { newEmail: typed, password };
163
+ setBusy("request");
164
+ setFailure(null);
165
+ setTaken(null);
166
+ setWrongPassword(false);
167
+ settle(() => onRequest(values)).then(
168
+ () => {
169
+ if (!mounted.current) return;
170
+ setBusy(null);
171
+ setNewEmail("");
172
+ setPassword("");
173
+ setResent(false);
174
+ focusNext.current = "pending";
175
+ setOwnPending(values.newEmail);
176
+ },
177
+ (error) => {
178
+ if (!mounted.current) return;
179
+ setBusy(null);
180
+ const own = describeError?.(error, "request");
181
+ if (hasMessage(own)) {
182
+ setFailure({ action: "request", message: own });
183
+ return;
184
+ }
185
+ if (isRateLimited(error)) {
186
+ setFailure({ action: "request", message: labels.rateLimited(retryAfterSeconds(error)) });
187
+ return;
188
+ }
189
+ const code = authErrorCode(error);
190
+ if (code === "email_taken") {
191
+ setTaken(values.newEmail);
192
+ emailRef.current?.focus();
193
+ return;
194
+ }
195
+ if (code === "password_incorrect" || code === "invalid_credentials") {
196
+ setWrongPassword(true);
197
+ passwordRef.current?.focus();
198
+ return;
199
+ }
200
+ setFailure({ action: "request", message: labels.failed });
201
+ }
202
+ );
203
+ };
204
+ return /* @__PURE__ */ jsxs(Card, { ...rest, "data-state": confirmed ? "confirmed" : "form", className: cn("p-4 space-y-3", className), children: [
205
+ /* @__PURE__ */ jsxs("div", { children: [
206
+ /* @__PURE__ */ jsx(SettingsCardTitle, { id: titleId, children: labels.title }),
207
+ /* @__PURE__ */ jsx("div", { className: cn(CARD_DESCRIPTION_CLASS, "break-all"), children: common.fieldValue(labels.current, currentEmail) })
208
+ ] }),
209
+ confirmed && /* @__PURE__ */ jsxs(AlertBanner, { tone: "success", size: "sm", children: [
210
+ /* @__PURE__ */ jsx("span", { className: "block", children: labels.confirmed(currentEmail) }),
211
+ passkeyNote && /* @__PURE__ */ jsx("span", { className: "mt-1 block", children: labels.passkeyNote })
212
+ ] }),
213
+ /* @__PURE__ */ jsxs("form", { className: "space-y-3", "aria-labelledby": titleId, onSubmit: submit, noValidate: true, children: [
214
+ /* @__PURE__ */ jsxs("div", { children: [
215
+ /* @__PURE__ */ jsx(
216
+ Input,
217
+ {
218
+ ref: emailRef,
219
+ type: "email",
220
+ name: "email",
221
+ autoComplete: "email",
222
+ label: labels.newEmail,
223
+ value: newEmail,
224
+ onChange: (e) => {
225
+ setNewEmail(e.target.value);
226
+ if (failure) setFailure(null);
227
+ },
228
+ readOnly: working,
229
+ error: emailError,
230
+ required: true
231
+ }
232
+ ),
233
+ suggestion && /* @__PURE__ */ jsxs("p", { className: "mt-1 text-xs text-[var(--text-muted)]", children: [
234
+ /* @__PURE__ */ jsx(
235
+ Button,
236
+ {
237
+ type: "button",
238
+ variant: "link",
239
+ size: "sm",
240
+ className: "h-auto p-0 align-baseline",
241
+ disabled: working,
242
+ "aria-describedby": tagHintId,
243
+ onClick: () => setNewEmail(suggestion),
244
+ children: labels.emailTagUse(suggestion)
245
+ }
246
+ ),
247
+ " ",
248
+ /* @__PURE__ */ jsx("span", { id: tagHintId, children: labels.emailTagHint })
249
+ ] })
250
+ ] }),
251
+ /* @__PURE__ */ jsx(
252
+ CurrentPasswordInput,
253
+ {
254
+ ref: passwordRef,
255
+ name: "password",
256
+ label: labels.password,
257
+ value: password,
258
+ onValueChange: (next) => {
259
+ setPassword(next);
260
+ setWrongPassword(false);
261
+ if (failure) setFailure(null);
262
+ },
263
+ hint: labels.passwordHint,
264
+ error: wrongPassword ? labels.wrongPassword : void 0,
265
+ busy: working,
266
+ required: true
267
+ }
268
+ ),
269
+ failure && /* @__PURE__ */ jsx(AlertBanner, { tone: "danger", size: "sm", role: "alert", children: failure.message }),
270
+ /* @__PURE__ */ jsx(Button, { type: "submit", commit: true, disabled: !working && !canSubmit, pending: working, children: labels.submit })
271
+ ] })
272
+ ] });
273
+ }
274
+ export {
275
+ DEFAULT_EMAIL_CHANGE_LABELS,
276
+ EmailChangeSetting
277
+ };
278
+ //# sourceMappingURL=email-change-setting.js.map