@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,234 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { useKitLabels } from "../i18n/kit-labels";
|
|
4
|
+
import { KIT_LANGUAGES } from "../i18n/languages";
|
|
5
|
+
import type { KitLanguageCode } from "../i18n/languages";
|
|
6
|
+
import { AlertBanner } from "../components/alert-banner";
|
|
7
|
+
import { CheckboxGroup } from "../components/checkbox-group";
|
|
8
|
+
import type { CheckboxGroupOption } from "../components/checkbox-group";
|
|
9
|
+
import { FormActions } from "../components/form-actions";
|
|
10
|
+
import { Caption } from "../components/text";
|
|
11
|
+
import { hasMessage } from "./admin-parts";
|
|
12
|
+
import type { MaybePromise } from "./admin-parts";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Who may review which translations: the REVIEWER role and its scope, in one editor
|
|
16
|
+
* (docs/user-admin-harmonization.md §4.1 `PUT /admin/users/{id}/reviewer {locales, areas}`,
|
|
17
|
+
* §7). It replaces three: keksdose's `user-reviewer-role.tsx` (a checkbox per language,
|
|
18
|
+
* saved on each click), Kurvenschmiede's `reviewer-dialog.tsx` (a `CheckboxGroup` in a
|
|
19
|
+
* dialog with Save) and kastlan's platform column.
|
|
20
|
+
*
|
|
21
|
+
* - **Languages** are the scope. Ticking none takes the role away — that is how both
|
|
22
|
+
* apps remove a reviewer — and the editor says so under the boxes.
|
|
23
|
+
* - **Areas** narrow it: "Only the legal pages" (Imprint, Privacy Policy, Terms) for a
|
|
24
|
+
* lawyer, who reads law, not French. An area only means something beside at least one
|
|
25
|
+
* language, so the areas wait for one. Saved as `areas: null` when none is ticked —
|
|
26
|
+
* server-kit's "every area" — never `[]`, which would be "no area at all".
|
|
27
|
+
*
|
|
28
|
+
* A draft with Save, not a save per click: keksdose saved every tick, and two quick ticks
|
|
29
|
+
* could land as a set nobody chose; one Save sends the whole scope, in the languages'
|
|
30
|
+
* order (CheckboxGroup's), so the answer equals the request and the row does not
|
|
31
|
+
* reshuffle on refetch. The server keeps its rules (an admin reviews everything already,
|
|
32
|
+
* a customer is not given the role): `disabledReason` says them here.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/** A reviewer's scope — the request body of `PUT …/reviewer`. */
|
|
36
|
+
export interface ReviewerScope {
|
|
37
|
+
/** Language codes, in the editor's order. Empty: not a reviewer. */
|
|
38
|
+
locales: string[];
|
|
39
|
+
/** The areas the scope is narrowed to; `null` = every area (server-kit's rule). */
|
|
40
|
+
areas: string[] | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** One area the scope can be narrowed to. */
|
|
44
|
+
export interface ReviewerScopeArea {
|
|
45
|
+
value: string;
|
|
46
|
+
label: ReactNode;
|
|
47
|
+
hint?: ReactNode;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** One language the editor offers, when the app's list is not the kit's codes. */
|
|
51
|
+
export interface ReviewerScopeLanguage {
|
|
52
|
+
value: string;
|
|
53
|
+
label: ReactNode;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The `reviewerScope` namespace. */
|
|
57
|
+
export interface ReviewerScopeLabels {
|
|
58
|
+
/** The language group's legend. */
|
|
59
|
+
languages: string;
|
|
60
|
+
/** Under the languages. */
|
|
61
|
+
hint: string;
|
|
62
|
+
/** Under the languages while none is ticked. */
|
|
63
|
+
none: string;
|
|
64
|
+
/** The area group's legend. */
|
|
65
|
+
areas: string;
|
|
66
|
+
/** The default area, `legal`. */
|
|
67
|
+
legalOnly: string;
|
|
68
|
+
legalOnlyHint: string;
|
|
69
|
+
/** A rejected save, unless `describeError` says better. */
|
|
70
|
+
failed: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const DEFAULT_REVIEWER_SCOPE_LABELS: ReviewerScopeLabels = {
|
|
74
|
+
languages: "Languages",
|
|
75
|
+
hint: "Tick the languages this person reviews.",
|
|
76
|
+
none: "No language: saving takes the reviewer role away.",
|
|
77
|
+
areas: "Limit to",
|
|
78
|
+
legalOnly: "Only the legal pages",
|
|
79
|
+
legalOnlyHint: "Imprint, Privacy Policy and Terms — for a lawyer rather than a native speaker.",
|
|
80
|
+
failed: "The reviewer scope couldn’t be saved. Please try again.",
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export interface ReviewerScopeEditorProps {
|
|
84
|
+
/** The scope the server has — the draft starts from it. Key the editor by the
|
|
85
|
+
* account (`key={user.id}`) so another account starts a fresh draft. */
|
|
86
|
+
value: { locales?: readonly string[] | null; areas?: readonly string[] | null };
|
|
87
|
+
/** Sends the scope. A promise keeps the editor busy, and a rejection keeps the draft
|
|
88
|
+
* and shows why. */
|
|
89
|
+
onSave: (scope: ReviewerScope) => MaybePromise;
|
|
90
|
+
/** A Cancel beside Save — a dialog's way out. */
|
|
91
|
+
onCancel?: () => void;
|
|
92
|
+
/**
|
|
93
|
+
* The languages offered: kit codes (named by the kit's registry, each in its own
|
|
94
|
+
* language — "Deutsch", "Français") or the app's own `{ value, label }` rows. Default:
|
|
95
|
+
* all seven of the kit's.
|
|
96
|
+
*/
|
|
97
|
+
languages?: readonly KitLanguageCode[] | readonly ReviewerScopeLanguage[];
|
|
98
|
+
/** The areas the scope can be narrowed to. Default: `legal` alone. `[]` for none. */
|
|
99
|
+
areas?: readonly ReviewerScopeArea[];
|
|
100
|
+
/** Why the scope cannot be changed for this account ("Administrators review every
|
|
101
|
+
* language already"). Every box says it; there is no Save. */
|
|
102
|
+
disabledReason?: ReactNode;
|
|
103
|
+
/** The app's words for a failed save. */
|
|
104
|
+
describeError?: (error: unknown) => ReactNode | undefined;
|
|
105
|
+
/** Over the languages: what the role is, in the app's words. */
|
|
106
|
+
intro?: ReactNode;
|
|
107
|
+
/** Columns for the languages from `sm` up. Default 2 (Kurvenschmiede's dialog). */
|
|
108
|
+
columns?: 1 | 2 | 3 | 4;
|
|
109
|
+
/** Save COMMITS: under a locked `WriteLockProvider` it is held with the lock's reason. */
|
|
110
|
+
commit?: boolean;
|
|
111
|
+
labels?: Partial<ReviewerScopeLabels>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function languageOptions(languages: ReviewerScopeEditorProps["languages"]): CheckboxGroupOption[] {
|
|
115
|
+
const rows = languages ?? KIT_LANGUAGES.map((language) => language.code);
|
|
116
|
+
return rows.map((row) => {
|
|
117
|
+
if (typeof row !== "string") return { value: row.value, label: row.label };
|
|
118
|
+
const language = KIT_LANGUAGES.find((entry) => entry.code === row);
|
|
119
|
+
return {
|
|
120
|
+
value: row,
|
|
121
|
+
// Each name in its own language, marked so a screen reader says it so.
|
|
122
|
+
label: language ? <span lang={language.formatLocale}>{language.nativeName}</span> : row,
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The same set, regardless of order. */
|
|
128
|
+
function sameSet(a: readonly string[], b: readonly string[]): boolean {
|
|
129
|
+
if (a.length !== b.length) return false;
|
|
130
|
+
const seen = new Set(a);
|
|
131
|
+
return b.every((x) => seen.has(x));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function ReviewerScopeEditor({
|
|
135
|
+
value,
|
|
136
|
+
onSave,
|
|
137
|
+
onCancel,
|
|
138
|
+
languages,
|
|
139
|
+
areas: areasProp,
|
|
140
|
+
disabledReason,
|
|
141
|
+
describeError,
|
|
142
|
+
intro,
|
|
143
|
+
columns = 2,
|
|
144
|
+
commit,
|
|
145
|
+
labels: labelsProp,
|
|
146
|
+
}: ReviewerScopeEditorProps) {
|
|
147
|
+
const labels = useKitLabels("reviewerScope", DEFAULT_REVIEWER_SCOPE_LABELS, labelsProp);
|
|
148
|
+
const areaOptions: readonly ReviewerScopeArea[] =
|
|
149
|
+
areasProp ?? [{ value: "legal", label: labels.legalOnly, hint: labels.legalOnlyHint }];
|
|
150
|
+
const savedLocales = [...(value.locales ?? [])];
|
|
151
|
+
const savedAreas = [...(value.areas ?? [])];
|
|
152
|
+
const [locales, setLocales] = useState<string[]>(savedLocales);
|
|
153
|
+
const [areas, setAreas] = useState<string[]>(savedAreas);
|
|
154
|
+
const [pending, setPending] = useState(false);
|
|
155
|
+
const [failure, setFailure] = useState<ReactNode>(null);
|
|
156
|
+
const locked = hasMessage(disabledReason);
|
|
157
|
+
|
|
158
|
+
const nextAreas = locales.length === 0 ? [] : areas;
|
|
159
|
+
const dirty = !sameSet(locales, savedLocales) || !sameSet(nextAreas, locales.length === 0 ? [] : savedAreas);
|
|
160
|
+
|
|
161
|
+
const save = () => {
|
|
162
|
+
if (pending || locked || !dirty) return;
|
|
163
|
+
const scope: ReviewerScope = {
|
|
164
|
+
locales,
|
|
165
|
+
areas: locales.length > 0 && areas.length > 0 ? areas : null,
|
|
166
|
+
};
|
|
167
|
+
setFailure(null);
|
|
168
|
+
let result: MaybePromise;
|
|
169
|
+
try {
|
|
170
|
+
result = onSave(scope);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
setFailure(describeError?.(error) ?? labels.failed);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (!result || typeof result.then !== "function") return;
|
|
176
|
+
setPending(true);
|
|
177
|
+
result.then(
|
|
178
|
+
() => setPending(false),
|
|
179
|
+
(error: unknown) => {
|
|
180
|
+
setPending(false);
|
|
181
|
+
const own = describeError?.(error);
|
|
182
|
+
setFailure(hasMessage(own) ? own : labels.failed);
|
|
183
|
+
},
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<div className="space-y-3">
|
|
189
|
+
{intro && <div className="text-sm text-[var(--text-secondary)]">{intro}</div>}
|
|
190
|
+
<CheckboxGroup
|
|
191
|
+
legend={labels.languages}
|
|
192
|
+
options={languageOptions(languages)}
|
|
193
|
+
value={locales}
|
|
194
|
+
onChange={(next) => {
|
|
195
|
+
setFailure(null);
|
|
196
|
+
setLocales(next);
|
|
197
|
+
}}
|
|
198
|
+
columns={columns}
|
|
199
|
+
hint={locked ? undefined : locales.length === 0 ? labels.none : labels.hint}
|
|
200
|
+
disabledReason={disabledReason}
|
|
201
|
+
/>
|
|
202
|
+
{areaOptions.length > 0 && (
|
|
203
|
+
<CheckboxGroup
|
|
204
|
+
legend={labels.areas}
|
|
205
|
+
options={areaOptions.map((area) => ({ value: area.value, label: area.label, hint: area.hint }))}
|
|
206
|
+
value={nextAreas}
|
|
207
|
+
onChange={(next) => {
|
|
208
|
+
setFailure(null);
|
|
209
|
+
setAreas(next);
|
|
210
|
+
}}
|
|
211
|
+
// An area narrows a language scope; with no language there is none to narrow.
|
|
212
|
+
disabled={locales.length === 0}
|
|
213
|
+
disabledReason={disabledReason}
|
|
214
|
+
/>
|
|
215
|
+
)}
|
|
216
|
+
{failure && (
|
|
217
|
+
<AlertBanner tone="danger" size="sm">
|
|
218
|
+
{failure}
|
|
219
|
+
</AlertBanner>
|
|
220
|
+
)}
|
|
221
|
+
{locked ? (
|
|
222
|
+
<Caption>{disabledReason}</Caption>
|
|
223
|
+
) : (
|
|
224
|
+
<FormActions
|
|
225
|
+
onSubmit={save}
|
|
226
|
+
onCancel={onCancel}
|
|
227
|
+
pending={pending}
|
|
228
|
+
submitDisabled={!dirty}
|
|
229
|
+
commit={commit}
|
|
230
|
+
/>
|
|
231
|
+
)}
|
|
232
|
+
</div>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { useKitLabels } from "../i18n/kit-labels";
|
|
3
|
+
import type { RoleVocabulary } from "../components/account-chips";
|
|
4
|
+
import { CheckboxGroup } from "../components/checkbox-group";
|
|
5
|
+
import type { CheckboxGroupOption } from "../components/checkbox-group";
|
|
6
|
+
import { Select } from "../components/ui";
|
|
7
|
+
import type { SelectProps } from "../components/ui";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The role of an account, chosen by an admin (docs/user-admin-harmonization.md §3.3,
|
|
11
|
+
* §4.1, §7): {@link RoleSelect} for the apps where an account has ONE role (keksdose,
|
|
12
|
+
* Kurvenschmiede) and {@link RolesEditor} for kastlan, where an account has several per
|
|
13
|
+
* company.
|
|
14
|
+
*
|
|
15
|
+
* Both take the app's {@link RoleVocabulary} — the one `RoleChip` reads — so a role is
|
|
16
|
+
* called the same in the chip, the select and the editor. Neither sends a request: a role
|
|
17
|
+
* change is an `acknowledge` action (§4.2), so the app opens `AdminActionConfirm` from
|
|
18
|
+
* `onChange` and the value stays where the server has it until the server says otherwise.
|
|
19
|
+
*
|
|
20
|
+
* WHY THE REASONS. The server refuses the last active admin's demotion (`last_admin`),
|
|
21
|
+
* your own admin role (`self`), Kurvenschmiede's CUSTOMER for an account that owns work,
|
|
22
|
+
* kastlan's TENANT until a tenant portal exists (§4.1, §9.6). A choice the server will
|
|
23
|
+
* refuse is shown as unavailable, with why, rather than offered and answered with an
|
|
24
|
+
* error after a confirmation dialog — the 0.18 write-lock rule: a control that cannot
|
|
25
|
+
* act says so where it is. `"last_admin"` and `"self"` are the kit's words in every
|
|
26
|
+
* language; anything else is the app's own sentence.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** A reason the kit words itself. `self_action` is the server's code for `self` (the
|
|
30
|
+
* account error codes), so a refusal's code can be handed on as it came. */
|
|
31
|
+
export type RoleLockCode = "last_admin" | "self" | "self_action";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Why a role (or the whole control) cannot be changed: one of the kit's
|
|
35
|
+
* {@link RoleLockCode}s, or the app's own words.
|
|
36
|
+
*/
|
|
37
|
+
export type RoleLock = RoleLockCode | (string & {}) | ReactNode;
|
|
38
|
+
|
|
39
|
+
/** The `roleSelect` namespace — RoleSelect's and RolesEditor's words. */
|
|
40
|
+
export interface RoleSelectLabels {
|
|
41
|
+
/** The select's name where no `label` is drawn, and RolesEditor's legend. "Role". */
|
|
42
|
+
label: string;
|
|
43
|
+
/** RolesEditor's legend. "Roles". */
|
|
44
|
+
rolesLegend: string;
|
|
45
|
+
/** The select's accessible name in a roster row — "Role of Ada Example". */
|
|
46
|
+
roleOf: (name: string) => string;
|
|
47
|
+
/** The whole control is locked: the account is the last active administrator. */
|
|
48
|
+
lockedLastAdmin: string;
|
|
49
|
+
/** The whole control is locked: it is the admin's own account. */
|
|
50
|
+
lockedSelf: string;
|
|
51
|
+
/** One option is unavailable for the last active administrator — said after the
|
|
52
|
+
* role's name, inside the option. */
|
|
53
|
+
notForLastAdmin: string;
|
|
54
|
+
/** One option is unavailable on the admin's own account. */
|
|
55
|
+
notForSelf: string;
|
|
56
|
+
/** An unavailable option's text: the role's name and why. */
|
|
57
|
+
unavailable: (role: string, reason: string) => string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const DEFAULT_ROLE_SELECT_LABELS: RoleSelectLabels = {
|
|
61
|
+
label: "Role",
|
|
62
|
+
rolesLegend: "Roles",
|
|
63
|
+
roleOf: (name) => `Role of ${name}`,
|
|
64
|
+
lockedLastAdmin: "The last active administrator keeps this role.",
|
|
65
|
+
lockedSelf: "You can’t change your own role.",
|
|
66
|
+
notForLastAdmin: "not for the last administrator",
|
|
67
|
+
notForSelf: "not for your own account",
|
|
68
|
+
unavailable: (role, reason) => `${role} (${reason})`,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** The whole-control reason, the kit's codes in the kit's words. */
|
|
72
|
+
function lockText(reason: RoleLock, labels: RoleSelectLabels): ReactNode {
|
|
73
|
+
if (reason === "last_admin") return labels.lockedLastAdmin;
|
|
74
|
+
if (reason === "self" || reason === "self_action") return labels.lockedSelf;
|
|
75
|
+
return reason;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** An option's reason as the text a native `<option>` can hold. */
|
|
79
|
+
function optionReasonText(reason: string, labels: RoleSelectLabels): string {
|
|
80
|
+
if (reason === "last_admin") return labels.notForLastAdmin;
|
|
81
|
+
if (reason === "self" || reason === "self_action") return labels.notForSelf;
|
|
82
|
+
return reason;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function present(node: ReactNode): boolean {
|
|
86
|
+
return node !== undefined && node !== null && node !== false && node !== "";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The vocabulary's keys, in its own order. */
|
|
90
|
+
function keysOf<R extends string>(roles: RoleVocabulary<R>): R[] {
|
|
91
|
+
return Object.keys(roles) as R[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* ── RoleSelect ─────────────────────────────────────────────────────────────── */
|
|
95
|
+
|
|
96
|
+
export interface RoleSelectProps<R extends string = string>
|
|
97
|
+
extends Omit<SelectProps, "value" | "defaultValue" | "onChange" | "children" | "multiple" | "disabledReason"> {
|
|
98
|
+
/** The role the server has. Controlled: a pick does not move the select until the
|
|
99
|
+
* app's request lands and the row comes back with the new role. */
|
|
100
|
+
value: R | null | undefined;
|
|
101
|
+
/** The app's roles — what `RoleChip` reads. Their order is the list's. */
|
|
102
|
+
roles: RoleVocabulary<R>;
|
|
103
|
+
/** A role other than `value` was picked. The app asks `AdminActionConfirm` (an
|
|
104
|
+
* `acknowledge` action, §4.2) and sends the change. */
|
|
105
|
+
onChange: (role: R) => void;
|
|
106
|
+
/**
|
|
107
|
+
* The roles that may be CHOSEN here, in the vocabulary's order whatever order this is
|
|
108
|
+
* in. Default: all of them. A role the account holds that is not offered (Kurvenschmiede's
|
|
109
|
+
* REVIEWER, given only through the reviewer scope, §9.6) is still shown, unavailable:
|
|
110
|
+
* a select that dropped it would show the account as something it is not.
|
|
111
|
+
*/
|
|
112
|
+
offered?: readonly R[];
|
|
113
|
+
/**
|
|
114
|
+
* Why the whole choice is locked for this account: `"last_admin"`, `"self"`, or the
|
|
115
|
+
* app's own words. The select stays focusable and says so (Select's `disabledReason`).
|
|
116
|
+
*/
|
|
117
|
+
disabledReason?: RoleLock;
|
|
118
|
+
/**
|
|
119
|
+
* Why ONE role cannot be chosen for this account: `"last_admin"`, `"self"`, or the
|
|
120
|
+
* app's own words (Kurvenschmiede: "owns work", for CUSTOMER) — a STRING, because a
|
|
121
|
+
* native option holds text only. The option is disabled and reads "Member (not for the
|
|
122
|
+
* last administrator)". `undefined` for an available role.
|
|
123
|
+
*/
|
|
124
|
+
optionDisabledReason?: (role: R) => string | undefined;
|
|
125
|
+
/** The account's name, for the select's accessible name in a roster row ("Role of
|
|
126
|
+
* Ada Example") where no `label` is drawn. */
|
|
127
|
+
name?: string;
|
|
128
|
+
labels?: Partial<RoleSelectLabels>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* One role, picked from the app's vocabulary — Kurvenschmiede's roster `Select`
|
|
133
|
+
* (users-panel.tsx), with the reasons it left to the server's toast drawn in place.
|
|
134
|
+
*
|
|
135
|
+
* Unlabelled by default, for a table cell: named "Role of Ada Example" (`name`) or
|
|
136
|
+
* "Role". Pass `label` for a form field. Every {@link Select} prop passes through
|
|
137
|
+
* (`size`, `commit`, `hint`, `error`, `data-*`).
|
|
138
|
+
*/
|
|
139
|
+
export function RoleSelect<R extends string = string>({
|
|
140
|
+
value,
|
|
141
|
+
roles,
|
|
142
|
+
onChange,
|
|
143
|
+
offered,
|
|
144
|
+
disabledReason,
|
|
145
|
+
optionDisabledReason,
|
|
146
|
+
name,
|
|
147
|
+
labels: labelsProp,
|
|
148
|
+
label,
|
|
149
|
+
...rest
|
|
150
|
+
}: RoleSelectProps<R>) {
|
|
151
|
+
const labels = useKitLabels("roleSelect", DEFAULT_ROLE_SELECT_LABELS, labelsProp);
|
|
152
|
+
const all = keysOf(roles);
|
|
153
|
+
const choosable = new Set<R>(offered ?? all);
|
|
154
|
+
const held = value ?? null;
|
|
155
|
+
// A cell has no room for a visible label: the select is named for the account it
|
|
156
|
+
// belongs to, so fifty of them in a roster are not fifty "Role"s.
|
|
157
|
+
const ariaLabel =
|
|
158
|
+
label === undefined ? (rest["aria-label"] ?? (name ? labels.roleOf(name) : labels.label)) : rest["aria-label"];
|
|
159
|
+
return (
|
|
160
|
+
<Select
|
|
161
|
+
{...rest}
|
|
162
|
+
label={label}
|
|
163
|
+
aria-label={ariaLabel}
|
|
164
|
+
value={held ?? ""}
|
|
165
|
+
disabledReason={present(disabledReason) ? lockText(disabledReason, labels) : undefined}
|
|
166
|
+
onChange={(event) => {
|
|
167
|
+
const next = event.target.value as R;
|
|
168
|
+
if (next && next !== held) onChange(next);
|
|
169
|
+
}}
|
|
170
|
+
>
|
|
171
|
+
{held === null && <option value="" disabled />}
|
|
172
|
+
{all
|
|
173
|
+
.filter((role) => choosable.has(role) || role === held)
|
|
174
|
+
.map((role) => {
|
|
175
|
+
const word = roles[role].label;
|
|
176
|
+
const reason = role === held ? undefined : optionDisabledReason?.(role);
|
|
177
|
+
const unavailable = !choosable.has(role) || present(reason);
|
|
178
|
+
return (
|
|
179
|
+
<option key={role} value={role} disabled={unavailable && role !== held}>
|
|
180
|
+
{reason ? labels.unavailable(word, optionReasonText(reason, labels)) : word}
|
|
181
|
+
</option>
|
|
182
|
+
);
|
|
183
|
+
})}
|
|
184
|
+
{/* A role the vocabulary does not know (an older client against a newer API) is
|
|
185
|
+
still the account's role: shown as its key, as RoleChip shows it. */}
|
|
186
|
+
{held !== null && !all.includes(held) && (
|
|
187
|
+
<option value={held} disabled>
|
|
188
|
+
{held}
|
|
189
|
+
</option>
|
|
190
|
+
)}
|
|
191
|
+
</Select>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* ── RolesEditor ────────────────────────────────────────────────────────────── */
|
|
196
|
+
|
|
197
|
+
export interface RolesEditorProps<R extends string = string> {
|
|
198
|
+
/** The roles ticked — the draft the app holds while its dialog is open. */
|
|
199
|
+
value: readonly R[];
|
|
200
|
+
roles: RoleVocabulary<R>;
|
|
201
|
+
/** The new set, in the vocabulary's order (a role the editor does not offer, but the
|
|
202
|
+
* account holds, is kept after the rest — CheckboxGroup's rule). */
|
|
203
|
+
onChange: (roles: R[]) => void;
|
|
204
|
+
/** The roles that may be ticked or unticked here. Default: all. kastlan leaves TENANT
|
|
205
|
+
* out until a tenant portal exists (§4.1). */
|
|
206
|
+
offered?: readonly R[];
|
|
207
|
+
/** Why nothing can be changed: `"last_admin"`, `"self"` or the app's words. */
|
|
208
|
+
disabledReason?: RoleLock;
|
|
209
|
+
/** Why one role cannot be changed — shown under it, and the box keeps its state:
|
|
210
|
+
* `"last_admin"` on the last administrator's ADMIN, say. */
|
|
211
|
+
optionDisabledReason?: (role: R) => RoleLock | undefined;
|
|
212
|
+
/** Default `roleSelect.rolesLegend` — "Roles". kastlan names the company: "Roles in
|
|
213
|
+
* Example Ltd". */
|
|
214
|
+
legend?: ReactNode;
|
|
215
|
+
legendVisibility?: "visible" | "sr-only";
|
|
216
|
+
/** At least one role (kastlan's dialog saves none). Draws the required star. */
|
|
217
|
+
required?: boolean;
|
|
218
|
+
hint?: ReactNode;
|
|
219
|
+
error?: ReactNode;
|
|
220
|
+
columns?: 1 | 2 | 3 | 4;
|
|
221
|
+
/** The editor SAVES on change — the write lock's opt-in (CheckboxGroup's `commit`). */
|
|
222
|
+
commit?: boolean;
|
|
223
|
+
className?: string;
|
|
224
|
+
labels?: Partial<RoleSelectLabels>;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Several roles at once — kastlan's manage-roles dialog (`ChoiceCardGroup multiple`),
|
|
229
|
+
* which holds an account's roles in the CURRENT company (§4.1: `PUT /admin/users/{id}/roles`).
|
|
230
|
+
* A kit {@link CheckboxGroup} of the vocabulary, with the reasons of {@link RoleSelect}:
|
|
231
|
+
* a role that cannot change keeps its box as it is and says why under it.
|
|
232
|
+
*
|
|
233
|
+
* A field, not a form: the app's dialog holds the draft, and its Save goes through
|
|
234
|
+
* `AdminActionConfirm` (`acknowledge`, §4.2) — which can draw this editor as its
|
|
235
|
+
* `children`, so the roles and the tick are one dialog.
|
|
236
|
+
*/
|
|
237
|
+
export function RolesEditor<R extends string = string>({
|
|
238
|
+
value,
|
|
239
|
+
roles,
|
|
240
|
+
onChange,
|
|
241
|
+
offered,
|
|
242
|
+
disabledReason,
|
|
243
|
+
optionDisabledReason,
|
|
244
|
+
legend,
|
|
245
|
+
legendVisibility,
|
|
246
|
+
required,
|
|
247
|
+
hint,
|
|
248
|
+
error,
|
|
249
|
+
columns,
|
|
250
|
+
commit,
|
|
251
|
+
className,
|
|
252
|
+
labels: labelsProp,
|
|
253
|
+
}: RolesEditorProps<R>) {
|
|
254
|
+
const labels = useKitLabels("roleSelect", DEFAULT_ROLE_SELECT_LABELS, labelsProp);
|
|
255
|
+
const all = keysOf(roles);
|
|
256
|
+
const choosable = new Set<R>(offered ?? all);
|
|
257
|
+
const held = new Set<R>(value);
|
|
258
|
+
const options: CheckboxGroupOption<R>[] = all
|
|
259
|
+
.filter((role) => choosable.has(role) || held.has(role))
|
|
260
|
+
.map((role) => {
|
|
261
|
+
const reason = optionDisabledReason?.(role);
|
|
262
|
+
const locked = present(reason);
|
|
263
|
+
return {
|
|
264
|
+
value: role,
|
|
265
|
+
label: roles[role].label,
|
|
266
|
+
hint: locked ? lockText(reason, labels) : undefined,
|
|
267
|
+
disabled: locked || !choosable.has(role),
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
return (
|
|
271
|
+
<CheckboxGroup<R>
|
|
272
|
+
legend={legend ?? labels.rolesLegend}
|
|
273
|
+
legendVisibility={legendVisibility}
|
|
274
|
+
options={options}
|
|
275
|
+
value={[...value]}
|
|
276
|
+
onChange={onChange}
|
|
277
|
+
required={required}
|
|
278
|
+
hint={hint}
|
|
279
|
+
error={error}
|
|
280
|
+
columns={columns}
|
|
281
|
+
commit={commit}
|
|
282
|
+
disabledReason={present(disabledReason) ? lockText(disabledReason, labels) : undefined}
|
|
283
|
+
className={className}
|
|
284
|
+
/>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { useKitLabels } from "../i18n/kit-labels";
|
|
4
|
+
import { Select } from "../components/ui";
|
|
5
|
+
import { Caption } from "../components/text";
|
|
6
|
+
import { AdminActionConfirm } from "./admin-action-confirm";
|
|
7
|
+
import type { AdminActionTarget, AdminConfirmLevel } from "./admin-action-confirm";
|
|
8
|
+
import { usePersonLabel } from "./admin-parts";
|
|
9
|
+
import type { AdminPerson, MaybePromise } from "./admin-parts";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Hand an account's owned work to another account — Kurvenschmiede's `TypedConfirm`
|
|
13
|
+
* with its recipient select (features/admin/typed-confirm.tsx, users-panel.tsx;
|
|
14
|
+
* docs/user-admin-harmonization.md §4.1 `POST /admin/users/{id}/transfer {to,
|
|
15
|
+
* confirm_email}`, §4.2: `type_email`).
|
|
16
|
+
*
|
|
17
|
+
* It is {@link AdminActionConfirm} with the recipient as the action's own field: the
|
|
18
|
+
* typed address is the SOURCE account's — the one whose work moves, which is the row the
|
|
19
|
+
* admin must prove they are on — and the confirm waits for a recipient too.
|
|
20
|
+
*
|
|
21
|
+
* WHO MAY RECEIVE IT (§9.6): never a customer, never a deactivated account, never the
|
|
22
|
+
* account itself. The APP decides — it knows its roles and states — and marks each
|
|
23
|
+
* candidate with why it cannot (`unavailable`); the kit shows those accounts, unavailable,
|
|
24
|
+
* with the reason, rather than leaving the admin to wonder where somebody went. The
|
|
25
|
+
* source account is marked `self` here whether or not the app did.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** Why a candidate cannot receive the work: the kit's three, or the app's own words. */
|
|
29
|
+
export type TransferUnavailable = "customer" | "deactivated" | "self";
|
|
30
|
+
|
|
31
|
+
/** An account that might receive the work. */
|
|
32
|
+
export interface TransferCandidate extends AdminPerson {
|
|
33
|
+
id: string | number;
|
|
34
|
+
email: string;
|
|
35
|
+
/** Why it cannot: `"customer"`, `"deactivated"`, `"self"`, or the app's own words. */
|
|
36
|
+
unavailable?: TransferUnavailable | (string & {});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** What {@link TransferOwnershipDialogProps.onTransfer} receives — the request body. */
|
|
40
|
+
export interface TransferValues {
|
|
41
|
+
toUserId: string | number;
|
|
42
|
+
/** The source account's address as typed (at `type_email`). */
|
|
43
|
+
confirmEmail?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The `transferOwnership` namespace. The guard and the refusals are `adminAction`'s
|
|
47
|
+
* and `dangerConfirm`'s. */
|
|
48
|
+
export interface TransferOwnershipLabels {
|
|
49
|
+
/** The heading — "Hand on Ada Example’s work". */
|
|
50
|
+
title: (name: string) => string;
|
|
51
|
+
/** What happens. */
|
|
52
|
+
body: string;
|
|
53
|
+
/** The recipient select's label. */
|
|
54
|
+
recipient: string;
|
|
55
|
+
/** Its empty first option. */
|
|
56
|
+
choose: string;
|
|
57
|
+
/** Why the confirm is held while nobody is chosen. */
|
|
58
|
+
chooseFirst: string;
|
|
59
|
+
/** The confirm button. */
|
|
60
|
+
confirm: string;
|
|
61
|
+
/** Reasons, said after the account's name inside its option. */
|
|
62
|
+
customer: string;
|
|
63
|
+
deactivated: string;
|
|
64
|
+
self: string;
|
|
65
|
+
/** An unavailable option's text: the account and why. */
|
|
66
|
+
unavailable: (account: string, reason: string) => string;
|
|
67
|
+
/** No account can receive it. */
|
|
68
|
+
noCandidates: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const DEFAULT_TRANSFER_OWNERSHIP_LABELS: TransferOwnershipLabels = {
|
|
72
|
+
title: (name) => `Hand on ${name}’s work`,
|
|
73
|
+
body: "Everything this account owns moves to the account you choose, in one step.",
|
|
74
|
+
recipient: "Hand it to",
|
|
75
|
+
choose: "Choose an account…",
|
|
76
|
+
chooseFirst: "Choose who receives the work",
|
|
77
|
+
confirm: "Hand it on",
|
|
78
|
+
customer: "a customer",
|
|
79
|
+
deactivated: "deactivated",
|
|
80
|
+
self: "the same account",
|
|
81
|
+
unavailable: (account, reason) => `${account} (${reason})`,
|
|
82
|
+
noCandidates: "No other account can receive it.",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export interface TransferOwnershipDialogProps {
|
|
86
|
+
/** The account whose work moves — its address is what the admin types. */
|
|
87
|
+
from: AdminActionTarget;
|
|
88
|
+
/** Who might receive it, each marked with why not where it cannot. */
|
|
89
|
+
candidates: readonly TransferCandidate[];
|
|
90
|
+
/** What moves, in the app's words — "3 sessions · 1 gear · 2 projects" (counts, never
|
|
91
|
+
* content). Under the sentence. */
|
|
92
|
+
summary?: ReactNode;
|
|
93
|
+
/** Sends it. Promise handling as {@link AdminActionConfirm}'s `onConfirm`. */
|
|
94
|
+
onTransfer: (values: TransferValues) => MaybePromise;
|
|
95
|
+
onClose: (done: boolean) => void;
|
|
96
|
+
/** The server's level for `transfer` — `type_email` (§4.2), the default. A transfer
|
|
97
|
+
* always has a recipient to choose, so `none` asks as `acknowledge` does. */
|
|
98
|
+
level?: AdminConfirmLevel;
|
|
99
|
+
describeError?: (error: unknown) => ReactNode | undefined;
|
|
100
|
+
/** Kept-mounted mode. */
|
|
101
|
+
open?: boolean;
|
|
102
|
+
labels?: Partial<TransferOwnershipLabels>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function TransferOwnershipDialog({
|
|
106
|
+
from,
|
|
107
|
+
candidates,
|
|
108
|
+
summary,
|
|
109
|
+
onTransfer,
|
|
110
|
+
onClose,
|
|
111
|
+
level = "type_email",
|
|
112
|
+
describeError,
|
|
113
|
+
open,
|
|
114
|
+
labels: labelsProp,
|
|
115
|
+
}: TransferOwnershipDialogProps) {
|
|
116
|
+
const labels = useKitLabels("transferOwnership", DEFAULT_TRANSFER_OWNERSHIP_LABELS, labelsProp);
|
|
117
|
+
const nameOf = usePersonLabel();
|
|
118
|
+
const [chosen, setChosen] = useState("");
|
|
119
|
+
|
|
120
|
+
const reasonOf = (candidate: TransferCandidate): string | undefined => {
|
|
121
|
+
const own = candidate.unavailable;
|
|
122
|
+
const isSource =
|
|
123
|
+
(from.id !== undefined && from.id !== null && candidate.id === from.id) ||
|
|
124
|
+
candidate.email.trim().toLowerCase() === from.email.trim().toLowerCase();
|
|
125
|
+
const code = isSource ? "self" : own;
|
|
126
|
+
if (!code) return undefined;
|
|
127
|
+
if (code === "customer") return labels.customer;
|
|
128
|
+
if (code === "deactivated") return labels.deactivated;
|
|
129
|
+
if (code === "self") return labels.self;
|
|
130
|
+
return code;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const rows = candidates.map((candidate) => {
|
|
134
|
+
const name = nameOf(candidate);
|
|
135
|
+
const shown = name && name !== candidate.email ? `${name} — ${candidate.email}` : candidate.email;
|
|
136
|
+
const reason = reasonOf(candidate);
|
|
137
|
+
return { candidate, value: String(candidate.id), text: reason ? labels.unavailable(shown, reason) : shown, reason };
|
|
138
|
+
});
|
|
139
|
+
const available = rows.filter((row) => !row.reason);
|
|
140
|
+
const recipient = available.find((row) => row.value === chosen)?.candidate;
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<AdminActionConfirm
|
|
144
|
+
open={open}
|
|
145
|
+
level={level === "none" ? "acknowledge" : level}
|
|
146
|
+
target={from}
|
|
147
|
+
title={labels.title(nameOf(from))}
|
|
148
|
+
consequence={labels.body}
|
|
149
|
+
confirmLabel={labels.confirm}
|
|
150
|
+
tone="danger"
|
|
151
|
+
confirmDisabledReason={
|
|
152
|
+
available.length === 0 ? labels.noCandidates : recipient === undefined ? labels.chooseFirst : undefined
|
|
153
|
+
}
|
|
154
|
+
onConfirm={(values) =>
|
|
155
|
+
recipient === undefined ? undefined : onTransfer({ toUserId: recipient.id, confirmEmail: values.confirmEmail })
|
|
156
|
+
}
|
|
157
|
+
onClose={onClose}
|
|
158
|
+
describeError={describeError}
|
|
159
|
+
>
|
|
160
|
+
{summary && <div className="text-sm text-[var(--text-secondary)]">{summary}</div>}
|
|
161
|
+
<Select label={labels.recipient} value={chosen} onChange={(event) => setChosen(event.target.value)}>
|
|
162
|
+
<option value="">{labels.choose}</option>
|
|
163
|
+
{rows.map((row) => (
|
|
164
|
+
<option key={row.value} value={row.value} disabled={Boolean(row.reason)}>
|
|
165
|
+
{row.text}
|
|
166
|
+
</option>
|
|
167
|
+
))}
|
|
168
|
+
</Select>
|
|
169
|
+
{available.length === 0 && <Caption>{labels.noCandidates}</Caption>}
|
|
170
|
+
</AdminActionConfirm>
|
|
171
|
+
);
|
|
172
|
+
}
|