@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.
- package/README.md +65 -6
- package/dist/account/account-parts.d.ts +21 -0
- package/dist/account/account-parts.js +40 -0
- package/dist/account/account-parts.js.map +1 -0
- package/dist/account/data-export-setting.d.ts +73 -0
- package/dist/account/data-export-setting.js +114 -0
- package/dist/account/data-export-setting.js.map +1 -0
- package/dist/account/delete-account-setting.d.ts +95 -0
- package/dist/account/delete-account-setting.js +200 -0
- package/dist/account/delete-account-setting.js.map +1 -0
- package/dist/account/email-change-setting.d.ts +136 -0
- package/dist/account/email-change-setting.js +278 -0
- package/dist/account/email-change-setting.js.map +1 -0
- package/dist/account/sessions-setting.d.ts +110 -0
- package/dist/account/sessions-setting.js +147 -0
- package/dist/account/sessions-setting.js.map +1 -0
- package/dist/admin/admin-action-confirm.d.ts +95 -0
- package/dist/admin/admin-action-confirm.js +276 -0
- package/dist/admin/admin-action-confirm.js.map +1 -0
- package/dist/admin/admin-action-log.d.ts +105 -0
- package/dist/admin/admin-action-log.js +153 -0
- package/dist/admin/admin-action-log.js.map +1 -0
- package/dist/admin/admin-parts.d.ts +40 -0
- package/dist/admin/admin-parts.js +45 -0
- package/dist/admin/admin-parts.js.map +1 -0
- package/dist/admin/invitations-panel.d.ts +95 -0
- package/dist/admin/invitations-panel.js +290 -0
- package/dist/admin/invitations-panel.js.map +1 -0
- package/dist/admin/reviewer-scope-editor.d.ts +95 -0
- package/dist/admin/reviewer-scope-editor.js +134 -0
- package/dist/admin/reviewer-scope-editor.js.map +1 -0
- package/dist/admin/role-select.d.ts +95 -0
- package/dist/admin/role-select.js +128 -0
- package/dist/admin/role-select.js.map +1 -0
- package/dist/admin/transfer-ownership-dialog.d.ts +95 -0
- package/dist/admin/transfer-ownership-dialog.js +83 -0
- package/dist/admin/transfer-ownership-dialog.js.map +1 -0
- package/dist/admin/user-roster.d.ts +95 -0
- package/dist/admin/user-roster.js +285 -0
- package/dist/admin/user-roster.js.map +1 -0
- package/dist/auth/auth-errors.d.ts +103 -6
- package/dist/auth/auth-errors.js +68 -2
- package/dist/auth/auth-errors.js.map +1 -1
- package/dist/auth/forgot-password-form.d.ts +10 -3
- package/dist/auth/forgot-password-form.js +6 -3
- package/dist/auth/forgot-password-form.js.map +1 -1
- package/dist/auth/register-form.d.ts +21 -12
- package/dist/auth/register-form.js +6 -4
- package/dist/auth/register-form.js.map +1 -1
- package/dist/auth/reset-password-form.d.ts +10 -3
- package/dist/auth/reset-password-form.js +6 -3
- package/dist/auth/reset-password-form.js.map +1 -1
- package/dist/auth/sign-in-form.d.ts +75 -9
- package/dist/auth/sign-in-form.js +105 -15
- package/dist/auth/sign-in-form.js.map +1 -1
- package/dist/auth/verify-email.d.ts +7 -2
- package/dist/auth/verify-email.js +44 -8
- package/dist/auth/verify-email.js.map +1 -1
- package/dist/chart.d.ts +20 -11
- package/dist/components/account-chips.d.ts +47 -7
- package/dist/components/account-chips.js +19 -3
- package/dist/components/account-chips.js.map +1 -1
- package/dist/components/account-settings-labels.d.ts +24 -1
- package/dist/components/account-settings-labels.js +6 -2
- package/dist/components/account-settings-labels.js.map +1 -1
- package/dist/components/account-settings.d.ts +69 -8
- package/dist/components/account-settings.js +133 -25
- package/dist/components/account-settings.js.map +1 -1
- package/dist/components/amount-input.d.ts +21 -12
- package/dist/components/button-group.d.ts +21 -12
- package/dist/components/calculator.d.ts +21 -12
- package/dist/components/confirm-dialog.d.ts +21 -12
- package/dist/components/copy-button.d.ts +18 -9
- package/dist/components/danger-confirm.d.ts +21 -12
- package/dist/components/data-table.js +8 -1
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.js +9 -4
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/facing-pair.d.ts +21 -12
- package/dist/components/file-button.d.ts +21 -12
- package/dist/components/file-dropzone.d.ts +21 -12
- package/dist/components/form-actions.d.ts +21 -12
- package/dist/components/iban-input.d.ts +21 -12
- package/dist/components/language-select.d.ts +21 -12
- package/dist/components/legal-page.d.ts +21 -12
- package/dist/components/legal.d.ts +21 -12
- package/dist/components/money-field.d.ts +21 -12
- package/dist/components/number-field.d.ts +21 -12
- package/dist/components/number-input.d.ts +21 -12
- package/dist/components/numpad-sheet.d.ts +21 -12
- package/dist/components/passkeys-setting.js +2 -1
- package/dist/components/passkeys-setting.js.map +1 -1
- package/dist/components/phone-input.d.ts +21 -12
- package/dist/components/series-chart.d.ts +21 -12
- package/dist/components/settings-fields.d.ts +55 -13
- package/dist/components/settings-fields.js +20 -1
- package/dist/components/settings-fields.js.map +1 -1
- package/dist/components/share-card.d.ts +20 -11
- package/dist/components/text-link.d.ts +21 -12
- package/dist/components/time-input.d.ts +21 -12
- package/dist/components/ui.d.ts +17 -8
- package/dist/{register-form-V1OeNlMr.d.ts → delete-account-setting-DCFS5Vof.d.ts} +6612 -5612
- package/dist/demo/demo-banner.d.ts +51 -0
- package/dist/demo/demo-banner.js +97 -0
- package/dist/demo/demo-banner.js.map +1 -0
- package/dist/demo/demo-countdown.d.ts +58 -0
- package/dist/demo/demo-countdown.js +79 -0
- package/dist/demo/demo-countdown.js.map +1 -0
- package/dist/demo/demo-ended.d.ts +45 -0
- package/dist/demo/demo-ended.js +42 -0
- package/dist/demo/demo-ended.js.map +1 -0
- package/dist/demo/demo-labels.d.ts +53 -0
- package/dist/demo/demo-labels.js +29 -0
- package/dist/demo/demo-labels.js.map +1 -0
- package/dist/demo/demo-session.d.ts +30 -0
- package/dist/demo/demo-session.js +8 -0
- package/dist/demo/demo-session.js.map +1 -0
- package/dist/demo/demo-start.d.ts +54 -0
- package/dist/demo/demo-start.js +68 -0
- package/dist/demo/demo-start.js.map +1 -0
- package/dist/feedback/feedback-attachment.d.ts +21 -12
- package/dist/feedback/feedback-context.d.ts +21 -12
- package/dist/feedback/feedback-crash.d.ts +21 -12
- package/dist/feedback/feedback-dialog.d.ts +21 -12
- package/dist/feedback/feedback-inbox.d.ts +21 -12
- package/dist/feedback/feedback-inbox.js +12 -2
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-labels.d.ts +21 -12
- package/dist/feedback/feedback-labels.js +1 -0
- package/dist/feedback/feedback-labels.js.map +1 -1
- package/dist/feedback/feedback-menu.d.ts +21 -12
- package/dist/feedback/feedback-record.d.ts +21 -12
- package/dist/feedback/feedback-record.js +2 -0
- package/dist/feedback/feedback-record.js.map +1 -1
- package/dist/feedback/feedback-row-detail.d.ts +21 -12
- package/dist/feedback/feedback-row-detail.js +7 -0
- package/dist/feedback/feedback-row-detail.js.map +1 -1
- package/dist/feedback/feedback-status-undo.d.ts +21 -12
- package/dist/feedback/feedback-submit.d.ts +21 -12
- package/dist/feedback/feedback-swipe.d.ts +22 -13
- package/dist/feedback/feedback-swipe.js.map +1 -1
- package/dist/feedback/feedback-table.d.ts +18 -9
- package/dist/feedback/feedback-thread.d.ts +21 -12
- package/dist/feedback.d.ts +21 -12
- package/dist/hooks/use-anchored-panel.d.ts +6 -2
- package/dist/hooks/use-anchored-panel.js +2 -1
- package/dist/hooks/use-anchored-panel.js.map +1 -1
- package/dist/hooks/use-file-drop.d.ts +21 -12
- package/dist/i18n/defaults.d.ts +21 -12
- package/dist/i18n/defaults.js +28 -0
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +21 -12
- package/dist/i18n/german.js +298 -12
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +14 -5
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +15 -6
- package/dist/i18n/locales/de-CH.d.ts +21 -12
- package/dist/i18n/locales/en.d.ts +21 -12
- package/dist/i18n/locales/es.d.ts +21 -12
- package/dist/i18n/locales/es.js +287 -10
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +21 -12
- package/dist/i18n/locales/fr.js +290 -7
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +21 -12
- package/dist/i18n/locales/hu.js +288 -12
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +21 -12
- package/dist/i18n/locales/it.js +289 -7
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +21 -12
- package/dist/i18n/locales/zh.js +279 -7
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +21 -12
- package/dist/i18n/review.js +50 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +31 -4
- package/dist/index.js +148 -0
- package/dist/index.js.map +1 -1
- package/dist/landing/access.d.ts +48 -0
- package/dist/landing/access.js +38 -0
- package/dist/landing/access.js.map +1 -0
- package/dist/landing/landing-actions.d.ts +138 -0
- package/dist/landing/landing-actions.js +39 -0
- package/dist/landing/landing-actions.js.map +1 -0
- package/dist/landing/landing-labels.d.ts +43 -0
- package/dist/landing/landing-labels.js +23 -0
- package/dist/landing/landing-labels.js.map +1 -0
- package/dist/landing/landing-sections.d.ts +218 -0
- package/dist/landing/landing-sections.js +167 -0
- package/dist/landing/landing-sections.js.map +1 -0
- package/dist/landing/page-seo.d.ts +99 -0
- package/dist/landing/page-seo.js +121 -0
- package/dist/landing/page-seo.js.map +1 -0
- package/dist/landing/public-header.d.ts +148 -0
- package/dist/landing/public-header.js +49 -0
- package/dist/landing/public-header.js.map +1 -0
- package/dist/landing/routing.d.ts +218 -0
- package/dist/landing/routing.js +81 -0
- package/dist/landing/routing.js.map +1 -0
- package/dist/rhf/fields.d.ts +21 -12
- package/dist/rhf/form.d.ts +21 -12
- package/dist/rhf.d.ts +21 -12
- package/dist/settings/settings-catalogue.d.ts +84 -0
- package/dist/settings/settings-catalogue.js +47 -0
- package/dist/settings/settings-catalogue.js.map +1 -0
- package/dist/settings/settings-context.d.ts +31 -0
- package/dist/settings/settings-context.js +11 -0
- package/dist/settings/settings-context.js.map +1 -0
- package/dist/settings/settings-heading.d.ts +50 -0
- package/dist/settings/settings-heading.js +27 -0
- package/dist/settings/settings-heading.js.map +1 -0
- package/dist/settings/settings-labels.d.ts +41 -0
- package/dist/settings/settings-labels.js +38 -0
- package/dist/settings/settings-labels.js.map +1 -0
- package/dist/settings/settings-layout.d.ts +77 -0
- package/dist/settings/settings-layout.js +242 -0
- package/dist/settings/settings-layout.js.map +1 -0
- package/dist/settings/settings-section.d.ts +133 -0
- package/dist/settings/settings-section.js +63 -0
- package/dist/settings/settings-section.js.map +1 -0
- package/dist/settings/use-account-language.d.ts +83 -0
- package/dist/settings/use-account-language.js +62 -0
- package/dist/settings/use-account-language.js.map +1 -0
- package/dist/settings/use-settings-focus.d.ts +34 -0
- package/dist/settings/use-settings-focus.js +77 -0
- package/dist/settings/use-settings-focus.js.map +1 -0
- package/dist/settings/use-settings-route.d.ts +118 -0
- package/dist/settings/use-settings-route.js +120 -0
- package/dist/settings/use-settings-route.js.map +1 -0
- package/dist/shell/app-shell.d.ts +27 -12
- package/dist/shell/app-shell.js +3 -2
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/shell/top-bar-brand.d.ts +21 -12
- package/dist/shell.d.ts +25 -6
- package/dist/shell.js +56 -0
- package/dist/shell.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +21 -12
- package/dist/wizard.d.ts +21 -12
- package/package.json +2 -1
- package/src/account/account-parts.ts +67 -0
- package/src/account/data-export-setting.tsx +219 -0
- package/src/account/delete-account-setting.tsx +363 -0
- package/src/account/email-change-setting.tsx +454 -0
- package/src/account/sessions-setting.tsx +284 -0
- package/src/admin/admin-action-confirm.tsx +495 -0
- package/src/admin/admin-action-log.tsx +297 -0
- package/src/admin/admin-parts.ts +82 -0
- package/src/admin/invitations-panel.tsx +523 -0
- package/src/admin/reviewer-scope-editor.tsx +234 -0
- package/src/admin/role-select.tsx +286 -0
- package/src/admin/transfer-ownership-dialog.tsx +172 -0
- package/src/admin/user-roster.tsx +573 -0
- package/src/auth/auth-errors.ts +196 -8
- package/src/auth/forgot-password-form.tsx +21 -5
- package/src/auth/register-form.tsx +24 -6
- package/src/auth/reset-password-form.tsx +19 -5
- package/src/auth/sign-in-form.tsx +241 -38
- package/src/auth/verify-email.tsx +59 -8
- package/src/components/account-chips.tsx +64 -7
- package/src/components/account-settings-labels.ts +28 -1
- package/src/components/account-settings.tsx +231 -34
- package/src/components/data-table.tsx +8 -0
- package/src/components/date-picker.tsx +9 -4
- package/src/components/passkeys-setting.tsx +2 -1
- package/src/components/settings-fields.tsx +50 -1
- package/src/demo/demo-banner.tsx +159 -0
- package/src/demo/demo-countdown.ts +141 -0
- package/src/demo/demo-ended.tsx +89 -0
- package/src/demo/demo-labels.ts +78 -0
- package/src/demo/demo-session.ts +32 -0
- package/src/demo/demo-start.tsx +150 -0
- package/src/feedback/feedback-inbox.tsx +21 -8
- package/src/feedback/feedback-labels.ts +2 -1
- package/src/feedback/feedback-record.ts +10 -7
- package/src/feedback/feedback-row-detail.tsx +28 -4
- package/src/feedback/feedback-swipe.tsx +1 -1
- package/src/hooks/use-anchored-panel.ts +14 -3
- package/src/i18n/defaults.ts +28 -0
- package/src/i18n/german.ts +327 -5
- package/src/i18n/kit-labels.tsx +42 -0
- package/src/i18n/locales/es.ts +313 -3
- package/src/i18n/locales/fr.ts +316 -0
- package/src/i18n/locales/hu.ts +308 -5
- package/src/i18n/locales/it.ts +313 -0
- package/src/i18n/locales/zh.ts +286 -0
- package/src/i18n/review.ts +49 -0
- package/src/index.ts +184 -0
- package/src/landing/access.ts +97 -0
- package/src/landing/landing-actions.tsx +92 -0
- package/src/landing/landing-labels.ts +59 -0
- package/src/landing/landing-sections.tsx +337 -0
- package/src/landing/page-seo.ts +251 -0
- package/src/landing/public-header.tsx +120 -0
- package/src/landing/routing.tsx +209 -0
- package/src/settings/settings-catalogue.ts +132 -0
- package/src/settings/settings-context.ts +33 -0
- package/src/settings/settings-heading.tsx +65 -0
- package/src/settings/settings-labels.ts +75 -0
- package/src/settings/settings-layout.tsx +379 -0
- package/src/settings/settings-section.tsx +108 -0
- package/src/settings/use-account-language.ts +146 -0
- package/src/settings/use-settings-focus.ts +120 -0
- package/src/settings/use-settings-route.ts +258 -0
- package/src/shell/app-shell.tsx +10 -2
- package/src/shell.ts +45 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
2
|
+
import type { ComponentPropsWithoutRef, FormEvent, ReactNode } from "react";
|
|
3
|
+
import { MailCheck } from "lucide-react";
|
|
4
|
+
|
|
5
|
+
import { DEFAULT_COMMON_LABELS, useKitLabels } from "../i18n/kit-labels";
|
|
6
|
+
import { cn } from "../lib/cn";
|
|
7
|
+
import { AlertBanner } from "../components/alert-banner";
|
|
8
|
+
import { hasMessage } from "../components/choice-parts";
|
|
9
|
+
import { CurrentPasswordInput } from "../components/danger-confirm";
|
|
10
|
+
import { Button, Card, Input } from "../components/ui";
|
|
11
|
+
import { authErrorCode, englishRateLimited, isRateLimited, retryAfterSeconds } from "../auth/auth-errors";
|
|
12
|
+
import { emailParts, taggedEmail } from "../auth/email-tag";
|
|
13
|
+
import { CARD_DESCRIPTION_CLASS, settle, useMounted } from "./account-parts";
|
|
14
|
+
import { SettingsCardTitle } from "../settings/settings-heading";
|
|
15
|
+
|
|
16
|
+
/* ── Labels ──────────────────────────────────────────────────────────────── */
|
|
17
|
+
|
|
18
|
+
/** Every string {@link EmailChangeSetting} renders — the `emailChange` namespace of
|
|
19
|
+
* `<UiKitProvider labels>`, overridable per instance through `labels`. */
|
|
20
|
+
export interface EmailChangeLabels {
|
|
21
|
+
/** The card's title. */
|
|
22
|
+
title: string;
|
|
23
|
+
/** Names the address the account has now: "Current address: ada@example.com". */
|
|
24
|
+
current: string;
|
|
25
|
+
/** The new address's field. */
|
|
26
|
+
newEmail: string;
|
|
27
|
+
/** The password field. */
|
|
28
|
+
password: string;
|
|
29
|
+
/** Under the password field: why it is asked again. */
|
|
30
|
+
passwordHint: string;
|
|
31
|
+
/** The address-tag button (auth §4.5), given the exact address it would use. */
|
|
32
|
+
emailTagUse: (address: string) => string;
|
|
33
|
+
/** The line after the address-tag button. */
|
|
34
|
+
emailTagHint: string;
|
|
35
|
+
/** The submit button. */
|
|
36
|
+
submit: string;
|
|
37
|
+
/** Under the new address while it is the current one. */
|
|
38
|
+
sameAsCurrent: string;
|
|
39
|
+
/** `email_taken`, under the new address. */
|
|
40
|
+
emailTaken: string;
|
|
41
|
+
/** `password_incorrect`, under the password. */
|
|
42
|
+
wrongPassword: string;
|
|
43
|
+
/** The pending state, given the new address the link went to. */
|
|
44
|
+
pending: (newEmail: string) => string;
|
|
45
|
+
/** Under it, given the current address — which still signs in until the link is
|
|
46
|
+
* confirmed. */
|
|
47
|
+
pendingHint: (currentEmail: string) => string;
|
|
48
|
+
/** Mails the link again. */
|
|
49
|
+
resend: string;
|
|
50
|
+
/** Said once it went. */
|
|
51
|
+
resent: string;
|
|
52
|
+
/** Drops the change; the current address stays. */
|
|
53
|
+
cancel: string;
|
|
54
|
+
/** The done state (`confirmed`), given the address the account has now. */
|
|
55
|
+
confirmed: (email: string) => string;
|
|
56
|
+
/** Under it (`passkeyNote`): a passkey's label in the authenticator keeps the old
|
|
57
|
+
* address (§6.2). */
|
|
58
|
+
passkeyNote: string;
|
|
59
|
+
/** A request was throttled — HTTP 429 — given its `Retry-After` wait in seconds, or
|
|
60
|
+
* `undefined` without one. */
|
|
61
|
+
rateLimited: (seconds?: number) => string;
|
|
62
|
+
/** Any other failure, of any of the three requests. */
|
|
63
|
+
failed: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const DEFAULT_EMAIL_CHANGE_LABELS: EmailChangeLabels = {
|
|
67
|
+
title: "Email address",
|
|
68
|
+
current: "Current address",
|
|
69
|
+
newEmail: "New email address",
|
|
70
|
+
password: "Current password",
|
|
71
|
+
passwordHint: "Your address is how you sign in, so changing it takes your password.",
|
|
72
|
+
emailTagUse: (address) => `Use ${address}`,
|
|
73
|
+
emailTagHint:
|
|
74
|
+
"Many providers deliver name+tag@… to the same inbox, so mail from this app is easy to filter and trace. Check yours does before you rely on it: you would sign in with the tagged address.",
|
|
75
|
+
submit: "Change email address",
|
|
76
|
+
sameAsCurrent: "This is already your address.",
|
|
77
|
+
emailTaken: "An account with this email address already exists.",
|
|
78
|
+
wrongPassword: "The password is incorrect.",
|
|
79
|
+
pending: (newEmail) => `Confirm the link we sent to ${newEmail}.`,
|
|
80
|
+
pendingHint: (currentEmail) =>
|
|
81
|
+
`Until you do, you keep signing in with ${currentEmail}. Check your spam folder too.`,
|
|
82
|
+
resend: "Send the link again",
|
|
83
|
+
resent: "We sent the link again.",
|
|
84
|
+
cancel: "Cancel the change",
|
|
85
|
+
confirmed: (email) => `Your email address is now ${email}.`,
|
|
86
|
+
passkeyNote: "Your passkeys keep working. Your device may still list them under your old address.",
|
|
87
|
+
rateLimited: englishRateLimited,
|
|
88
|
+
failed: "That didn’t work. Please try again.",
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/* ── Props ───────────────────────────────────────────────────────────────── */
|
|
92
|
+
|
|
93
|
+
/** What {@link EmailChangeSettingProps.onRequest} gets: the `POST /auth/me/email` body. */
|
|
94
|
+
export interface EmailChangeValues {
|
|
95
|
+
/** Trimmed. A `+tag` stays (auth §4.5); lower-casing is the server's. */
|
|
96
|
+
newEmail: string;
|
|
97
|
+
/** As typed. */
|
|
98
|
+
password: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Which request failed — {@link EmailChangeSettingProps.describeError}'s second
|
|
102
|
+
* argument. */
|
|
103
|
+
export type EmailChangeAction = "request" | "resend" | "cancel";
|
|
104
|
+
|
|
105
|
+
export interface EmailChangeSettingProps extends Omit<ComponentPropsWithoutRef<"div">, "children" | "onSubmit"> {
|
|
106
|
+
/** The account's address now. */
|
|
107
|
+
currentEmail: string;
|
|
108
|
+
/**
|
|
109
|
+
* The address a change waits on, from the app's server state — so a reload, or
|
|
110
|
+
* another tab, shows the pending state. `null`: none, whatever the card did. Left out
|
|
111
|
+
* (`undefined`), the card keeps its own: pending from a resolved `onRequest` until a
|
|
112
|
+
* resolved `onCancel`.
|
|
113
|
+
*/
|
|
114
|
+
pendingEmail?: string | null;
|
|
115
|
+
/**
|
|
116
|
+
* The form was submitted: send `POST /auth/me/email {new_email, password}` (§6.2).
|
|
117
|
+
* Resolve once the link is mailed — refresh `pendingEmail` first if the app passes
|
|
118
|
+
* it — and the card shows "Confirm the link we sent to …". Reject with the client's
|
|
119
|
+
* error: `email_taken` shows under the new address, `password_incorrect` (server-kit's
|
|
120
|
+
* `400` for a wrong current password; an older `invalid_credentials` too) under the
|
|
121
|
+
* password, a 429 as `rateLimited`, anything else as `failed` unless `describeError`
|
|
122
|
+
* has the app's words.
|
|
123
|
+
*/
|
|
124
|
+
onRequest: (values: EmailChangeValues) => Promise<unknown> | void;
|
|
125
|
+
/** Mail the link again. Left out, no button. */
|
|
126
|
+
onResend?: () => Promise<unknown> | void;
|
|
127
|
+
/** Drop the pending change. Left out, no button. */
|
|
128
|
+
onCancel?: () => Promise<unknown> | void;
|
|
129
|
+
/**
|
|
130
|
+
* The change was just confirmed — the app's confirm route (`POST /auth/me/email/confirm`)
|
|
131
|
+
* came back here. Says "Your email address is now …" over the form, with
|
|
132
|
+
* `passkeyNote`.
|
|
133
|
+
*/
|
|
134
|
+
confirmed?: boolean;
|
|
135
|
+
/** With `confirmed`: say that a passkey's label keeps the old address (§6.2). Default
|
|
136
|
+
* `true`; `false` for an account without passkeys. */
|
|
137
|
+
passkeyNote?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* The app's address tag (`"kastlan"`, auth §4.5): once the new address is plausible a
|
|
140
|
+
* button under it offers the tagged form — the rule of `RegisterForm`, since this is
|
|
141
|
+
* the person's own address. Never applied on its own. Left out, no offer.
|
|
142
|
+
*/
|
|
143
|
+
emailTag?: string;
|
|
144
|
+
/** The app's own words for a failure, or `undefined` for the kit's. Asked first, for
|
|
145
|
+
* every failure (a demo account's 403, the device offline). */
|
|
146
|
+
describeError?: (error: unknown, action: EmailChangeAction) => ReactNode | undefined;
|
|
147
|
+
labels?: Partial<EmailChangeLabels>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
interface Failure {
|
|
151
|
+
action: EmailChangeAction;
|
|
152
|
+
message: ReactNode;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Changing the account's email address (docs/user-admin-harmonization.md §6.2, §2.5):
|
|
157
|
+
* the current address, the new one, the password — then a pending state until the new
|
|
158
|
+
* address confirms its link.
|
|
159
|
+
*
|
|
160
|
+
* **The new address must confirm before it takes effect.** The server mails a one-time
|
|
161
|
+
* link to the NEW address (and a notice to the old one); until it is opened, the account
|
|
162
|
+
* keeps the old address and signs in with it. So the card's answer to a request is not
|
|
163
|
+
* "changed" but "Confirm the link we sent to …", with "Send the link again" and "Cancel
|
|
164
|
+
* the change". The state is the server's: pass `pendingEmail` and a reload shows it too.
|
|
165
|
+
*
|
|
166
|
+
* **The password is asked again** because the address is the identity: whoever holds the
|
|
167
|
+
* session must not move the account to a mailbox of their own. It is a
|
|
168
|
+
* {@link CurrentPasswordInput}, so a password manager fills it and offers no new one.
|
|
169
|
+
*
|
|
170
|
+
* **The `+tag` offer** (`emailTag`) is RegisterForm's: the address is the person's own,
|
|
171
|
+
* so `you+kastlan@…` is offered under the field, applied only on a click.
|
|
172
|
+
*
|
|
173
|
+
* **It never sends a request** (auth §8): `onRequest`, `onResend` and `onCancel` are the
|
|
174
|
+
* app's, and their refusals are read by code — `email_taken` and `password_incorrect`
|
|
175
|
+
* under their fields, which take the focus; a 429 as "Too many attempts". A wrong
|
|
176
|
+
* password is a `400 password_incorrect`, never a 401: an app's client reads a 401 on a
|
|
177
|
+
* signed-in route as an ended session, and would sign the person out for a typo.
|
|
178
|
+
*
|
|
179
|
+
* **Done** (`confirmed`): "Your email address is now …" and, unless `passkeyNote` is
|
|
180
|
+
* off, that a passkey keeps its old label in the device's list — the authenticator
|
|
181
|
+
* stored the name it was given, and only a new passkey carries the new one.
|
|
182
|
+
*/
|
|
183
|
+
export function EmailChangeSetting({
|
|
184
|
+
currentEmail,
|
|
185
|
+
pendingEmail,
|
|
186
|
+
onRequest,
|
|
187
|
+
onResend,
|
|
188
|
+
onCancel,
|
|
189
|
+
confirmed,
|
|
190
|
+
passkeyNote = true,
|
|
191
|
+
emailTag,
|
|
192
|
+
describeError,
|
|
193
|
+
labels: labelsProp,
|
|
194
|
+
className,
|
|
195
|
+
...rest
|
|
196
|
+
}: EmailChangeSettingProps) {
|
|
197
|
+
const labels = useKitLabels("emailChange", DEFAULT_EMAIL_CHANGE_LABELS, labelsProp);
|
|
198
|
+
const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
|
|
199
|
+
const [newEmail, setNewEmail] = useState("");
|
|
200
|
+
const [password, setPassword] = useState("");
|
|
201
|
+
const [ownPending, setOwnPending] = useState<string | null>(null);
|
|
202
|
+
const [busy, setBusy] = useState<EmailChangeAction | null>(null);
|
|
203
|
+
const [failure, setFailure] = useState<Failure | null>(null);
|
|
204
|
+
// `email_taken` belongs to the address it was answered for; another one clears it.
|
|
205
|
+
const [taken, setTaken] = useState<string | null>(null);
|
|
206
|
+
const [wrongPassword, setWrongPassword] = useState(false);
|
|
207
|
+
const [resent, setResent] = useState(false);
|
|
208
|
+
const mounted = useMounted();
|
|
209
|
+
const titleId = useId();
|
|
210
|
+
const tagHintId = useId();
|
|
211
|
+
const emailRef = useRef<HTMLInputElement>(null);
|
|
212
|
+
const passwordRef = useRef<HTMLInputElement>(null);
|
|
213
|
+
const pendingRef = useRef<HTMLDivElement>(null);
|
|
214
|
+
|
|
215
|
+
const pending = pendingEmail !== undefined ? pendingEmail : ownPending;
|
|
216
|
+
const isPending = pending !== null && pending !== "";
|
|
217
|
+
|
|
218
|
+
// The state swapped under the button that was pressed (the form for the pending
|
|
219
|
+
// message, or back): the focus goes to what came in, never down to <body>. Only after
|
|
220
|
+
// the person's own request — a pending state that arrives with the page takes nothing.
|
|
221
|
+
const focusNext = useRef<"pending" | "form" | null>(null);
|
|
222
|
+
useEffect(() => {
|
|
223
|
+
const target = focusNext.current;
|
|
224
|
+
if (target === "pending" && isPending) {
|
|
225
|
+
focusNext.current = null;
|
|
226
|
+
pendingRef.current?.focus();
|
|
227
|
+
} else if (target === "form" && !isPending) {
|
|
228
|
+
focusNext.current = null;
|
|
229
|
+
emailRef.current?.focus();
|
|
230
|
+
}
|
|
231
|
+
}, [isPending]);
|
|
232
|
+
|
|
233
|
+
const messageFor = (error: unknown, action: EmailChangeAction): ReactNode => {
|
|
234
|
+
const own = describeError?.(error, action);
|
|
235
|
+
if (hasMessage(own)) return own;
|
|
236
|
+
return isRateLimited(error) ? labels.rateLimited(retryAfterSeconds(error)) : labels.failed;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/* ── The pending state ── */
|
|
240
|
+
if (isPending) {
|
|
241
|
+
const run = (action: "resend" | "cancel", call: () => unknown) => {
|
|
242
|
+
if (busy) return;
|
|
243
|
+
setBusy(action);
|
|
244
|
+
setFailure(null);
|
|
245
|
+
setResent(false);
|
|
246
|
+
settle(call).then(
|
|
247
|
+
() => {
|
|
248
|
+
if (!mounted.current) return;
|
|
249
|
+
setBusy(null);
|
|
250
|
+
if (action === "resend") {
|
|
251
|
+
setResent(true);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
focusNext.current = "form";
|
|
255
|
+
setOwnPending(null);
|
|
256
|
+
},
|
|
257
|
+
(error: unknown) => {
|
|
258
|
+
if (!mounted.current) return;
|
|
259
|
+
setBusy(null);
|
|
260
|
+
setFailure({ action, message: messageFor(error, action) });
|
|
261
|
+
},
|
|
262
|
+
);
|
|
263
|
+
};
|
|
264
|
+
return (
|
|
265
|
+
<Card {...rest} data-state="pending" className={cn("p-4 space-y-3", className)}>
|
|
266
|
+
<div>
|
|
267
|
+
<SettingsCardTitle id={titleId}>{labels.title}</SettingsCardTitle>
|
|
268
|
+
<div className={cn(CARD_DESCRIPTION_CLASS, "break-all")}>{common.fieldValue(labels.current, currentEmail)}</div>
|
|
269
|
+
</div>
|
|
270
|
+
{/* Focusable, not a control: the request's answer is read out when it takes the
|
|
271
|
+
focus from the submit that went with the form. */}
|
|
272
|
+
<div ref={pendingRef} tabIndex={-1} className="flex gap-2 outline-none">
|
|
273
|
+
<MailCheck aria-hidden className="mt-0.5 size-4 shrink-0 text-[var(--success)]" />
|
|
274
|
+
<div className="min-w-0 space-y-1">
|
|
275
|
+
<p className="break-words text-sm">{labels.pending(pending)}</p>
|
|
276
|
+
<p className={CARD_DESCRIPTION_CLASS}>{labels.pendingHint(currentEmail)}</p>
|
|
277
|
+
</div>
|
|
278
|
+
</div>
|
|
279
|
+
{(onResend || onCancel) && (
|
|
280
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
281
|
+
{onResend && (
|
|
282
|
+
<Button
|
|
283
|
+
type="button"
|
|
284
|
+
variant="secondary"
|
|
285
|
+
size="sm"
|
|
286
|
+
commit
|
|
287
|
+
pending={busy === "resend"}
|
|
288
|
+
disabled={busy === "cancel"}
|
|
289
|
+
onClick={() => run("resend", onResend)}
|
|
290
|
+
>
|
|
291
|
+
{labels.resend}
|
|
292
|
+
</Button>
|
|
293
|
+
)}
|
|
294
|
+
{onCancel && (
|
|
295
|
+
<Button
|
|
296
|
+
type="button"
|
|
297
|
+
variant="ghost"
|
|
298
|
+
size="sm"
|
|
299
|
+
commit
|
|
300
|
+
pending={busy === "cancel"}
|
|
301
|
+
disabled={busy === "resend"}
|
|
302
|
+
onClick={() => run("cancel", onCancel)}
|
|
303
|
+
>
|
|
304
|
+
{labels.cancel}
|
|
305
|
+
</Button>
|
|
306
|
+
)}
|
|
307
|
+
{/* Always in the tree, so the "sent again" that appears in it is announced
|
|
308
|
+
(VerifyEmailStatus's resend line). */}
|
|
309
|
+
<span role="status" className="text-xs text-[var(--success)]">
|
|
310
|
+
{resent ? labels.resent : null}
|
|
311
|
+
</span>
|
|
312
|
+
</div>
|
|
313
|
+
)}
|
|
314
|
+
{failure && (
|
|
315
|
+
<AlertBanner tone="danger" size="sm" role="alert">
|
|
316
|
+
{failure.message}
|
|
317
|
+
</AlertBanner>
|
|
318
|
+
)}
|
|
319
|
+
</Card>
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/* ── The form ── */
|
|
324
|
+
const typed = newEmail.trim();
|
|
325
|
+
const same = typed !== "" && typed.toLowerCase() === currentEmail.trim().toLowerCase();
|
|
326
|
+
const working = busy !== null;
|
|
327
|
+
const canSubmit = emailParts(newEmail) !== null && !same && password !== "";
|
|
328
|
+
const suggestion = emailTag ? taggedEmail(newEmail, emailTag) : null;
|
|
329
|
+
const emailError = same ? labels.sameAsCurrent : taken !== null && taken === typed ? labels.emailTaken : undefined;
|
|
330
|
+
|
|
331
|
+
const submit = (e: FormEvent) => {
|
|
332
|
+
e.preventDefault();
|
|
333
|
+
if (!canSubmit || working) return;
|
|
334
|
+
const values: EmailChangeValues = { newEmail: typed, password };
|
|
335
|
+
setBusy("request");
|
|
336
|
+
setFailure(null);
|
|
337
|
+
setTaken(null);
|
|
338
|
+
setWrongPassword(false);
|
|
339
|
+
settle(() => onRequest(values)).then(
|
|
340
|
+
() => {
|
|
341
|
+
if (!mounted.current) return;
|
|
342
|
+
setBusy(null);
|
|
343
|
+
// The password has done its work; nothing of the form stays in state.
|
|
344
|
+
setNewEmail("");
|
|
345
|
+
setPassword("");
|
|
346
|
+
setResent(false);
|
|
347
|
+
focusNext.current = "pending";
|
|
348
|
+
setOwnPending(values.newEmail);
|
|
349
|
+
},
|
|
350
|
+
(error: unknown) => {
|
|
351
|
+
if (!mounted.current) return;
|
|
352
|
+
setBusy(null);
|
|
353
|
+
const own = describeError?.(error, "request");
|
|
354
|
+
if (hasMessage(own)) {
|
|
355
|
+
setFailure({ action: "request", message: own });
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (isRateLimited(error)) {
|
|
359
|
+
setFailure({ action: "request", message: labels.rateLimited(retryAfterSeconds(error)) });
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const code = authErrorCode(error);
|
|
363
|
+
if (code === "email_taken") {
|
|
364
|
+
setTaken(values.newEmail);
|
|
365
|
+
emailRef.current?.focus();
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
// `invalid_credentials` too, for a server that answered a wrong password so
|
|
369
|
+
// before server-kit 0.4.0 named `password_incorrect`.
|
|
370
|
+
if (code === "password_incorrect" || code === "invalid_credentials") {
|
|
371
|
+
setWrongPassword(true);
|
|
372
|
+
passwordRef.current?.focus();
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
setFailure({ action: "request", message: labels.failed });
|
|
376
|
+
},
|
|
377
|
+
);
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
return (
|
|
381
|
+
<Card {...rest} data-state={confirmed ? "confirmed" : "form"} className={cn("p-4 space-y-3", className)}>
|
|
382
|
+
<div>
|
|
383
|
+
<SettingsCardTitle id={titleId}>{labels.title}</SettingsCardTitle>
|
|
384
|
+
<div className={cn(CARD_DESCRIPTION_CLASS, "break-all")}>{common.fieldValue(labels.current, currentEmail)}</div>
|
|
385
|
+
</div>
|
|
386
|
+
{confirmed && (
|
|
387
|
+
<AlertBanner tone="success" size="sm">
|
|
388
|
+
<span className="block">{labels.confirmed(currentEmail)}</span>
|
|
389
|
+
{passkeyNote && <span className="mt-1 block">{labels.passkeyNote}</span>}
|
|
390
|
+
</AlertBanner>
|
|
391
|
+
)}
|
|
392
|
+
<form className="space-y-3" aria-labelledby={titleId} onSubmit={submit} noValidate>
|
|
393
|
+
<div>
|
|
394
|
+
<Input
|
|
395
|
+
ref={emailRef}
|
|
396
|
+
type="email"
|
|
397
|
+
name="email"
|
|
398
|
+
autoComplete="email"
|
|
399
|
+
label={labels.newEmail}
|
|
400
|
+
value={newEmail}
|
|
401
|
+
onChange={(e) => {
|
|
402
|
+
setNewEmail(e.target.value);
|
|
403
|
+
if (failure) setFailure(null);
|
|
404
|
+
}}
|
|
405
|
+
readOnly={working}
|
|
406
|
+
error={emailError}
|
|
407
|
+
required
|
|
408
|
+
/>
|
|
409
|
+
{/* RegisterForm's offer (auth §4.5): one click, the exact address on the
|
|
410
|
+
button, reversible by typing. */}
|
|
411
|
+
{suggestion && (
|
|
412
|
+
<p className="mt-1 text-xs text-[var(--text-muted)]">
|
|
413
|
+
<Button
|
|
414
|
+
type="button"
|
|
415
|
+
variant="link"
|
|
416
|
+
size="sm"
|
|
417
|
+
className="h-auto p-0 align-baseline"
|
|
418
|
+
disabled={working}
|
|
419
|
+
aria-describedby={tagHintId}
|
|
420
|
+
onClick={() => setNewEmail(suggestion)}
|
|
421
|
+
>
|
|
422
|
+
{labels.emailTagUse(suggestion)}
|
|
423
|
+
</Button>{" "}
|
|
424
|
+
<span id={tagHintId}>{labels.emailTagHint}</span>
|
|
425
|
+
</p>
|
|
426
|
+
)}
|
|
427
|
+
</div>
|
|
428
|
+
<CurrentPasswordInput
|
|
429
|
+
ref={passwordRef}
|
|
430
|
+
name="password"
|
|
431
|
+
label={labels.password}
|
|
432
|
+
value={password}
|
|
433
|
+
onValueChange={(next) => {
|
|
434
|
+
setPassword(next);
|
|
435
|
+
setWrongPassword(false);
|
|
436
|
+
if (failure) setFailure(null);
|
|
437
|
+
}}
|
|
438
|
+
hint={labels.passwordHint}
|
|
439
|
+
error={wrongPassword ? labels.wrongPassword : undefined}
|
|
440
|
+
busy={working}
|
|
441
|
+
required
|
|
442
|
+
/>
|
|
443
|
+
{failure && (
|
|
444
|
+
<AlertBanner tone="danger" size="sm" role="alert">
|
|
445
|
+
{failure.message}
|
|
446
|
+
</AlertBanner>
|
|
447
|
+
)}
|
|
448
|
+
<Button type="submit" commit disabled={!working && !canSubmit} pending={working}>
|
|
449
|
+
{labels.submit}
|
|
450
|
+
</Button>
|
|
451
|
+
</form>
|
|
452
|
+
</Card>
|
|
453
|
+
);
|
|
454
|
+
}
|