@gntik-ai/blocks 0.9.0 → 0.11.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/dist/index.d.ts +426 -55
- package/dist/index.js +2275 -639
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.labels.test.tsx +179 -0
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.tsx +59 -24
- package/src/auth/ForgotPasswordForm/block.meta.ts +22 -1
- package/src/auth/ForgotPasswordForm/examples/Labels.tsx +29 -0
- package/src/auth/MfaChallenge/MfaChallenge.labels.test.tsx +139 -0
- package/src/auth/MfaChallenge/MfaChallenge.tsx +69 -23
- package/src/auth/MfaChallenge/block.meta.ts +29 -1
- package/src/auth/MfaChallenge/examples/Labels.tsx +28 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.labels.test.tsx +104 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.tsx +42 -15
- package/src/auth/ResetPasswordForm/block.meta.ts +17 -1
- package/src/auth/ResetPasswordForm/examples/Labels.tsx +28 -0
- package/src/auth/SignInForm/SignInForm.labels.test.tsx +137 -0
- package/src/auth/SignInForm/SignInForm.tsx +43 -16
- package/src/auth/SignInForm/block.meta.ts +22 -1
- package/src/auth/SignInForm/examples/Labels.tsx +29 -0
- package/src/auth/SignUpForm/SignUpForm.labels.test.tsx +217 -0
- package/src/auth/SignUpForm/SignUpForm.tsx +65 -26
- package/src/auth/SignUpForm/block.meta.ts +27 -1
- package/src/auth/SignUpForm/examples/Labels.tsx +29 -0
- package/src/auth/SsoButtons/SsoButtons.labels.test.tsx +30 -0
- package/src/auth/SsoButtons/SsoButtons.tsx +10 -2
- package/src/auth/SsoButtons/block.meta.ts +8 -1
- package/src/auth/SsoButtons/examples/Labels.tsx +24 -0
- package/src/auth/shared.i18n.test.tsx +71 -0
- package/src/auth/shared.tsx +48 -11
- package/src/billing/CostBreakdown/CostBreakdown.test.tsx +10 -0
- package/src/billing/CostBreakdown/CostBreakdown.tsx +50 -43
- package/src/billing/SpendVsBudget/SpendVsBudget.test.tsx +10 -0
- package/src/billing/SpendVsBudget/SpendVsBudget.tsx +35 -31
- package/src/builders/FlowBuilder/FlowBuilder.test.tsx +237 -2
- package/src/builders/FlowBuilder/FlowBuilder.tsx +101 -29
- package/src/builders/FlowBuilder/block.meta.ts +1 -1
- package/src/builders/FlowBuilder/connections.ts +30 -12
- package/src/builders/FlowBuilder/examples/ControlledGraph.tsx +8 -0
- package/src/builders/FlowBuilder/graph-state.ts +78 -0
- package/src/builders/LogViewer/LogViewer.labels.test.tsx +90 -0
- package/src/builders/LogViewer/LogViewer.levels.test.tsx +49 -0
- package/src/builders/LogViewer/LogViewer.tsx +72 -18
- package/src/builders/LogViewer/LogViewer.wrap.test.tsx +181 -0
- package/src/builders/LogViewer/block.meta.ts +19 -1
- package/src/builders/LogViewer/examples/Spanish.tsx +30 -0
- package/src/builders/LogViewer/examples/Wrap.tsx +62 -0
- package/src/builders/LogViewer/use-wrapped-log-rows.ts +42 -0
- package/src/data-display/ChartCard/ChartCard.locale.test.tsx +15 -0
- package/src/data-display/ChartCard/ChartCard.test.tsx +9 -0
- package/src/data-display/ChartCard/ChartCard.tsx +81 -67
- package/src/data-display/ChartCard/block.meta.ts +1 -1
- package/src/data-display/DescriptionListCard/DescriptionListCard.labels.test.tsx +73 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.options.test.tsx +64 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.tsx +74 -23
- package/src/data-display/DescriptionListCard/block.meta.ts +11 -1
- package/src/data-display/DescriptionListCard/examples/Spanish.tsx +29 -0
- package/src/feedback/EmptyStates/EmptyStates.labels.test.tsx +185 -0
- package/src/feedback/EmptyStates/EmptyStates.tsx +101 -30
- package/src/feedback/EmptyStates/NoAccessEmpty.options.test.tsx +38 -0
- package/src/feedback/EmptyStates/block.meta.ts +73 -1
- package/src/feedback/EmptyStates/examples/Spanish.tsx +48 -0
- package/src/feedback/ErrorPanel/ErrorPanel.labels.test.tsx +99 -0
- package/src/feedback/ErrorPanel/ErrorPanel.tsx +38 -9
- package/src/feedback/ErrorPanel/block.meta.ts +19 -1
- package/src/feedback/ErrorPanel/examples/Spanish.tsx +30 -0
- package/src/feedback/InlineCallout/InlineCallout.labels.test.tsx +62 -0
- package/src/feedback/InlineCallout/InlineCallout.tsx +22 -9
- package/src/feedback/InlineCallout/block.meta.ts +9 -1
- package/src/feedback/InlineCallout/examples/Spanish.tsx +19 -0
- package/src/feedback/Skeletons/Skeletons.labels.test.tsx +24 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.labels.test.tsx +115 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.tsx +63 -21
- package/src/forms/CreateApiKeyDialog/block.meta.ts +22 -1
- package/src/forms/CreateApiKeyDialog/examples/Labels.tsx +29 -0
- package/src/forms/CredentialDisclosureDialog/CredentialDisclosureDialog.labels.test.tsx +165 -0
- package/src/forms/CredentialDisclosureDialog/CredentialDisclosureDialog.tsx +31 -8
- package/src/forms/CredentialDisclosureDialog/SecretCopy.tsx +16 -8
- package/src/forms/CredentialDisclosureDialog/block.meta.ts +19 -1
- package/src/forms/CredentialDisclosureDialog/examples/Labels.tsx +38 -0
- package/src/forms/DangerZone/ConfirmDestructiveDialog.tsx +17 -3
- package/src/forms/DangerZone/DangerZone.labels.test.tsx +87 -0
- package/src/forms/DangerZone/DangerZone.tsx +20 -5
- package/src/forms/DangerZone/block.meta.ts +10 -1
- package/src/forms/DangerZone/examples/Labels.tsx +29 -0
- package/src/forms/DateRangeFilter/DateRangeFilter.labels.test.tsx +52 -0
- package/src/forms/DateRangeFilter/DateRangeFilter.tsx +11 -3
- package/src/forms/DateRangeFilter/block.meta.ts +8 -1
- package/src/forms/DateRangeFilter/examples/Labels.tsx +28 -0
- package/src/forms/DialogWizard/DialogWizard.labels.test.tsx +37 -0
- package/src/forms/DialogWizard/DialogWizard.tsx +13 -2
- package/src/forms/DialogWizard/block.meta.ts +7 -1
- package/src/forms/DialogWizard/examples/Labels.tsx +39 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.labels.test.tsx +126 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.test.tsx +22 -1
- package/src/forms/FileUploadPanel/FileUploadPanel.tsx +85 -22
- package/src/forms/FileUploadPanel/block.meta.ts +22 -1
- package/src/forms/FileUploadPanel/examples/Labels.tsx +29 -0
- package/src/forms/FileUploadPanel/fixtures.ts +0 -12
- package/src/forms/FileUploadPanel/format-bytes.test.ts +8 -0
- package/src/forms/FormSection/FormSection.labels.test.tsx +37 -0
- package/src/forms/FormSection/FormSection.tsx +14 -3
- package/src/forms/FormSection/block.meta.ts +7 -1
- package/src/forms/FormSection/examples/Labels.tsx +27 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.labels.test.tsx +87 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.tsx +51 -16
- package/src/forms/InviteMembersDialog/block.meta.ts +20 -1
- package/src/forms/InviteMembersDialog/examples/Labels.tsx +28 -0
- package/src/forms/SettingsRow/SettingsRow.labels.test.tsx +33 -0
- package/src/forms/SettingsRow/SettingsRow.tsx +14 -3
- package/src/forms/SettingsRow/block.meta.ts +7 -1
- package/src/forms/SettingsRow/examples/Labels.tsx +27 -0
- package/src/forms/ValidationSummary/ValidationSummary.labels.test.tsx +47 -0
- package/src/forms/ValidationSummary/ValidationSummary.tsx +9 -3
- package/src/forms/ValidationSummary/block.meta.ts +6 -1
- package/src/forms/ValidationSummary/examples/Labels.tsx +24 -0
- package/src/forms/index.ts +5 -1
- package/src/forms/translated-content.tsx +12 -0
- package/src/page-chrome/PageHeader/PageHeader.labels.test.tsx +56 -0
- package/src/page-chrome/PageHeader/PageHeader.options.test.tsx +34 -0
- package/src/page-chrome/PageHeader/PageHeader.tsx +26 -5
- package/src/page-chrome/PageHeader/block.meta.ts +8 -1
- package/src/page-chrome/PageHeader/examples/Labels.tsx +16 -0
- package/src/page-chrome/PageHeader/examples/Spanish.tsx +11 -0
- package/src/scheduling/AgendaList/AgendaList.test.tsx +25 -0
- package/src/scheduling/AgendaList/AgendaList.tsx +7 -2
- package/src/scheduling/AgendaList/AgendaListLocale.test.tsx +11 -0
- package/src/scheduling/AgendaList/block.meta.ts +1 -1
- package/src/scheduling/AgendaList/examples/Locale.tsx +29 -0
- package/src/scheduling/MonthCalendar/MonthCalendar.test.tsx +111 -1
- package/src/scheduling/MonthCalendar/MonthCalendar.tsx +19 -9
- package/src/scheduling/MonthCalendar/block.meta.ts +1 -1
- package/src/scheduling/MonthCalendar/examples/Locale.tsx +19 -0
- package/src/scheduling/WeekCalendar/WeekCalendar.test.tsx +73 -2
- package/src/scheduling/WeekCalendar/WeekCalendar.tsx +26 -12
- package/src/scheduling/WeekCalendar/block.meta.ts +1 -1
- package/src/scheduling/WeekCalendar/examples/Locale.tsx +19 -0
- package/src/scheduling/shared/dates.test.ts +75 -0
- package/src/scheduling/shared/dates.ts +46 -22
- package/src/scheduling/shared/useSchedulingClock.ts +13 -0
- package/src/shell/GlobalSearch/GlobalSearch.test.tsx +12 -0
- package/src/shell/GlobalSearch/fixtures.ts +2 -2
- package/src/tables/DataTable/DataTable.cross-page-selection.test.tsx +322 -0
- package/src/tables/DataTable/DataTable.labels.test.tsx +74 -0
- package/src/tables/DataTable/DataTable.server-pagination.test.tsx +1 -1
- package/src/tables/DataTable/DataTable.single-select.test.tsx +47 -7
- package/src/tables/DataTable/DataTable.test.tsx +55 -0
- package/src/tables/DataTable/DataTable.tsx +134 -67
- package/src/tables/DataTable/block.meta.ts +21 -3
- package/src/tables/DataTable/data-table-props.ts +14 -5
- package/src/tables/DataTable/data-table-row.tsx +7 -3
- package/src/tables/DataTable/data-table-utils.ts +2 -0
- package/src/tables/DataTable/examples/client-selection.tsx +33 -0
- package/src/tables/DataTable/examples/paginated-single-selection.tsx +46 -0
- package/src/tables/DataTable/examples/server-pagination.tsx +55 -15
- package/src/tables/DataTable/labels.ts +4 -0
- package/src/tables/DataTable/selection-strip.tsx +31 -0
- package/src/tables/DataTable/single-selection.tsx +0 -7
- package/src/tables/DataTable/use-multiple-selection.ts +86 -0
- package/src/tables/PaginationFooter/PaginationFooter.i18n.test.tsx +26 -0
- package/src/test/OptInDefaults.test.tsx +27 -0
- package/src/test/fixtures/opt-in-defaults.json +10 -0
|
@@ -1,10 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useI18n,
|
|
3
|
+
Alert,
|
|
4
|
+
Button,
|
|
5
|
+
Field,
|
|
6
|
+
FieldDescription,
|
|
7
|
+
FieldError,
|
|
8
|
+
FieldLabel,
|
|
9
|
+
Input,
|
|
10
|
+
OtpInput,
|
|
11
|
+
cn,
|
|
12
|
+
} from '@gntik-ai/ui';
|
|
2
13
|
import { useEffect, useState, type ReactNode } from 'react';
|
|
3
14
|
import { AuthHeader, authFormClass, useAsyncSubmit } from '../shared';
|
|
4
15
|
|
|
5
16
|
export type MfaMethod = 'code' | 'backup';
|
|
6
17
|
|
|
18
|
+
export interface MfaChallengeLabels {
|
|
19
|
+
eyebrow: string;
|
|
20
|
+
title: string;
|
|
21
|
+
backupTitle: string;
|
|
22
|
+
backupDescription: string;
|
|
23
|
+
destinationDescription: (length: number, destination: string) => string;
|
|
24
|
+
description: (length: number) => string;
|
|
25
|
+
formLabel: string;
|
|
26
|
+
codeLabel: string;
|
|
27
|
+
codeRequired: (length: number) => string;
|
|
28
|
+
backupLabel: string;
|
|
29
|
+
backupPlaceholder: string;
|
|
30
|
+
backupHint: string;
|
|
31
|
+
backupRequired: string;
|
|
32
|
+
submit: string;
|
|
33
|
+
useCode: string;
|
|
34
|
+
resendIn: (remaining: number) => string;
|
|
35
|
+
resend: string;
|
|
36
|
+
resent: string;
|
|
37
|
+
backToSignIn: string;
|
|
38
|
+
fallbackError: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
7
41
|
export interface MfaChallengeProps {
|
|
42
|
+
labels?: Partial<MfaChallengeLabels>;
|
|
8
43
|
/** Verifies the code. A returned promise shows the loading state; a rejection shows in the alert. */
|
|
9
44
|
onVerify?: (code: string, method: MfaMethod) => void | Promise<void>;
|
|
10
45
|
/** Sends a new code; the resend button then waits `resendCooldown` seconds. */
|
|
@@ -31,6 +66,7 @@ export interface MfaChallengeProps {
|
|
|
31
66
|
* and a resend button with a countdown.
|
|
32
67
|
*/
|
|
33
68
|
export function MfaChallenge({
|
|
69
|
+
labels,
|
|
34
70
|
onVerify,
|
|
35
71
|
onResend,
|
|
36
72
|
resendCooldown = 30,
|
|
@@ -40,10 +76,13 @@ export function MfaChallenge({
|
|
|
40
76
|
error: errorProp,
|
|
41
77
|
loading: loadingProp,
|
|
42
78
|
onCancel,
|
|
43
|
-
eyebrow
|
|
44
|
-
title
|
|
79
|
+
eyebrow: eyebrowProp,
|
|
80
|
+
title: titleProp,
|
|
45
81
|
className,
|
|
46
82
|
}: MfaChallengeProps) {
|
|
83
|
+
const { t } = useI18n();
|
|
84
|
+
const eyebrow = eyebrowProp === undefined ? (labels?.eyebrow ?? t('mfaChallenge.eyebrow')) : eyebrowProp;
|
|
85
|
+
const title = titleProp === undefined ? (labels?.title ?? t('mfaChallenge.title')) : titleProp;
|
|
47
86
|
const [method, setMethod] = useState<MfaMethod>('code');
|
|
48
87
|
const [code, setCode] = useState('');
|
|
49
88
|
const [backup, setBackup] = useState('');
|
|
@@ -53,7 +92,7 @@ export function MfaChallenge({
|
|
|
53
92
|
const [now, setNow] = useState(start);
|
|
54
93
|
const [resendAt, setResendAt] = useState(() => start + (initialCooldown ?? resendCooldown) * 1000);
|
|
55
94
|
const [resent, setResent] = useState(false);
|
|
56
|
-
const { loading, error, run } = useAsyncSubmit(
|
|
95
|
+
const { loading, error, run } = useAsyncSubmit(labels?.fallbackError ?? t('mfaChallenge.fallbackError'));
|
|
57
96
|
const busy = loadingProp ?? loading;
|
|
58
97
|
const alert = errorProp ?? error;
|
|
59
98
|
const remaining = Math.max(0, Math.ceil((resendAt - now) / 1000));
|
|
@@ -73,30 +112,31 @@ export function MfaChallenge({
|
|
|
73
112
|
};
|
|
74
113
|
|
|
75
114
|
const resend = async () => {
|
|
76
|
-
const
|
|
77
|
-
setNow(
|
|
78
|
-
setResendAt(
|
|
115
|
+
const time = Date.now();
|
|
116
|
+
setNow(time);
|
|
117
|
+
setResendAt(time + resendCooldown * 1000);
|
|
79
118
|
setResent(true);
|
|
80
119
|
await onResend?.();
|
|
81
120
|
};
|
|
82
121
|
|
|
83
122
|
const description =
|
|
84
123
|
method === 'backup'
|
|
85
|
-
?
|
|
124
|
+
? (labels?.backupDescription ?? t('mfaChallenge.backupDescription'))
|
|
86
125
|
: destination
|
|
87
|
-
?
|
|
88
|
-
|
|
126
|
+
? (labels?.destinationDescription?.(length, destination) ??
|
|
127
|
+
t('mfaChallenge.destinationDescription', { length, destination }))
|
|
128
|
+
: (labels?.description?.(length) ?? t('mfaChallenge.description', { length }));
|
|
89
129
|
|
|
90
130
|
return (
|
|
91
131
|
<div className={cn(authFormClass, className)}>
|
|
92
132
|
<AuthHeader
|
|
93
133
|
eyebrow={eyebrow}
|
|
94
|
-
title={method === 'backup' ?
|
|
134
|
+
title={method === 'backup' ? (labels?.backupTitle ?? t('mfaChallenge.backupTitle')) : title}
|
|
95
135
|
description={description}
|
|
96
136
|
/>
|
|
97
137
|
<form
|
|
98
138
|
noValidate
|
|
99
|
-
aria-label=
|
|
139
|
+
aria-label={labels?.formLabel ?? t('mfaChallenge.formLabel')}
|
|
100
140
|
className="flex flex-col gap-5"
|
|
101
141
|
onSubmit={(e) => {
|
|
102
142
|
e.preventDefault();
|
|
@@ -106,7 +146,7 @@ export function MfaChallenge({
|
|
|
106
146
|
{alert && <Alert tone="destructive" description={alert} />}
|
|
107
147
|
{method === 'code' ? (
|
|
108
148
|
<Field invalid={invalid}>
|
|
109
|
-
<FieldLabel>
|
|
149
|
+
<FieldLabel>{labels?.codeLabel ?? t('mfaChallenge.codeLabel')}</FieldLabel>
|
|
110
150
|
<OtpInput
|
|
111
151
|
length={length}
|
|
112
152
|
value={code}
|
|
@@ -116,25 +156,27 @@ export function MfaChallenge({
|
|
|
116
156
|
groupSize={length / 2}
|
|
117
157
|
disabled={busy}
|
|
118
158
|
/>
|
|
119
|
-
<FieldError match={invalid}>
|
|
159
|
+
<FieldError match={invalid}>
|
|
160
|
+
{labels?.codeRequired?.(length) ?? t('mfaChallenge.codeRequired', { length })}
|
|
161
|
+
</FieldError>
|
|
120
162
|
</Field>
|
|
121
163
|
) : (
|
|
122
164
|
<Field invalid={invalid}>
|
|
123
|
-
<FieldLabel>
|
|
165
|
+
<FieldLabel>{labels?.backupLabel ?? t('mfaChallenge.backupLabel')}</FieldLabel>
|
|
124
166
|
<Input
|
|
125
167
|
value={backup}
|
|
126
168
|
onValueChange={setBackup}
|
|
127
|
-
placeholder=
|
|
169
|
+
placeholder={labels?.backupPlaceholder ?? t('mfaChallenge.backupPlaceholder')}
|
|
128
170
|
autoComplete="one-time-code"
|
|
129
171
|
spellCheck={false}
|
|
130
172
|
inputClassName="font-mono tracking-wider"
|
|
131
173
|
/>
|
|
132
|
-
<FieldDescription>
|
|
133
|
-
<FieldError match={invalid}>
|
|
174
|
+
<FieldDescription>{labels?.backupHint ?? t('mfaChallenge.backupHint')}</FieldDescription>
|
|
175
|
+
<FieldError match={invalid}>{labels?.backupRequired ?? t('mfaChallenge.backupRequired')}</FieldError>
|
|
134
176
|
</Field>
|
|
135
177
|
)}
|
|
136
178
|
<Button type="submit" size="lg" loading={busy} className="w-full">
|
|
137
|
-
|
|
179
|
+
{labels?.submit ?? t('mfaChallenge.submit')}
|
|
138
180
|
</Button>
|
|
139
181
|
</form>
|
|
140
182
|
<div className="mt-6 flex flex-wrap items-center justify-between gap-3 text-[13px]">
|
|
@@ -147,21 +189,25 @@ export function MfaChallenge({
|
|
|
147
189
|
setSubmitted(false);
|
|
148
190
|
}}
|
|
149
191
|
>
|
|
150
|
-
{method === 'code'
|
|
192
|
+
{method === 'code'
|
|
193
|
+
? (labels?.backupTitle ?? t('mfaChallenge.backupTitle'))
|
|
194
|
+
: (labels?.useCode ?? t('mfaChallenge.useCode'))}
|
|
151
195
|
</Button>
|
|
152
196
|
{method === 'code' && onResend !== undefined && (
|
|
153
197
|
<Button variant="ghost" size="sm" disabled={remaining > 0} onClick={() => void resend()}>
|
|
154
|
-
{remaining > 0
|
|
198
|
+
{remaining > 0
|
|
199
|
+
? (labels?.resendIn?.(remaining) ?? t('mfaChallenge.resendIn', { remaining }))
|
|
200
|
+
: (labels?.resend ?? t('mfaChallenge.resend'))}
|
|
155
201
|
</Button>
|
|
156
202
|
)}
|
|
157
203
|
</div>
|
|
158
204
|
<span role="status" className="sr-only">
|
|
159
|
-
{resent ?
|
|
205
|
+
{resent ? (labels?.resent ?? t('mfaChallenge.resent')) : ''}
|
|
160
206
|
</span>
|
|
161
207
|
{onCancel && (
|
|
162
208
|
<p className="mt-6 text-center">
|
|
163
209
|
<Button variant="ghost" size="sm" onClick={onCancel}>
|
|
164
|
-
|
|
210
|
+
{labels?.backToSignIn ?? t('mfaChallenge.backToSignIn')}
|
|
165
211
|
</Button>
|
|
166
212
|
</p>
|
|
167
213
|
)}
|
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
import type { BlockMeta } from '../../meta';
|
|
2
|
+
import type { MfaChallengeLabels } from './MfaChallenge';
|
|
2
3
|
|
|
3
4
|
export const meta: BlockMeta = {
|
|
4
5
|
name: 'MFA challenge',
|
|
5
6
|
family: 'auth',
|
|
6
7
|
status: 'stable',
|
|
7
|
-
description:
|
|
8
|
+
description:
|
|
9
|
+
'Second-factor step with a one-time code (auto-submit), a backup-code mode and resend with a countdown. Optional labels?: Partial<MfaChallengeLabels> overrides built-in copy; explicit props and validation messages win, then labels, then I18nProvider (en/es). No provider preserves English; fixtures and caller content stay unchanged. Interactive preview: /preview.html?kind=block&id=mfa-challenge--labels.',
|
|
10
|
+
labels: [
|
|
11
|
+
{ key: 'eyebrow', type: 'string', state: 'Default content and accessible names' },
|
|
12
|
+
{ key: 'title', type: 'string', state: 'Default content and accessible names' },
|
|
13
|
+
{ key: 'backupTitle', type: 'string', state: 'Default content and accessible names' },
|
|
14
|
+
{ key: 'backupDescription', type: 'string', state: 'Default content and accessible names' },
|
|
15
|
+
{
|
|
16
|
+
key: 'destinationDescription',
|
|
17
|
+
type: '(length: number, destination: string) => string',
|
|
18
|
+
state: 'Default content and accessible names',
|
|
19
|
+
},
|
|
20
|
+
{ key: 'description', type: '(length: number) => string', state: 'Default content and accessible names' },
|
|
21
|
+
{ key: 'formLabel', type: 'string', state: 'Default content and accessible names' },
|
|
22
|
+
{ key: 'codeLabel', type: 'string', state: 'Default content and accessible names' },
|
|
23
|
+
{ key: 'codeRequired', type: '(length: number) => string', state: 'Validation feedback' },
|
|
24
|
+
{ key: 'backupLabel', type: 'string', state: 'Default content and accessible names' },
|
|
25
|
+
{ key: 'backupPlaceholder', type: 'string', state: 'Default content and accessible names' },
|
|
26
|
+
{ key: 'backupHint', type: 'string', state: 'Default content and accessible names' },
|
|
27
|
+
{ key: 'backupRequired', type: 'string', state: 'Validation feedback' },
|
|
28
|
+
{ key: 'submit', type: 'string', state: 'Default content and accessible names' },
|
|
29
|
+
{ key: 'useCode', type: 'string', state: 'Default content and accessible names' },
|
|
30
|
+
{ key: 'resendIn', type: '(remaining: number) => string', state: 'Default content and accessible names' },
|
|
31
|
+
{ key: 'resend', type: 'string', state: 'Default content and accessible names' },
|
|
32
|
+
{ key: 'resent', type: 'string', state: 'Async feedback' },
|
|
33
|
+
{ key: 'backToSignIn', type: 'string', state: 'Default content and accessible names' },
|
|
34
|
+
{ key: 'fallbackError', type: 'string', state: 'Validation feedback' },
|
|
35
|
+
] satisfies Array<{ key: keyof MfaChallengeLabels; type: string; state: string }>,
|
|
8
36
|
uses: ['OtpInput', 'Field', 'Input', 'Button', 'Alert'],
|
|
9
37
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Button, I18nProvider } from '@gntik-ai/ui';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { MfaChallenge, type MfaChallengeLabels } from '../MfaChallenge';
|
|
4
|
+
|
|
5
|
+
export default function Labels() {
|
|
6
|
+
const [spanish, setSpanish] = useState(false);
|
|
7
|
+
const [custom, setCustom] = useState(true);
|
|
8
|
+
const labels: Partial<MfaChallengeLabels> = {
|
|
9
|
+
title: 'Confirm access',
|
|
10
|
+
submit: 'Confirm code',
|
|
11
|
+
codeRequired: (length) => `Provide the ${length} digits.`,
|
|
12
|
+
};
|
|
13
|
+
return (
|
|
14
|
+
<div className="grid gap-4">
|
|
15
|
+
<div className="flex flex-wrap gap-2">
|
|
16
|
+
<Button variant="secondary" aria-pressed={spanish} onClick={() => setSpanish(!spanish)}>
|
|
17
|
+
Spanish catalog
|
|
18
|
+
</Button>
|
|
19
|
+
<Button variant="secondary" aria-pressed={custom} onClick={() => setCustom(!custom)}>
|
|
20
|
+
Custom labels
|
|
21
|
+
</Button>
|
|
22
|
+
</div>
|
|
23
|
+
<I18nProvider locale={spanish ? 'es' : 'en'}>
|
|
24
|
+
<MfaChallenge labels={custom ? labels : undefined} />
|
|
25
|
+
</I18nProvider>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { I18nProvider, en, es } from '@gntik-ai/ui';
|
|
4
|
+
import { ResetPasswordForm, type ResetPasswordFormLabels } from './ResetPasswordForm';
|
|
5
|
+
import { expectNoAxeViolations } from '../../test/a11y';
|
|
6
|
+
it('preserves English defaults without a provider', () => {
|
|
7
|
+
render(<ResetPasswordForm />);
|
|
8
|
+
expect(screen.getByRole('heading', { name: 'Set a new password' })).toBeVisible();
|
|
9
|
+
expect(screen.getByRole('form', { name: 'Set a new password' })).toBeVisible();
|
|
10
|
+
expect(screen.getByText('Account recovery')).toBeVisible();
|
|
11
|
+
expect(screen.getByText('Use at least 8 characters. Avoid passwords you use elsewhere.')).toBeVisible();
|
|
12
|
+
expect(screen.getByLabelText('New password')).toBeVisible();
|
|
13
|
+
expect(screen.getByLabelText('Confirm password')).toBeVisible();
|
|
14
|
+
expect(screen.getByRole('button', { name: 'Update password' })).toBeVisible();
|
|
15
|
+
});
|
|
16
|
+
it('translates every label, parameterised validation and success state', async () => {
|
|
17
|
+
let fails = true;
|
|
18
|
+
render(
|
|
19
|
+
<I18nProvider locale="es">
|
|
20
|
+
<ResetPasswordForm onSubmit={() => (fails ? Promise.reject(null) : undefined)} minPasswordLength={10} />
|
|
21
|
+
</I18nProvider>,
|
|
22
|
+
);
|
|
23
|
+
expect(screen.getByText(es['resetPassword.eyebrow'])).toBeVisible();
|
|
24
|
+
expect(screen.getByRole('heading', { name: es['resetPassword.title'] })).toBeVisible();
|
|
25
|
+
expect(screen.getByText('Usa al menos 10 caracteres. Evita contraseñas que uses en otros sitios.')).toBeVisible();
|
|
26
|
+
fireEvent.submit(screen.getByRole('form', { name: es['resetPassword.title'] }));
|
|
27
|
+
expect(screen.getByText('Usa al menos 10 caracteres.')).toBeVisible();
|
|
28
|
+
fireEvent.change(screen.getByLabelText(es['resetPassword.newPassword']), { target: { value: 'password123' } });
|
|
29
|
+
await userEvent.click(screen.getByRole('button', { name: es['resetPassword.submit'] }));
|
|
30
|
+
expect(screen.getByText(es['resetPassword.passwordMismatch'])).toBeVisible();
|
|
31
|
+
fireEvent.change(screen.getByLabelText(es['resetPassword.confirmPassword']), { target: { value: 'password123' } });
|
|
32
|
+
await userEvent.click(screen.getByRole('button', { name: es['resetPassword.submit'] }));
|
|
33
|
+
expect(await screen.findByText(es['resetPassword.fallbackError'])).toBeVisible();
|
|
34
|
+
await expectNoAxeViolations(screen.getByRole('form'));
|
|
35
|
+
fails = false;
|
|
36
|
+
await userEvent.click(screen.getByRole('button', { name: es['resetPassword.submit'] }));
|
|
37
|
+
expect(await screen.findByRole('heading', { name: es['resetPassword.successTitle'] })).toBeVisible();
|
|
38
|
+
expect(screen.getByText(es['resetPassword.successDescription'])).toBeVisible();
|
|
39
|
+
expect(screen.getByRole('status')).toHaveTextContent(es['resetPassword.successStatus']);
|
|
40
|
+
expect(screen.getByRole('button', { name: es['resetPassword.continue'] })).toBeVisible();
|
|
41
|
+
});
|
|
42
|
+
it.each(['en', 'es'])('honours all label overrides under %s', async (locale) => {
|
|
43
|
+
const labels: ResetPasswordFormLabels = {
|
|
44
|
+
eyebrow: 'Custom eyebrow',
|
|
45
|
+
title: 'Custom title',
|
|
46
|
+
description: (minimum) => `Custom description ${minimum}`,
|
|
47
|
+
newPassword: 'Custom newPassword',
|
|
48
|
+
confirmPassword: 'Custom confirmPassword',
|
|
49
|
+
passwordTooShort: (minimum) => `Custom passwordTooShort ${minimum}`,
|
|
50
|
+
passwordMismatch: 'Custom passwordMismatch',
|
|
51
|
+
submit: 'Custom submit',
|
|
52
|
+
successTitle: 'Custom successTitle',
|
|
53
|
+
successDescription: 'Custom successDescription',
|
|
54
|
+
successStatus: 'Custom successStatus',
|
|
55
|
+
continue: 'Custom continue',
|
|
56
|
+
fallbackError: 'Custom fallbackError',
|
|
57
|
+
};
|
|
58
|
+
let fails = true;
|
|
59
|
+
const { rerender } = render(
|
|
60
|
+
<I18nProvider locale={locale}>
|
|
61
|
+
<ResetPasswordForm labels={labels} onSubmit={() => (fails ? Promise.reject(null) : undefined)} />
|
|
62
|
+
</I18nProvider>,
|
|
63
|
+
);
|
|
64
|
+
expect(screen.getByText(labels.eyebrow)).toBeVisible();
|
|
65
|
+
expect(screen.getByRole('heading', { name: labels.title })).toBeVisible();
|
|
66
|
+
expect(screen.getByText('Custom description 8')).toBeVisible();
|
|
67
|
+
fireEvent.submit(screen.getByRole('form', { name: labels.title }));
|
|
68
|
+
expect(screen.getByText('Custom passwordTooShort 8')).toBeVisible();
|
|
69
|
+
fireEvent.change(screen.getByLabelText(labels.newPassword), { target: { value: 'password123' } });
|
|
70
|
+
await userEvent.click(screen.getByRole('button', { name: labels.submit }));
|
|
71
|
+
expect(screen.getByText(labels.passwordMismatch)).toBeVisible();
|
|
72
|
+
fireEvent.change(screen.getByLabelText(labels.confirmPassword), { target: { value: 'password123' } });
|
|
73
|
+
await userEvent.click(screen.getByRole('button', { name: labels.submit }));
|
|
74
|
+
expect(await screen.findByText(labels.fallbackError)).toBeVisible();
|
|
75
|
+
fails = false;
|
|
76
|
+
await userEvent.click(screen.getByRole('button', { name: labels.submit }));
|
|
77
|
+
expect(await screen.findByRole('heading', { name: labels.successTitle })).toBeVisible();
|
|
78
|
+
expect(screen.getByText(labels.successDescription)).toBeVisible();
|
|
79
|
+
expect(screen.getByRole('status')).toHaveTextContent(labels.successStatus);
|
|
80
|
+
expect(screen.getByRole('button', { name: labels.continue })).toBeVisible();
|
|
81
|
+
rerender(
|
|
82
|
+
<I18nProvider locale={locale}>
|
|
83
|
+
<ResetPasswordForm labels={labels} eyebrow="Explicit eyebrow" />
|
|
84
|
+
</I18nProvider>,
|
|
85
|
+
);
|
|
86
|
+
expect(screen.getByText('Explicit eyebrow')).toBeVisible();
|
|
87
|
+
});
|
|
88
|
+
it('freezes the original English catalog values', () => {
|
|
89
|
+
expect(en['resetPassword.eyebrow']).toBe('Account recovery');
|
|
90
|
+
expect(en['resetPassword.title']).toBe('Set a new password');
|
|
91
|
+
expect(en['resetPassword.description']).toBe('Use at least {minimum} characters. Avoid passwords you use elsewhere.');
|
|
92
|
+
expect(en['resetPassword.newPassword']).toBe('New password');
|
|
93
|
+
expect(en['resetPassword.confirmPassword']).toBe('Confirm password');
|
|
94
|
+
expect(en['resetPassword.passwordTooShort']).toBe('Use at least {minimum} characters.');
|
|
95
|
+
expect(en['resetPassword.passwordMismatch']).toBe("Passwords don't match.");
|
|
96
|
+
expect(en['resetPassword.submit']).toBe('Update password');
|
|
97
|
+
expect(en['resetPassword.successTitle']).toBe('Password updated');
|
|
98
|
+
expect(en['resetPassword.successDescription']).toBe(
|
|
99
|
+
'You can now sign in with your new password. Other sessions were signed out.',
|
|
100
|
+
);
|
|
101
|
+
expect(en['resetPassword.successStatus']).toBe('Password updated.');
|
|
102
|
+
expect(en['resetPassword.continue']).toBe('Continue to sign in');
|
|
103
|
+
expect(en['resetPassword.fallbackError']).toBe('Your password could not be updated.');
|
|
104
|
+
});
|
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import { Alert, Button, Field, FieldError, FieldLabel, PasswordInput, cn } from '@gntik-ai/ui';
|
|
1
|
+
import { useI18n, Alert, Button, Field, FieldError, FieldLabel, PasswordInput, cn } from '@gntik-ai/ui';
|
|
2
2
|
import { CircleCheck } from '@gntik-ai/icons';
|
|
3
3
|
import { useState, type ReactNode } from 'react';
|
|
4
4
|
import { AuthHeader, authFormClass, useAsyncSubmit } from '../shared';
|
|
5
5
|
|
|
6
|
+
export interface ResetPasswordFormLabels {
|
|
7
|
+
eyebrow: string;
|
|
8
|
+
title: string;
|
|
9
|
+
description: (minimum: number) => string;
|
|
10
|
+
newPassword: string;
|
|
11
|
+
confirmPassword: string;
|
|
12
|
+
passwordTooShort: (minimum: number) => string;
|
|
13
|
+
passwordMismatch: string;
|
|
14
|
+
submit: string;
|
|
15
|
+
successTitle: string;
|
|
16
|
+
successDescription: string;
|
|
17
|
+
successStatus: string;
|
|
18
|
+
continue: string;
|
|
19
|
+
fallbackError: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
6
22
|
export interface ResetPasswordFormProps {
|
|
23
|
+
labels?: Partial<ResetPasswordFormLabels>;
|
|
7
24
|
/** Saves the new password. A returned promise shows the loading state; a rejection shows in the alert. */
|
|
8
25
|
onSubmit?: (password: string) => void | Promise<void>;
|
|
9
26
|
error?: string | null;
|
|
@@ -16,19 +33,22 @@ export interface ResetPasswordFormProps {
|
|
|
16
33
|
|
|
17
34
|
/** New password + confirmation with length and mismatch validation, then a success state. */
|
|
18
35
|
export function ResetPasswordForm({
|
|
36
|
+
labels,
|
|
19
37
|
onSubmit,
|
|
20
38
|
error: errorProp,
|
|
21
39
|
minPasswordLength = 8,
|
|
22
40
|
onContinue,
|
|
23
|
-
eyebrow
|
|
41
|
+
eyebrow: eyebrowProp,
|
|
24
42
|
className,
|
|
25
43
|
}: ResetPasswordFormProps) {
|
|
44
|
+
const { t } = useI18n();
|
|
45
|
+
const eyebrow = eyebrowProp === undefined ? (labels?.eyebrow ?? t('resetPassword.eyebrow')) : eyebrowProp;
|
|
26
46
|
const [password, setPassword] = useState('');
|
|
27
47
|
const [confirm, setConfirm] = useState('');
|
|
28
48
|
const [confirmTouched, setConfirmTouched] = useState(false);
|
|
29
49
|
const [submitted, setSubmitted] = useState(false);
|
|
30
50
|
const [done, setDone] = useState(false);
|
|
31
|
-
const { loading, error, run } = useAsyncSubmit(
|
|
51
|
+
const { loading, error, run } = useAsyncSubmit(labels?.fallbackError ?? t('resetPassword.fallbackError'));
|
|
32
52
|
const alert = errorProp ?? error;
|
|
33
53
|
const tooShort = password.length < minPasswordLength;
|
|
34
54
|
const mismatch = confirm !== password;
|
|
@@ -43,14 +63,14 @@ export function ResetPasswordForm({
|
|
|
43
63
|
</span>
|
|
44
64
|
<AuthHeader
|
|
45
65
|
eyebrow={eyebrow}
|
|
46
|
-
title=
|
|
47
|
-
description=
|
|
66
|
+
title={labels?.successTitle ?? t('resetPassword.successTitle')}
|
|
67
|
+
description={labels?.successDescription ?? t('resetPassword.successDescription')}
|
|
48
68
|
/>
|
|
49
69
|
<div role="status" className="sr-only">
|
|
50
|
-
|
|
70
|
+
{labels?.successStatus ?? t('resetPassword.successStatus')}
|
|
51
71
|
</div>
|
|
52
72
|
<Button size="lg" className="w-full" onClick={onContinue}>
|
|
53
|
-
|
|
73
|
+
{labels?.continue ?? t('resetPassword.continue')}
|
|
54
74
|
</Button>
|
|
55
75
|
</div>
|
|
56
76
|
);
|
|
@@ -60,12 +80,14 @@ export function ResetPasswordForm({
|
|
|
60
80
|
<div className={cn(authFormClass, className)}>
|
|
61
81
|
<AuthHeader
|
|
62
82
|
eyebrow={eyebrow}
|
|
63
|
-
title=
|
|
64
|
-
description={
|
|
83
|
+
title={labels?.title ?? t('resetPassword.title')}
|
|
84
|
+
description={
|
|
85
|
+
labels?.description?.(minPasswordLength) ?? t('resetPassword.description', { minimum: minPasswordLength })
|
|
86
|
+
}
|
|
65
87
|
/>
|
|
66
88
|
<form
|
|
67
89
|
noValidate
|
|
68
|
-
aria-label=
|
|
90
|
+
aria-label={labels?.title ?? t('resetPassword.title')}
|
|
69
91
|
className="flex flex-col gap-4"
|
|
70
92
|
onSubmit={(e) => {
|
|
71
93
|
e.preventDefault();
|
|
@@ -76,12 +98,15 @@ export function ResetPasswordForm({
|
|
|
76
98
|
>
|
|
77
99
|
{alert && <Alert tone="destructive" description={alert} />}
|
|
78
100
|
<Field invalid={passwordInvalid}>
|
|
79
|
-
<FieldLabel>
|
|
101
|
+
<FieldLabel>{labels?.newPassword ?? t('resetPassword.newPassword')}</FieldLabel>
|
|
80
102
|
<PasswordInput showStrength value={password} onValueChange={setPassword} required />
|
|
81
|
-
<FieldError match={passwordInvalid}>
|
|
103
|
+
<FieldError match={passwordInvalid}>
|
|
104
|
+
{labels?.passwordTooShort?.(minPasswordLength) ??
|
|
105
|
+
t('resetPassword.passwordTooShort', { minimum: minPasswordLength })}
|
|
106
|
+
</FieldError>
|
|
82
107
|
</Field>
|
|
83
108
|
<Field invalid={confirmInvalid}>
|
|
84
|
-
<FieldLabel>
|
|
109
|
+
<FieldLabel>{labels?.confirmPassword ?? t('resetPassword.confirmPassword')}</FieldLabel>
|
|
85
110
|
<PasswordInput
|
|
86
111
|
autoComplete="new-password"
|
|
87
112
|
value={confirm}
|
|
@@ -89,10 +114,12 @@ export function ResetPasswordForm({
|
|
|
89
114
|
onBlur={() => setConfirmTouched(true)}
|
|
90
115
|
required
|
|
91
116
|
/>
|
|
92
|
-
<FieldError match={confirmInvalid}>
|
|
117
|
+
<FieldError match={confirmInvalid}>
|
|
118
|
+
{labels?.passwordMismatch ?? t('resetPassword.passwordMismatch')}
|
|
119
|
+
</FieldError>
|
|
93
120
|
</Field>
|
|
94
121
|
<Button type="submit" size="lg" loading={loading} className="mt-2 w-full">
|
|
95
|
-
|
|
122
|
+
{labels?.submit ?? t('resetPassword.submit')}
|
|
96
123
|
</Button>
|
|
97
124
|
</form>
|
|
98
125
|
</div>
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import type { BlockMeta } from '../../meta';
|
|
2
|
+
import type { ResetPasswordFormLabels } from './ResetPasswordForm';
|
|
2
3
|
|
|
3
4
|
export const meta: BlockMeta = {
|
|
4
5
|
name: 'Reset password form',
|
|
5
6
|
family: 'auth',
|
|
6
7
|
status: 'stable',
|
|
7
8
|
description:
|
|
8
|
-
'New password with a strength meter and a confirmation field with mismatch validation, then a success state.',
|
|
9
|
+
'New password with a strength meter and a confirmation field with mismatch validation, then a success state. Optional labels?: Partial<ResetPasswordFormLabels> overrides built-in copy; explicit props and validation messages win, then labels, then I18nProvider (en/es). No provider preserves English; fixtures and caller content stay unchanged. Interactive preview: /preview.html?kind=block&id=reset-password-form--labels.',
|
|
10
|
+
labels: [
|
|
11
|
+
{ key: 'eyebrow', type: 'string', state: 'Default content and accessible names' },
|
|
12
|
+
{ key: 'title', type: 'string', state: 'Default content and accessible names' },
|
|
13
|
+
{ key: 'description', type: '(minimum: number) => string', state: 'Default content and accessible names' },
|
|
14
|
+
{ key: 'newPassword', type: 'string', state: 'Default content and accessible names' },
|
|
15
|
+
{ key: 'confirmPassword', type: 'string', state: 'Default content and accessible names' },
|
|
16
|
+
{ key: 'passwordTooShort', type: '(minimum: number) => string', state: 'Validation feedback' },
|
|
17
|
+
{ key: 'passwordMismatch', type: 'string', state: 'Validation feedback' },
|
|
18
|
+
{ key: 'submit', type: 'string', state: 'Default content and accessible names' },
|
|
19
|
+
{ key: 'successTitle', type: 'string', state: 'Async feedback' },
|
|
20
|
+
{ key: 'successDescription', type: 'string', state: 'Async feedback' },
|
|
21
|
+
{ key: 'successStatus', type: 'string', state: 'Async feedback' },
|
|
22
|
+
{ key: 'continue', type: 'string', state: 'Default content and accessible names' },
|
|
23
|
+
{ key: 'fallbackError', type: 'string', state: 'Validation feedback' },
|
|
24
|
+
] satisfies Array<{ key: keyof ResetPasswordFormLabels; type: string; state: string }>,
|
|
9
25
|
uses: ['Field', 'PasswordInput', 'Button', 'Alert'],
|
|
10
26
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Button, I18nProvider } from '@gntik-ai/ui';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { ResetPasswordForm, type ResetPasswordFormLabels } from '../ResetPasswordForm';
|
|
4
|
+
|
|
5
|
+
export default function Labels() {
|
|
6
|
+
const [spanish, setSpanish] = useState(false);
|
|
7
|
+
const [custom, setCustom] = useState(true);
|
|
8
|
+
const labels: Partial<ResetPasswordFormLabels> = {
|
|
9
|
+
title: 'Choose a password',
|
|
10
|
+
submit: 'Save password',
|
|
11
|
+
passwordTooShort: (minimum) => `Choose at least ${minimum} characters.`,
|
|
12
|
+
};
|
|
13
|
+
return (
|
|
14
|
+
<div className="grid gap-4">
|
|
15
|
+
<div className="flex flex-wrap gap-2">
|
|
16
|
+
<Button variant="secondary" aria-pressed={spanish} onClick={() => setSpanish(!spanish)}>
|
|
17
|
+
Spanish catalog
|
|
18
|
+
</Button>
|
|
19
|
+
<Button variant="secondary" aria-pressed={custom} onClick={() => setCustom(!custom)}>
|
|
20
|
+
Custom labels
|
|
21
|
+
</Button>
|
|
22
|
+
</div>
|
|
23
|
+
<I18nProvider locale={spanish ? 'es' : 'en'}>
|
|
24
|
+
<ResetPasswordForm labels={custom ? labels : undefined} />
|
|
25
|
+
</I18nProvider>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|