@eifi1/ui-kit 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -4
- package/dist/auth/accept-invitation.d.ts +90 -0
- package/dist/auth/accept-invitation.js +117 -0
- package/dist/auth/accept-invitation.js.map +1 -0
- package/dist/auth/auth-errors.d.ts +60 -0
- package/dist/auth/auth-errors.js +32 -0
- package/dist/auth/auth-errors.js.map +1 -0
- package/dist/auth/complete-name-dialog.d.ts +71 -0
- package/dist/auth/complete-name-dialog.js +168 -0
- package/dist/auth/complete-name-dialog.js.map +1 -0
- package/dist/auth/email-tag.d.ts +60 -0
- package/dist/auth/email-tag.js +23 -0
- package/dist/auth/email-tag.js.map +1 -0
- package/dist/auth/forgot-password-form.d.ts +79 -0
- package/dist/auth/forgot-password-form.js +120 -0
- package/dist/auth/forgot-password-form.js.map +1 -0
- package/dist/auth/form-rules.d.ts +27 -0
- package/dist/auth/form-rules.js +23 -0
- package/dist/auth/form-rules.js.map +1 -0
- package/dist/auth/new-password-fields.d.ts +38 -0
- package/dist/auth/new-password-fields.js +54 -0
- package/dist/auth/new-password-fields.js.map +1 -0
- package/dist/auth/not-found-page.d.ts +57 -0
- package/dist/auth/not-found-page.js +40 -0
- package/dist/auth/not-found-page.js.map +1 -0
- package/dist/auth/register-form.d.ts +86 -0
- package/dist/auth/register-form.js +268 -0
- package/dist/auth/register-form.js.map +1 -0
- package/dist/auth/reset-password-form.d.ts +124 -0
- package/dist/auth/reset-password-form.js +164 -0
- package/dist/auth/reset-password-form.js.map +1 -0
- package/dist/auth/sign-in-form.d.ts +243 -0
- package/dist/auth/sign-in-form.js +345 -0
- package/dist/auth/sign-in-form.js.map +1 -0
- package/dist/auth/status-parts.d.ts +78 -0
- package/dist/auth/status-parts.js +83 -0
- package/dist/auth/status-parts.js.map +1 -0
- package/dist/auth/verify-email.d.ts +121 -0
- package/dist/auth/verify-email.js +207 -0
- package/dist/auth/verify-email.js.map +1 -0
- package/dist/chart.d.ts +17 -2
- package/dist/components/amount-input.d.ts +18 -2
- package/dist/components/button-group.d.ts +18 -2
- package/dist/components/calculator.d.ts +18 -2
- package/dist/components/confirm-dialog.d.ts +18 -2
- package/dist/components/copy-button.d.ts +18 -2
- package/dist/components/danger-confirm.d.ts +18 -2
- package/dist/components/facing-pair.d.ts +18 -2
- package/dist/components/file-button.d.ts +18 -2
- package/dist/components/file-dropzone.d.ts +18 -2
- package/dist/components/form-actions.d.ts +18 -2
- package/dist/components/iban-input.d.ts +18 -2
- package/dist/components/language-select.d.ts +18 -9
- package/dist/components/legal-page.d.ts +26 -4
- package/dist/components/legal-page.js +24 -5
- package/dist/components/legal-page.js.map +1 -1
- package/dist/components/legal.d.ts +18 -2
- package/dist/components/legal.js +49 -5
- package/dist/components/legal.js.map +1 -1
- package/dist/components/money-field.d.ts +18 -2
- package/dist/components/number-field.d.ts +18 -2
- package/dist/components/number-input.d.ts +18 -2
- package/dist/components/numpad-sheet.d.ts +18 -2
- package/dist/components/phone-input.d.ts +18 -2
- package/dist/components/series-chart.d.ts +18 -2
- package/dist/components/settings-fields.d.ts +15 -2
- package/dist/components/share-card.d.ts +18 -2
- package/dist/components/text-link.d.ts +18 -2
- package/dist/components/time-input.d.ts +18 -2
- package/dist/components/ui.d.ts +17 -1
- package/dist/components/user-avatar.d.ts +16 -2
- package/dist/components/user-avatar.js +7 -3
- package/dist/components/user-avatar.js.map +1 -1
- package/dist/feedback/feedback-attachment.d.ts +18 -2
- package/dist/feedback/feedback-context.d.ts +18 -2
- package/dist/feedback/feedback-crash.d.ts +18 -2
- package/dist/feedback/feedback-dialog.d.ts +18 -2
- package/dist/feedback/feedback-inbox.d.ts +18 -2
- package/dist/feedback/feedback-labels.d.ts +18 -2
- package/dist/feedback/feedback-menu.d.ts +18 -2
- package/dist/feedback/feedback-record.d.ts +18 -2
- package/dist/feedback/feedback-row-detail.d.ts +18 -2
- package/dist/feedback/feedback-status-undo.d.ts +18 -2
- package/dist/feedback/feedback-submit.d.ts +18 -2
- package/dist/feedback/feedback-swipe.d.ts +18 -2
- package/dist/feedback/feedback-table.d.ts +18 -2
- package/dist/feedback/feedback-thread.d.ts +18 -2
- package/dist/feedback.d.ts +18 -2
- package/dist/hooks/use-file-drop.d.ts +18 -2
- package/dist/i18n/defaults.d.ts +18 -2
- package/dist/i18n/defaults.js +18 -0
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +18 -2
- package/dist/i18n/german.js +145 -0
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +18 -2
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +13 -201
- package/dist/i18n/locales/de-CH.d.ts +18 -2
- package/dist/i18n/locales/en.d.ts +18 -2
- package/dist/i18n/locales/es.d.ts +18 -2
- package/dist/i18n/locales/es.js +147 -3
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +18 -2
- package/dist/i18n/locales/fr.js +147 -0
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +18 -2
- package/dist/i18n/locales/hu.js +149 -3
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +18 -2
- package/dist/i18n/locales/it.js +146 -1
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +18 -2
- package/dist/i18n/locales/zh.js +146 -1
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +18 -2
- package/dist/i18n/review.js +17 -7
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.js +49 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/person-name.d.ts +69 -0
- package/dist/lib/person-name.js +65 -0
- package/dist/lib/person-name.js.map +1 -0
- package/dist/{kit-labels-SBN0biPl.d.ts → register-form-V1OeNlMr.d.ts} +423 -6
- package/dist/rhf/fields.d.ts +18 -2
- package/dist/rhf/form.d.ts +18 -2
- package/dist/rhf.d.ts +18 -2
- package/dist/shell/app-shell.d.ts +18 -2
- package/dist/shell/company-switcher.d.ts +59 -0
- package/dist/shell/company-switcher.js +85 -0
- package/dist/shell/company-switcher.js.map +1 -0
- package/dist/shell/top-bar-brand.d.ts +18 -2
- package/dist/shell/topbar-action-menu.d.ts +1 -0
- package/dist/shell.d.ts +12 -2
- package/dist/wizard/stepper-nav.d.ts +18 -2
- package/dist/wizard.d.ts +18 -2
- package/package.json +1 -1
- package/src/auth/accept-invitation.tsx +227 -0
- package/src/auth/auth-errors.ts +105 -0
- package/src/auth/complete-name-dialog.tsx +253 -0
- package/src/auth/email-tag.ts +75 -0
- package/src/auth/forgot-password-form.tsx +213 -0
- package/src/auth/form-rules.ts +40 -0
- package/src/auth/new-password-fields.tsx +85 -0
- package/src/auth/not-found-page.tsx +98 -0
- package/src/auth/register-form.tsx +459 -0
- package/src/auth/reset-password-form.tsx +337 -0
- package/src/auth/sign-in-form.tsx +687 -0
- package/src/auth/status-parts.tsx +138 -0
- package/src/auth/verify-email.tsx +358 -0
- package/src/components/legal-page.tsx +35 -0
- package/src/components/legal.tsx +93 -7
- package/src/components/user-avatar.tsx +22 -4
- package/src/i18n/defaults.ts +18 -0
- package/src/i18n/german.ts +153 -0
- package/src/i18n/kit-labels.tsx +27 -0
- package/src/i18n/locales/es.ts +156 -3
- package/src/i18n/locales/fr.ts +157 -0
- package/src/i18n/locales/hu.ts +159 -3
- package/src/i18n/locales/it.ts +154 -1
- package/src/i18n/locales/zh.ts +149 -1
- package/src/i18n/review.ts +15 -6
- package/src/index.ts +63 -1
- package/src/lib/person-name.ts +157 -0
- package/src/shell/company-switcher.tsx +140 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { useId, useRef, useState } from "react";
|
|
2
|
+
import type { ComponentPropsWithoutRef, FormEvent, ReactNode } from "react";
|
|
3
|
+
import { MailCheck } from "lucide-react";
|
|
4
|
+
import { cn } from "../lib/cn";
|
|
5
|
+
import { useKitLabels } from "../i18n/kit-labels";
|
|
6
|
+
import { AlertBanner } from "../components/alert-banner";
|
|
7
|
+
import { TextLink } from "../components/text-link";
|
|
8
|
+
import { Button, Input } from "../components/ui";
|
|
9
|
+
import { FORM_HEADING_CLASS, INTRO_CLASS, OutcomeMessage, isThenable, useFocusWhen } from "./status-parts";
|
|
10
|
+
import type { AuthHeadingLevel } from "./status-parts";
|
|
11
|
+
|
|
12
|
+
/* ── Labels ──────────────────────────────────────────────────────────────── */
|
|
13
|
+
|
|
14
|
+
/** Every string the form renders — the `forgotPassword` namespace. keksdose's words
|
|
15
|
+
* (`auth.forgot.*`), which kastlan took over unchanged. */
|
|
16
|
+
export interface ForgotPasswordLabels {
|
|
17
|
+
/** The heading. */
|
|
18
|
+
title: string;
|
|
19
|
+
/** Under the heading, before the field. */
|
|
20
|
+
intro: string;
|
|
21
|
+
/** The email field's label. */
|
|
22
|
+
email: string;
|
|
23
|
+
submit: string;
|
|
24
|
+
/** The one answer, whatever the server knows — given the address as typed. */
|
|
25
|
+
sent: (email: string) => string;
|
|
26
|
+
/** Under it: how long the link lives, and where else to look. */
|
|
27
|
+
sentHint: string;
|
|
28
|
+
/** The link back to the sign-in page, on both states. */
|
|
29
|
+
backToSignIn: string;
|
|
30
|
+
/** A request that did not go through: a throttle, an outage. Never "unknown
|
|
31
|
+
* address" — the endpoint does not say. */
|
|
32
|
+
error: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const DEFAULT_FORGOT_PASSWORD_LABELS: ForgotPasswordLabels = {
|
|
36
|
+
title: "Forgot password",
|
|
37
|
+
intro: "Enter your account’s email address. We’ll send you a link to choose a new password.",
|
|
38
|
+
email: "Email",
|
|
39
|
+
submit: "Send the link",
|
|
40
|
+
sent: (email) => `If an account exists for ${email}, the link is on its way.`,
|
|
41
|
+
sentHint: "The link is valid for one hour and works exactly once. Check your spam folder too.",
|
|
42
|
+
backToSignIn: "Back to sign in",
|
|
43
|
+
error: "The request failed. Please try again later.",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/* ── The form ────────────────────────────────────────────────────────────── */
|
|
47
|
+
|
|
48
|
+
export interface ForgotPasswordFormProps
|
|
49
|
+
extends Omit<ComponentPropsWithoutRef<"div">, "onSubmit" | "children" | "title"> {
|
|
50
|
+
/**
|
|
51
|
+
* The address was submitted, trimmed: send `POST /auth/password-reset/request`.
|
|
52
|
+
* Resolve when the server answered — whatever it answered: it is `204` whether or not
|
|
53
|
+
* an account exists. Reject only when the request did not go through (a throttle, an
|
|
54
|
+
* outage); the form then stays, with the address, and says so. The form never sends a
|
|
55
|
+
* request itself (§8).
|
|
56
|
+
*/
|
|
57
|
+
onSubmit: (email: string) => Promise<unknown> | void;
|
|
58
|
+
/** "Back to sign in" — the app's `/login`. Default `/login`. */
|
|
59
|
+
signInHref?: string;
|
|
60
|
+
/** The field's start value — the address the sign-in form already had, so someone
|
|
61
|
+
* whose password just failed need not type it twice. */
|
|
62
|
+
defaultEmail?: string;
|
|
63
|
+
/**
|
|
64
|
+
* The app's words for a failed request (a `429`: "Too many requests — try again in
|
|
65
|
+
* an hour"), or `undefined` for the kit's `error`. The same hook as `SignInForm`'s.
|
|
66
|
+
*/
|
|
67
|
+
describeError?: (error: unknown) => ReactNode | undefined;
|
|
68
|
+
/** App content under the intro — a notice, a support address. */
|
|
69
|
+
formContent?: ReactNode;
|
|
70
|
+
/** The heading. Default `labels.title`; `null` draws none, for a page that puts it
|
|
71
|
+
* in `AuthLayout`'s `title` instead. */
|
|
72
|
+
title?: ReactNode;
|
|
73
|
+
/** The heading's level. Default `h2`, under the page's `h1`. */
|
|
74
|
+
headingAs?: AuthHeadingLevel;
|
|
75
|
+
labels?: Partial<ForgotPasswordLabels>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* "I forgot my password" for every app (docs/auth-harmonization.md §7): one field, then
|
|
80
|
+
* the same sentence whatever the answer — keksdose's `ForgotPasswordPage`
|
|
81
|
+
* (features/auth/forgot-password-page.tsx), kastlan's copy of it, as one component.
|
|
82
|
+
*
|
|
83
|
+
* **It always ends on the same message**: "If an account exists for …, the link is on
|
|
84
|
+
* its way." The server answers `204` whether or not the address has an account — so the
|
|
85
|
+
* page cannot be used to find out who has one — and the page must not undo that by
|
|
86
|
+
* saying more than the server knows. Worded as a promise ("we sent you a link"), a typo
|
|
87
|
+
* would look like a mail-delivery problem and send the person waiting instead of trying
|
|
88
|
+
* their other address (keksdose #198). The address shown is the one they typed, so a
|
|
89
|
+
* typo is visible.
|
|
90
|
+
*
|
|
91
|
+
* The only failure it can show is a request that did not go through (throttled, the
|
|
92
|
+
* server down), never "unknown address". §4.5's fallback to a tagged address
|
|
93
|
+
* (`you+kastlan@…` when `you@…` has no account) is the server's and changes nothing here.
|
|
94
|
+
*
|
|
95
|
+
* The submit is not disabled while the field is empty — a browser that autofills
|
|
96
|
+
* withholds the value until the first interaction, and a disabled button would swallow
|
|
97
|
+
* that first click; the field's own `required` answers an empty submit instead. After a
|
|
98
|
+
* submit the confirmation takes focus, because the button that had it is gone with the
|
|
99
|
+
* form.
|
|
100
|
+
*/
|
|
101
|
+
export function ForgotPasswordForm({
|
|
102
|
+
onSubmit,
|
|
103
|
+
signInHref = "/login",
|
|
104
|
+
defaultEmail = "",
|
|
105
|
+
describeError,
|
|
106
|
+
formContent,
|
|
107
|
+
title,
|
|
108
|
+
headingAs: Heading = "h2",
|
|
109
|
+
labels: labelsProp,
|
|
110
|
+
className,
|
|
111
|
+
...rest
|
|
112
|
+
}: ForgotPasswordFormProps) {
|
|
113
|
+
const labels = useKitLabels("forgotPassword", DEFAULT_FORGOT_PASSWORD_LABELS, labelsProp);
|
|
114
|
+
const [email, setEmail] = useState(defaultEmail);
|
|
115
|
+
const [pending, setPending] = useState(false);
|
|
116
|
+
const [failure, setFailure] = useState<ReactNode>(null);
|
|
117
|
+
const [sentTo, setSentTo] = useState<string | null>(null);
|
|
118
|
+
const headingId = useId();
|
|
119
|
+
const sentRef = useRef<HTMLDivElement>(null);
|
|
120
|
+
useFocusWhen(sentTo !== null, sentRef);
|
|
121
|
+
|
|
122
|
+
const heading =
|
|
123
|
+
title === null ? null : (
|
|
124
|
+
<Heading id={headingId} className={FORM_HEADING_CLASS}>
|
|
125
|
+
{title ?? labels.title}
|
|
126
|
+
</Heading>
|
|
127
|
+
);
|
|
128
|
+
const back = (
|
|
129
|
+
<p className="text-center text-sm">
|
|
130
|
+
<TextLink href={signInHref} tone="primary">
|
|
131
|
+
{labels.backToSignIn}
|
|
132
|
+
</TextLink>
|
|
133
|
+
</p>
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
if (sentTo !== null) {
|
|
137
|
+
return (
|
|
138
|
+
<div {...rest} data-state="sent" className={cn("space-y-3", className)}>
|
|
139
|
+
{heading}
|
|
140
|
+
<OutcomeMessage icon={<MailCheck className="text-[var(--success)]" />} focusRef={sentRef}>
|
|
141
|
+
<p className={INTRO_CLASS}>{labels.sent(sentTo)}</p>
|
|
142
|
+
<p className="text-xs text-[var(--text-muted)]">{labels.sentHint}</p>
|
|
143
|
+
</OutcomeMessage>
|
|
144
|
+
{back}
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const submit = (e: FormEvent) => {
|
|
150
|
+
e.preventDefault();
|
|
151
|
+
const address = email.trim();
|
|
152
|
+
if (pending || address === "") return;
|
|
153
|
+
setFailure(null);
|
|
154
|
+
let result: unknown;
|
|
155
|
+
try {
|
|
156
|
+
result = onSubmit(address);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
setFailure(describeError?.(error) ?? labels.error);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (!isThenable(result)) {
|
|
162
|
+
setSentTo(address);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
setPending(true);
|
|
166
|
+
result.then(
|
|
167
|
+
() => {
|
|
168
|
+
setPending(false);
|
|
169
|
+
setSentTo(address);
|
|
170
|
+
},
|
|
171
|
+
(error: unknown) => {
|
|
172
|
+
setPending(false);
|
|
173
|
+
setFailure(describeError?.(error) ?? labels.error);
|
|
174
|
+
},
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<div {...rest} data-state="form" className={cn("space-y-3", className)}>
|
|
180
|
+
<form
|
|
181
|
+
className="space-y-3"
|
|
182
|
+
aria-labelledby={title === null ? undefined : headingId}
|
|
183
|
+
onSubmit={submit}
|
|
184
|
+
>
|
|
185
|
+
{heading}
|
|
186
|
+
<p className={INTRO_CLASS}>{labels.intro}</p>
|
|
187
|
+
{formContent}
|
|
188
|
+
<Input
|
|
189
|
+
type="email"
|
|
190
|
+
name="email"
|
|
191
|
+
autoComplete="email"
|
|
192
|
+
label={labels.email}
|
|
193
|
+
value={email}
|
|
194
|
+
onChange={(e) => {
|
|
195
|
+
setEmail(e.target.value);
|
|
196
|
+
if (failure) setFailure(null);
|
|
197
|
+
}}
|
|
198
|
+
readOnly={pending}
|
|
199
|
+
required
|
|
200
|
+
/>
|
|
201
|
+
{failure != null && (
|
|
202
|
+
<AlertBanner tone="danger" size="sm" role="alert">
|
|
203
|
+
{failure}
|
|
204
|
+
</AlertBanner>
|
|
205
|
+
)}
|
|
206
|
+
<Button type="submit" className="w-full" pending={pending}>
|
|
207
|
+
{labels.submit}
|
|
208
|
+
</Button>
|
|
209
|
+
</form>
|
|
210
|
+
{back}
|
|
211
|
+
</div>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { passwordByteLength } from "../components/password-strength";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The few hard rules of the sign-up and sign-in forms, in one place — and the only ones
|
|
5
|
+
* (docs/auth-harmonization.md §3.1, §8). The servers check the same; the kit adds no
|
|
6
|
+
* rule of its own, and everything the strength meter shows beyond these is advice.
|
|
7
|
+
*
|
|
8
|
+
* @internal Shared by RegisterForm, SignInForm and CompleteNameDialog; the coordinator
|
|
9
|
+
* decides whether the constants join the barrel.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** At least 8 characters. */
|
|
13
|
+
export const PASSWORD_MIN_LENGTH = 8;
|
|
14
|
+
|
|
15
|
+
/** At most 72 BYTES — bcrypt reads no further, so a longer password would be silently
|
|
16
|
+
* cut. "ü" is two bytes, an emoji four. */
|
|
17
|
+
export const PASSWORD_MAX_BYTES = 72;
|
|
18
|
+
|
|
19
|
+
/** A first or last name: 1–120 characters after trimming — the old `display_name`
|
|
20
|
+
* limit, so a migrated name fits (§3.1). */
|
|
21
|
+
export const PERSON_NAME_MAX_LENGTH = 120;
|
|
22
|
+
|
|
23
|
+
/** 1–120 characters after trimming. */
|
|
24
|
+
export function personNameOk(value: string): boolean {
|
|
25
|
+
const length = value.trim().length;
|
|
26
|
+
return length >= 1 && length <= PERSON_NAME_MAX_LENGTH;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Why a new password and its confirmation may not be submitted yet, or `null` when they
|
|
31
|
+
* may — keksdose's `passwordPairError` (features/auth/password-fields.tsx). Characters
|
|
32
|
+
* are counted as code points, as the strength meter counts them: an emoji is one
|
|
33
|
+
* character to the person typing it.
|
|
34
|
+
*/
|
|
35
|
+
export function newPasswordProblem(password: string, confirm: string): "length" | "bytes" | "mismatch" | null {
|
|
36
|
+
if ([...password].length < PASSWORD_MIN_LENGTH) return "length";
|
|
37
|
+
if (passwordByteLength(password) > PASSWORD_MAX_BYTES) return "bytes";
|
|
38
|
+
if (password !== confirm) return "mismatch";
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ReactNode, Ref } from "react";
|
|
2
|
+
import { PasswordStrengthMeter } from "../components/password-strength";
|
|
3
|
+
import { Input } from "../components/ui";
|
|
4
|
+
import { PASSWORD_MAX_BYTES, PASSWORD_MIN_LENGTH } from "./form-rules";
|
|
5
|
+
|
|
6
|
+
/** @internal The words the fields show — the host form's own labels. */
|
|
7
|
+
export interface NewPasswordFieldsText {
|
|
8
|
+
password: ReactNode;
|
|
9
|
+
confirm: ReactNode;
|
|
10
|
+
mismatch: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** @internal */
|
|
14
|
+
export interface NewPasswordFieldsProps {
|
|
15
|
+
password: string;
|
|
16
|
+
confirm: string;
|
|
17
|
+
onPasswordChange: (value: string) => void;
|
|
18
|
+
onConfirmChange: (value: string) => void;
|
|
19
|
+
text: NewPasswordFieldsText;
|
|
20
|
+
/** A request is running: both fields `readOnly` (not `disabled`, which would drop
|
|
21
|
+
* the focus of the one being typed in). */
|
|
22
|
+
busy?: boolean;
|
|
23
|
+
passwordRef?: Ref<HTMLInputElement>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* "Choose a password": the field, the strength meter with its advisory checklist, and
|
|
28
|
+
* the confirmation — keksdose's `PasswordFields`, which its register form, its reset
|
|
29
|
+
* page and its forced-change step share so that every screen choosing a password does
|
|
30
|
+
* it under the same rules and the same feedback. Here `RegisterForm` and
|
|
31
|
+
* `SignInForm`'s set-a-new-password step share it.
|
|
32
|
+
*
|
|
33
|
+
* Both fields are `new-password`: a password manager offers to generate one and never
|
|
34
|
+
* fills in the current one. The confirmation carries the mismatch as its own `error`,
|
|
35
|
+
* attached with `aria-describedby`; the key is always passed, so the message coming and
|
|
36
|
+
* going never remounts the field under the typist.
|
|
37
|
+
*
|
|
38
|
+
* @internal Not part of the barrel; the forms are.
|
|
39
|
+
*/
|
|
40
|
+
export function NewPasswordFields({
|
|
41
|
+
password,
|
|
42
|
+
confirm,
|
|
43
|
+
onPasswordChange,
|
|
44
|
+
onConfirmChange,
|
|
45
|
+
text,
|
|
46
|
+
busy = false,
|
|
47
|
+
passwordRef,
|
|
48
|
+
}: NewPasswordFieldsProps) {
|
|
49
|
+
const mismatch = confirm !== "" && confirm !== password;
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
<div>
|
|
53
|
+
<Input
|
|
54
|
+
ref={passwordRef}
|
|
55
|
+
type="password"
|
|
56
|
+
name="new-password"
|
|
57
|
+
autoComplete="new-password"
|
|
58
|
+
label={text.password}
|
|
59
|
+
value={password}
|
|
60
|
+
onChange={(e) => onPasswordChange(e.target.value)}
|
|
61
|
+
minLength={PASSWORD_MIN_LENGTH}
|
|
62
|
+
readOnly={busy}
|
|
63
|
+
required
|
|
64
|
+
/>
|
|
65
|
+
{/* The 72-byte cap is passed because a SIGN-IN password has one (bcrypt); the
|
|
66
|
+
minimum is passed rather than left to the meter's own default 8, so the two
|
|
67
|
+
cannot drift apart. */}
|
|
68
|
+
<PasswordStrengthMeter value={password} minLength={PASSWORD_MIN_LENGTH} maxBytes={PASSWORD_MAX_BYTES} />
|
|
69
|
+
</div>
|
|
70
|
+
{/* A typo'd password costs a reset mail — and under keksdose's end-to-end
|
|
71
|
+
encryption, data (feedback #124) — so it is typed twice. */}
|
|
72
|
+
<Input
|
|
73
|
+
type="password"
|
|
74
|
+
name="confirm-password"
|
|
75
|
+
autoComplete="new-password"
|
|
76
|
+
label={text.confirm}
|
|
77
|
+
value={confirm}
|
|
78
|
+
onChange={(e) => onConfirmChange(e.target.value)}
|
|
79
|
+
readOnly={busy}
|
|
80
|
+
error={mismatch ? text.mismatch : undefined}
|
|
81
|
+
required
|
|
82
|
+
/>
|
|
83
|
+
</>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
+
import { cn } from "../lib/cn";
|
|
3
|
+
import { useKitLabels } from "../i18n/kit-labels";
|
|
4
|
+
import { useNoIndex } from "../hooks/use-noindex";
|
|
5
|
+
import { Button } from "../components/ui";
|
|
6
|
+
import type { AuthHeadingLevel } from "./status-parts";
|
|
7
|
+
|
|
8
|
+
/** Every string the page renders — the `notFound` namespace. keksdose's words
|
|
9
|
+
* (`error.not_found_*`), which kastlan took over. */
|
|
10
|
+
export interface NotFoundLabels {
|
|
11
|
+
/** The heading. */
|
|
12
|
+
title: string;
|
|
13
|
+
/** Under it. */
|
|
14
|
+
body: string;
|
|
15
|
+
/** The way out for everyone — to `homeHref`. */
|
|
16
|
+
home: string;
|
|
17
|
+
/** The second way out for someone signed in — to `appHref`. */
|
|
18
|
+
app: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const DEFAULT_NOT_FOUND_LABELS: NotFoundLabels = {
|
|
22
|
+
title: "Page not found",
|
|
23
|
+
body: "This address doesn’t exist (any more). It may be a typo, or the page has moved.",
|
|
24
|
+
home: "Go to the start page",
|
|
25
|
+
app: "Back to the app",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export interface NotFoundPageProps extends Omit<ComponentPropsWithoutRef<"div">, "children" | "title"> {
|
|
29
|
+
/** "Go to the start page". Default `/`, which takes a signed-in user into the app and
|
|
30
|
+
* anyone else to sign-in in all three apps. */
|
|
31
|
+
homeHref?: string;
|
|
32
|
+
/**
|
|
33
|
+
* "Back to the app", beside it — pass it while someone is signed in. A LITERAL page
|
|
34
|
+
* (keksdose's `/budget`), never the "last visited page" an app restores on start: a
|
|
35
|
+
* stale one of those pointing at a route that is gone is the likeliest way a
|
|
36
|
+
* signed-in user lands here (keksdose's not-found-page.tsx).
|
|
37
|
+
*/
|
|
38
|
+
appHref?: string;
|
|
39
|
+
/** App content under the text — a search field, a support address. */
|
|
40
|
+
children?: ReactNode;
|
|
41
|
+
/** `false` adds no `noindex` — for a preview inside another page. Default `true`. */
|
|
42
|
+
noIndex?: boolean;
|
|
43
|
+
/** The heading's level. Default `h2`, under `AuthLayout`'s `h1`; `h1` where the page
|
|
44
|
+
* stands alone (inside the app shell). */
|
|
45
|
+
headingAs?: AuthHeadingLevel;
|
|
46
|
+
labels?: Partial<NotFoundLabels>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* What an unknown address renders (the router's catch-all), signed out and signed in —
|
|
51
|
+
* keksdose's `NotFoundPage` (app/not-found-page.tsx, feedback #129), which kastlan took
|
|
52
|
+
* over on `AuthLayout` (docs/auth-harmonization.md §7).
|
|
53
|
+
*
|
|
54
|
+
* In place of the silent `<Navigate to="/">` keksdose had: bouncing every typo, dead link
|
|
55
|
+
* and fabricated URL to the start page is what Search Console reports as a soft 404, and
|
|
56
|
+
* it hid broken links. An SPA cannot send a real 404 status — the web server answers
|
|
57
|
+
* every path with index.html — so the page says it in words and calls
|
|
58
|
+
* {@link useNoIndex}, which makes a crawler drop it (the server's `X-Robots-Tag` is the
|
|
59
|
+
* authoritative half).
|
|
60
|
+
*
|
|
61
|
+
* It is the page's CONTENT, not a frame, so it sits in either: as `AuthLayout`'s child
|
|
62
|
+
* for a visitor (`headingAs` default `h2`, under the layout's title), or bare inside the
|
|
63
|
+
* app shell for someone signed in (`headingAs="h1"`, and `appHref`). The large "404" is
|
|
64
|
+
* decoration — the heading says it in words — and hidden from a screen reader.
|
|
65
|
+
*/
|
|
66
|
+
export function NotFoundPage({
|
|
67
|
+
homeHref = "/",
|
|
68
|
+
appHref,
|
|
69
|
+
children,
|
|
70
|
+
noIndex = true,
|
|
71
|
+
headingAs: Heading = "h2",
|
|
72
|
+
labels: labelsProp,
|
|
73
|
+
className,
|
|
74
|
+
...rest
|
|
75
|
+
}: NotFoundPageProps) {
|
|
76
|
+
const labels = useKitLabels("notFound", DEFAULT_NOT_FOUND_LABELS, labelsProp);
|
|
77
|
+
useNoIndex(noIndex);
|
|
78
|
+
return (
|
|
79
|
+
<div {...rest} className={cn("flex flex-col items-center gap-2 py-4 text-center", className)}>
|
|
80
|
+
<p aria-hidden className="text-6xl font-bold leading-none tracking-tight text-[var(--text-placeholder)]">
|
|
81
|
+
404
|
|
82
|
+
</p>
|
|
83
|
+
<Heading className="mt-2 text-xl font-semibold text-[var(--text-primary)]">{labels.title}</Heading>
|
|
84
|
+
<p className="max-w-prose text-sm text-[var(--text-secondary)]">{labels.body}</p>
|
|
85
|
+
{children}
|
|
86
|
+
<div className="mt-4 flex flex-wrap justify-center gap-3">
|
|
87
|
+
<Button href={homeHref} variant="brand">
|
|
88
|
+
{labels.home}
|
|
89
|
+
</Button>
|
|
90
|
+
{appHref !== undefined && (
|
|
91
|
+
<Button href={appHref} variant="secondary">
|
|
92
|
+
{labels.app}
|
|
93
|
+
</Button>
|
|
94
|
+
)}
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|