@eifi1/ui-kit 0.41.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/README.md +19 -6
  2. package/dist/admin/admin-area-labels.d.ts +55 -0
  3. package/dist/admin/admin-area-labels.js +33 -0
  4. package/dist/admin/admin-area-labels.js.map +1 -0
  5. package/dist/admin/admin-forbidden.d.ts +35 -0
  6. package/dist/admin/admin-forbidden.js +36 -0
  7. package/dist/admin/admin-forbidden.js.map +1 -0
  8. package/dist/admin/admin-overview.d.ts +93 -0
  9. package/dist/admin/admin-overview.js +69 -0
  10. package/dist/admin/admin-overview.js.map +1 -0
  11. package/dist/admin/admin-sections.d.ts +63 -0
  12. package/dist/admin/admin-sections.js +64 -0
  13. package/dist/admin/admin-sections.js.map +1 -0
  14. package/dist/admin/admin-tool-links.d.ts +48 -0
  15. package/dist/admin/admin-tool-links.js +31 -0
  16. package/dist/admin/admin-tool-links.js.map +1 -0
  17. package/dist/billing/billing-banner.d.ts +25 -2
  18. package/dist/billing/billing-banner.js +5 -2
  19. package/dist/billing/billing-banner.js.map +1 -1
  20. package/dist/billing/billing-labels.d.ts +32 -0
  21. package/dist/billing/billing-labels.js +9 -0
  22. package/dist/billing/billing-labels.js.map +1 -1
  23. package/dist/billing/billing-overview.d.ts +33 -0
  24. package/dist/billing/billing-overview.js +6 -0
  25. package/dist/billing/billing-overview.js.map +1 -1
  26. package/dist/billing/billing-standing.d.ts +8 -0
  27. package/dist/billing/billing-standing.js.map +1 -1
  28. package/dist/billing/cancel-subscription.d.ts +46 -0
  29. package/dist/billing/cancel-subscription.js +57 -0
  30. package/dist/billing/cancel-subscription.js.map +1 -0
  31. package/dist/billing/plan-card.d.ts +45 -1
  32. package/dist/billing/plan-card.js +53 -2
  33. package/dist/billing/plan-card.js.map +1 -1
  34. package/dist/billing/plan-switch.d.ts +10 -1
  35. package/dist/billing/plan-switch.js +22 -13
  36. package/dist/billing/plan-switch.js.map +1 -1
  37. package/dist/billing/subscription-actions.d.ts +37 -4
  38. package/dist/billing/subscription-actions.js +10 -3
  39. package/dist/billing/subscription-actions.js.map +1 -1
  40. package/dist/components/account-chips.d.ts +42 -1
  41. package/dist/components/account-chips.js +33 -0
  42. package/dist/components/account-chips.js.map +1 -1
  43. package/dist/components/empty-state.d.ts +2 -1
  44. package/dist/components/empty-state.js.map +1 -1
  45. package/dist/eslint/index.js +1 -1
  46. package/dist/i18n/defaults.js +5 -1
  47. package/dist/i18n/defaults.js.map +1 -1
  48. package/dist/i18n/german.js +79 -0
  49. package/dist/i18n/german.js.map +1 -1
  50. package/dist/i18n/kit-labels.d.ts +9 -0
  51. package/dist/i18n/kit-labels.js.map +1 -1
  52. package/dist/i18n/locales/en.js +93 -1
  53. package/dist/i18n/locales/en.js.map +3 -3
  54. package/dist/i18n/locales/es.js +76 -0
  55. package/dist/i18n/locales/es.js.map +1 -1
  56. package/dist/i18n/locales/fr.js +75 -0
  57. package/dist/i18n/locales/fr.js.map +1 -1
  58. package/dist/i18n/locales/hu.js +76 -0
  59. package/dist/i18n/locales/hu.js.map +1 -1
  60. package/dist/i18n/locales/it.js +76 -0
  61. package/dist/i18n/locales/it.js.map +1 -1
  62. package/dist/i18n/locales/zh.js +75 -0
  63. package/dist/i18n/locales/zh.js.map +1 -1
  64. package/dist/i18n/review.js +20 -1
  65. package/dist/i18n/review.js.map +1 -1
  66. package/dist/index.d.ts +18 -2
  67. package/dist/index.js +23 -1
  68. package/dist/index.js.map +1 -1
  69. package/dist/settings/settings-layout.d.ts +7 -1
  70. package/dist/settings/settings-layout.js +35 -27
  71. package/dist/settings/settings-layout.js.map +1 -1
  72. package/dist/shell/account-menu-language.d.ts +46 -0
  73. package/dist/shell/account-menu-language.js +64 -0
  74. package/dist/shell/account-menu-language.js.map +1 -0
  75. package/dist/shell/admin-menu.d.ts +46 -0
  76. package/dist/shell/admin-menu.js +60 -0
  77. package/dist/shell/admin-menu.js.map +1 -0
  78. package/dist/shell/app-shell.d.ts +10 -0
  79. package/dist/shell/app-shell.js +22 -4
  80. package/dist/shell/app-shell.js.map +1 -1
  81. package/dist/shell/dev-switchers.d.ts +53 -0
  82. package/dist/shell/dev-switchers.js +102 -0
  83. package/dist/shell/dev-switchers.js.map +1 -0
  84. package/dist/shell/sync-status-indicator.d.ts +86 -0
  85. package/dist/shell/sync-status-indicator.js +170 -0
  86. package/dist/shell/sync-status-indicator.js.map +1 -0
  87. package/dist/shell/top-bar-actions.d.ts +49 -0
  88. package/dist/shell/top-bar-actions.js +31 -0
  89. package/dist/shell/top-bar-actions.js.map +1 -0
  90. package/dist/shell/top-bar-parts-labels.d.ts +84 -0
  91. package/dist/shell/top-bar-parts-labels.js +48 -0
  92. package/dist/shell/top-bar-parts-labels.js.map +1 -0
  93. package/dist/shell/topbar-action-menu.d.ts +13 -1
  94. package/dist/shell/topbar-action-menu.js +5 -2
  95. package/dist/shell/topbar-action-menu.js.map +1 -1
  96. package/dist/shell/topbar-controls.d.ts +16 -3
  97. package/dist/shell/topbar-controls.js +5 -1
  98. package/dist/shell/topbar-controls.js.map +1 -1
  99. package/dist/shell/tour-menu.d.ts +58 -0
  100. package/dist/shell/tour-menu.js +73 -0
  101. package/dist/shell/tour-menu.js.map +1 -0
  102. package/dist/shell.d.ts +14 -0
  103. package/dist/shell.js +19 -0
  104. package/dist/shell.js.map +1 -1
  105. package/package.json +1 -1
  106. package/src/admin/admin-area-labels.ts +85 -0
  107. package/src/admin/admin-forbidden.tsx +75 -0
  108. package/src/admin/admin-overview.tsx +166 -0
  109. package/src/admin/admin-sections.tsx +137 -0
  110. package/src/admin/admin-tool-links.tsx +84 -0
  111. package/src/billing/billing-banner.tsx +32 -4
  112. package/src/billing/billing-labels.ts +53 -0
  113. package/src/billing/billing-overview.ts +37 -0
  114. package/src/billing/billing-standing.ts +8 -0
  115. package/src/billing/cancel-subscription.tsx +102 -0
  116. package/src/billing/plan-card.tsx +97 -1
  117. package/src/billing/plan-switch.tsx +16 -0
  118. package/src/billing/subscription-actions.tsx +64 -15
  119. package/src/components/account-chips.tsx +81 -1
  120. package/src/components/empty-state.tsx +2 -1
  121. package/src/i18n/defaults.ts +4 -0
  122. package/src/i18n/german.ts +92 -0
  123. package/src/i18n/kit-labels.tsx +9 -0
  124. package/src/i18n/locales/en.ts +19 -0
  125. package/src/i18n/locales/es.ts +86 -0
  126. package/src/i18n/locales/fr.ts +86 -0
  127. package/src/i18n/locales/hu.ts +84 -0
  128. package/src/i18n/locales/it.ts +87 -0
  129. package/src/i18n/locales/zh.ts +79 -0
  130. package/src/i18n/review.ts +19 -0
  131. package/src/index.ts +30 -2
  132. package/src/settings/settings-layout.tsx +58 -34
  133. package/src/shell/account-menu-language.tsx +116 -0
  134. package/src/shell/admin-menu.tsx +117 -0
  135. package/src/shell/app-shell.tsx +44 -3
  136. package/src/shell/dev-switchers.tsx +171 -0
  137. package/src/shell/sync-status-indicator.tsx +301 -0
  138. package/src/shell/top-bar-actions.tsx +79 -0
  139. package/src/shell/top-bar-parts-labels.ts +133 -0
  140. package/src/shell/topbar-action-menu.tsx +15 -2
  141. package/src/shell/topbar-controls.tsx +20 -3
  142. package/src/shell/tour-menu.tsx +144 -0
  143. package/src/shell.ts +24 -0
@@ -0,0 +1,75 @@
1
+ import type { ComponentPropsWithRef } from "react";
2
+ import { ShieldAlert } from "lucide-react";
3
+ import { cn } from "../lib/cn";
4
+ import { Button } from "../components/button";
5
+ import { EmptyState } from "../components/empty-state";
6
+ import type { LabelOverride } from "../i18n/kit-labels";
7
+ import { useAdminAreaLabels } from "./admin-area-labels";
8
+ import type { AdminAreaLabels } from "./admin-area-labels";
9
+
10
+ export interface AdminForbiddenProps extends Omit<ComponentPropsWithRef<"div">, "children" | "title"> {
11
+ /** The app's name, in the sentence: "This is where administrators run Kastlan." */
12
+ appName: string;
13
+ /** The button's target: the app's start page (keksdose `/budget`, kastlan `/dashboard`). */
14
+ homeHref: string;
15
+ /** The button's words, where the app names its start ("Back to the budget"). Default
16
+ * `adminArea.forbiddenHome`, "Go to the start page". */
17
+ homeLabel?: string;
18
+ /** Pass it to a translation reviewer: a second button, "Review translations", to the
19
+ * tool their role does have (§2.2 decision 8). */
20
+ reviewerHref?: string;
21
+ /** The heading's level. Default `h1`: the page stands alone inside the app shell. */
22
+ headingAs?: "h1" | "h2" | "h3";
23
+ /** Prop > `<UiKitProvider labels={{ adminArea }}>` > English. */
24
+ labels?: LabelOverride<AdminAreaLabels>;
25
+ }
26
+
27
+ /**
28
+ * The admin area's 403 page (0.42.0, docs/admin-harmonization.md §2.2 decision 8, §6.7),
29
+ * keksdose's `AdminForbidden`: "Only for administrators" / "This is where administrators
30
+ * run {app}. Your account cannot open this page.", and a button back to the app's start.
31
+ *
32
+ * It RENDERS, it does not redirect: the app's client gate shows it in place of the admin
33
+ * page, on the same admin check the account menu uses, inside the lazy route — so a
34
+ * bookmark keeps its address, and signing in as an admin opens the page that was asked
35
+ * for. The server's gate stays the rule. kastlan shows it on its admin tools (`/admin`,
36
+ * `/import`, `/feedback`); its work pages keep their generic 403.
37
+ *
38
+ * The words say only that this area is closed to this account, never that the person
39
+ * administers nothing anywhere: a kastlan superuser who isn't ADMIN in the acting company
40
+ * gets this page too.
41
+ */
42
+ export function AdminForbidden({
43
+ appName,
44
+ homeHref,
45
+ homeLabel,
46
+ reviewerHref,
47
+ headingAs = "h1",
48
+ labels: labelsProp,
49
+ className,
50
+ ...rest
51
+ }: AdminForbiddenProps) {
52
+ const labels = useAdminAreaLabels(labelsProp);
53
+ return (
54
+ <div {...rest} data-slot="admin-forbidden" className={cn("mx-auto w-full max-w-xl p-4 md:p-6", className)}>
55
+ <EmptyState
56
+ icon={<ShieldAlert />}
57
+ headingAs={headingAs}
58
+ title={labels.forbiddenTitle}
59
+ hint={labels.forbiddenBody(appName)}
60
+ action={
61
+ <>
62
+ <Button href={homeHref} variant="secondary">
63
+ {homeLabel ?? labels.forbiddenHome}
64
+ </Button>
65
+ {reviewerHref !== undefined && (
66
+ <Button href={reviewerHref} variant="secondary">
67
+ {labels.forbiddenReviewer}
68
+ </Button>
69
+ )}
70
+ </>
71
+ }
72
+ />
73
+ </div>
74
+ );
75
+ }
@@ -0,0 +1,166 @@
1
+ import type { ReactNode } from "react";
2
+ import { StatTile, StatTileGrid } from "../components/stat-tile";
3
+ import type { StatTileProps } from "../components/stat-tile";
4
+ import type { LabelOverride } from "../i18n/kit-labels";
5
+ import { useAdminAreaLabels } from "./admin-area-labels";
6
+ import type { AdminAreaLabels } from "./admin-area-labels";
7
+
8
+ /**
9
+ * The admin's start page (0.42.0, docs/admin-harmonization.md §2.4, §6.1–§6.5): a grid
10
+ * of tiles, each a count of what is waiting and a link to where the work is, fed by one
11
+ * server answer.
12
+ */
13
+
14
+ /**
15
+ * `GET /admin/attention` (§2.4 decision 14, §6.4) — server-kit's `AdminAttention`
16
+ * (`eifi1_server_kit.user_admin.attention`), as the API sends it.
17
+ *
18
+ * Each count is `null` where the app has no such thing or this viewer cannot act on it,
19
+ * and every count is `null` in a demo session. Demo accounts never count. `extra` holds
20
+ * the app's own counts, keyed as its overview names them (keksdose `support_waiting`,
21
+ * Kurvenschmiede `released_for_work`).
22
+ */
23
+ export interface AdminAttention {
24
+ /** "To triage": OPEN reports, crash reports included (§6.1). */
25
+ feedback_waiting: number | null;
26
+ /** Accounts that asked to be deleted — only where this viewer acts on them (§6.2). */
27
+ deletion_requests: number | null;
28
+ invitations_pending: number | null;
29
+ users_total: number | null;
30
+ /** Accounts made in the last seven days. */
31
+ users_new_7d: number | null;
32
+ extra: Record<string, number | null>;
33
+ }
34
+
35
+ /** The shared counts that are a tile of their own (`users_new_7d` is the users tile's line). */
36
+ export type AdminAttentionTile = "feedback_waiting" | "deletion_requests" | "invitations_pending" | "users_total";
37
+
38
+ /** Where each shared tile links when the app names nothing else (§2.4 decision 13). */
39
+ export const DEFAULT_ADMIN_ATTENTION_HREFS: Readonly<Record<AdminAttentionTile, string>> = Object.freeze({
40
+ feedback_waiting: "/feedback",
41
+ deletion_requests: "/admin/users?state=deletion_requested",
42
+ invitations_pending: "/admin/invitations",
43
+ users_total: "/admin/users",
44
+ });
45
+
46
+ /**
47
+ * The account menu's badge (§2.4 decision 15, §6.3): the sum of the counts that are work
48
+ * waiting on THIS admin — each app names its own (keksdose `["feedback_waiting",
49
+ * "support_waiting", "awaiting_verdict"]`, kastlan `["feedback_waiting"]`, Kurvenschmiede
50
+ * `["feedback_waiting", "deletion_requests"]`). A name is a shared count or an `extra`
51
+ * key; a `null` or missing count adds nothing. Invitations and users never belong in it.
52
+ * `null` while there is no answer yet, so the badge shows nothing rather than a 0.
53
+ */
54
+ export function adminWaitingCount(
55
+ attention: AdminAttention | null | undefined,
56
+ counts: readonly (AdminAttentionTile | (string & {}))[],
57
+ ): number | null {
58
+ if (!attention) return null;
59
+ let sum = 0;
60
+ for (const key of counts) {
61
+ const shared = (attention as unknown as Record<string, unknown>)[key];
62
+ const value = typeof shared === "number" ? shared : attention.extra?.[key];
63
+ if (typeof value === "number" && value > 0) sum += value;
64
+ }
65
+ return sum;
66
+ }
67
+
68
+ export interface AttentionTileProps extends Omit<StatTileProps, "href" | "onClick" | "value"> {
69
+ /** The count. `null` shows the tile's dash; {@link AdminOverview} leaves such a tile out. */
70
+ count: number | null | undefined;
71
+ /** Where the work is — the tile is a link to it. */
72
+ href: string;
73
+ }
74
+
75
+ /**
76
+ * One tile of the overview: a {@link StatTile} that is a LINK to where the work is, its
77
+ * count the headline. The whole tile is the link, named by its label; route it through
78
+ * `renderLink` or the provider's link component, as any StatTile.
79
+ */
80
+ export function AttentionTile({ count, href, ...tile }: AttentionTileProps) {
81
+ return <StatTile data-slot="attention-tile" {...tile} value={count ?? null} href={href} />;
82
+ }
83
+
84
+ /** One of the app's own tiles (§2.4 decision 13: keksdose's "Support waiting"). */
85
+ export interface AdminExtraTile {
86
+ /** Unique among the tiles; usually the `extra` key it shows. */
87
+ key: string;
88
+ label: ReactNode;
89
+ /** `null` or `undefined` leaves the tile out, as for a shared one. */
90
+ count: number | null | undefined;
91
+ href: string;
92
+ /** A line under the count. */
93
+ description?: ReactNode;
94
+ }
95
+
96
+ export interface AdminOverviewProps {
97
+ /** The server's answer; `undefined` while it loads (the grid shows its skeletons). */
98
+ attention: AdminAttention | null | undefined;
99
+ /**
100
+ * Where the shared tiles link, over {@link DEFAULT_ADMIN_ATTENTION_HREFS} — the
101
+ * inbox's address filtered to OPEN (§6.1) is the app's own:
102
+ * `{ feedback_waiting: "/feedback?status=OPEN" }`.
103
+ */
104
+ hrefs?: Partial<Record<AdminAttentionTile, string>>;
105
+ /** The app's own tiles, after the shared ones, in this order. */
106
+ extraTiles?: readonly AdminExtraTile[];
107
+ /** Passed to every tile — `renderLink` for the router, `size`, `variant`. */
108
+ tileProps?: Pick<StatTileProps, "renderLink" | "size" | "variant" | "locale">;
109
+ /** Prop > `<UiKitProvider labels={{ adminArea }}>` > English. */
110
+ labels?: LabelOverride<AdminAreaLabels>;
111
+ className?: string;
112
+ }
113
+
114
+ /**
115
+ * The overview section (§2.4): the shared tiles in their order — To triage, Deletion
116
+ * requests, Pending invitations, Users (with the new accounts of the last 7 days under
117
+ * the total) — then the app's `extraTiles`. A tile whose count is `null` is left out,
118
+ * so each app shows only what it has; a `0` is a quiet tile, "nothing waiting".
119
+ *
120
+ * Put it in the `overview` section's `SettingsSection` (titled by the sidebar, so
121
+ * `titleVisible={false}`). keksdose links its metrics from here with at most two tiles
122
+ * (§6.5).
123
+ */
124
+ export function AdminOverview({
125
+ attention,
126
+ hrefs,
127
+ extraTiles = [],
128
+ tileProps,
129
+ labels: labelsProp,
130
+ className,
131
+ }: AdminOverviewProps) {
132
+ const labels = useAdminAreaLabels(labelsProp);
133
+ const href = { ...DEFAULT_ADMIN_ATTENTION_HREFS, ...hrefs };
134
+ const loading = attention === undefined;
135
+ const shared: { key: AdminAttentionTile; label: string; description?: ReactNode }[] = [
136
+ { key: "feedback_waiting", label: labels.tiles.feedbackWaiting },
137
+ { key: "deletion_requests", label: labels.tiles.deletionRequests },
138
+ { key: "invitations_pending", label: labels.tiles.invitationsPending },
139
+ {
140
+ key: "users_total",
141
+ label: labels.tiles.users,
142
+ description:
143
+ attention && typeof attention.users_new_7d === "number" ? labels.tiles.usersNew(attention.users_new_7d) : undefined,
144
+ },
145
+ ];
146
+ const tiles = [
147
+ ...shared.map((t) => ({ ...t, count: attention ? attention[t.key] : undefined, href: href[t.key] })),
148
+ ...extraTiles,
149
+ ].filter((t) => loading || (t.count !== null && t.count !== undefined));
150
+ if (!loading && tiles.length === 0) return null;
151
+ return (
152
+ <StatTileGrid data-slot="admin-overview" loading={loading} className={className}>
153
+ {tiles.map((t) => (
154
+ <AttentionTile
155
+ key={t.key}
156
+ {...tileProps}
157
+ data-attention={t.key}
158
+ label={t.label}
159
+ count={t.count}
160
+ href={t.href}
161
+ description={t.description}
162
+ />
163
+ ))}
164
+ </StatTileGrid>
165
+ );
166
+ }
@@ -0,0 +1,137 @@
1
+ import { createElement } from "react";
2
+ import type { ReactNode } from "react";
3
+ import { History, LayoutDashboard, Mail, Receipt, Users } from "lucide-react";
4
+ import type { LucideIcon } from "lucide-react";
5
+ import type { SettingsGroup } from "../settings/settings-catalogue";
6
+ import { DEFAULT_ADMIN_AREA_LABELS } from "./admin-area-labels";
7
+ import type { AdminAreaLabels, AdminSharedSection } from "./admin-area-labels";
8
+
9
+ /**
10
+ * The admin area's sections (0.42.0, docs/admin-harmonization.md §2.3, §6.8): the five
11
+ * every app shares, in the template's order, and the helper that builds an app's
12
+ * `SettingsLayout` catalogue groups from them and the app's own.
13
+ */
14
+
15
+ /** One shared section: its path segment and its icon. The words are `adminArea.sections`. */
16
+ export interface AdminSectionDefinition {
17
+ id: AdminSharedSection;
18
+ icon: LucideIcon;
19
+ }
20
+
21
+ /**
22
+ * The shared sections in the template's order (§2.3 decision 10, §6.13): Overview, Users,
23
+ * Invitations, Billing, Activity. An app's own sections go between them
24
+ * ({@link adminSections}).
25
+ */
26
+ export const ADMIN_SECTIONS: readonly AdminSectionDefinition[] = Object.freeze([
27
+ { id: "overview", icon: LayoutDashboard },
28
+ { id: "users", icon: Users },
29
+ { id: "invitations", icon: Mail },
30
+ { id: "billing", icon: Receipt },
31
+ { id: "activity", icon: History },
32
+ ]);
33
+
34
+ /**
35
+ * One of the app's own sections: a catalogue group with its words, plus where it goes.
36
+ * `after` names the section it follows — a shared one or another of the app's own. Left
37
+ * out, it goes where the template puts an app's sections, after Invitations and before
38
+ * Billing, in the order given.
39
+ */
40
+ export interface AdminOwnSection<G extends string = string> extends SettingsGroup<G> {
41
+ after?: AdminSharedSection | G;
42
+ }
43
+
44
+ export interface AdminSectionsOptions {
45
+ /**
46
+ * Shared sections this app does not have — keksdose and Kurvenschmiede have no billing
47
+ * view (`["billing"]`). Left out, every shared section is in the catalogue.
48
+ */
49
+ leaveOut?: readonly AdminSharedSection[];
50
+ /**
51
+ * A shared section that is in the catalogue but hidden for now, as
52
+ * {@link SettingsGroup.visible}: kastlan's `{ billing: billingEnabled }` (settings §5),
53
+ * whose path then acts as an unknown one.
54
+ */
55
+ visible?: Partial<Record<AdminSharedSection, boolean>>;
56
+ }
57
+
58
+ /** The shared section after which the app's sections go when they name no place. */
59
+ const OWN_DEFAULT_AFTER: AdminSharedSection = "invitations";
60
+
61
+ /**
62
+ * An app's admin catalogue groups, in the template's order (§2.3 decision 10, §6.8): the
63
+ * shared sections with the kit's icons and words, and the app's own at the places they
64
+ * name. The result is `SettingsLayout`'s `groups`; the entries stay the app's (a group
65
+ * with no visible entry is hidden, as on any settings page).
66
+ *
67
+ * const groups = adminSections(useAdminAreaLabels(), [
68
+ * { id: "metrics", icon: <BarChart3 />, title: t("…"), help: t("…"), after: "overview" },
69
+ * { id: "messaging", icon: <MessageSquare />, title: t("…"), help: t("…") },
70
+ * { id: "health", icon: <HeartPulse />, title: t("…"), help: t("…"), after: "billing" },
71
+ * ], { leaveOut: ["billing"] });
72
+ *
73
+ * gives keksdose's overview, metrics, users, invitations, messaging, health, activity.
74
+ * An `after` that names a left-out section takes that section's place. Kurvenschmiede's
75
+ * Teams needs no `after`: between Invitations and Activity is the default.
76
+ *
77
+ * `labels` is the `adminArea` namespace, resolved — {@link useAdminAreaLabels} inside a
78
+ * component, or the app's catalogue for the language; `undefined` is English. Throws for
79
+ * an own section whose id is a shared one, an id given twice, or an `after` that names no
80
+ * section: the catalogue is built once, and a section quietly missing from it is worse.
81
+ */
82
+ export function adminSections<G extends string = never>(
83
+ labels: AdminAreaLabels | undefined,
84
+ own: readonly AdminOwnSection<G>[] = [],
85
+ options: AdminSectionsOptions = {},
86
+ ): SettingsGroup<AdminSharedSection | G>[] {
87
+ const words = labels ?? DEFAULT_ADMIN_AREA_LABELS;
88
+ const leaveOut = new Set<string>(options.leaveOut ?? []);
89
+ const shared = new Set<string>(ADMIN_SECTIONS.map((s) => s.id));
90
+ const ownIds = new Set<string>();
91
+ for (const section of own) {
92
+ if (shared.has(section.id)) throw new Error(`adminSections: "${section.id}" is a shared section's id`);
93
+ if (ownIds.has(section.id)) throw new Error(`adminSections: "${section.id}" is given twice`);
94
+ ownIds.add(section.id);
95
+ }
96
+ for (const section of own) {
97
+ const after = section.after;
98
+ if (after !== undefined && !shared.has(after) && !ownIds.has(after)) {
99
+ throw new Error(`adminSections: "${section.id}" goes after "${after}", which is no section`);
100
+ }
101
+ }
102
+
103
+ // Each section's followers, in the order given: the shared ones, then the own ones
104
+ // under their `after`, recursively, so an own section may follow another own one.
105
+ const followers = new Map<string, AdminOwnSection<G>[]>();
106
+ for (const section of own) {
107
+ const after = section.after ?? OWN_DEFAULT_AFTER;
108
+ followers.set(after, [...(followers.get(after) ?? []), section]);
109
+ }
110
+
111
+ const out: SettingsGroup<AdminSharedSection | G>[] = [];
112
+ const placeAfter = (id: string) => {
113
+ for (const section of followers.get(id) ?? []) {
114
+ const { after: _after, ...group } = section;
115
+ out.push(group);
116
+ placeAfter(section.id);
117
+ }
118
+ };
119
+ for (const { id, icon } of ADMIN_SECTIONS) {
120
+ if (!leaveOut.has(id)) {
121
+ const visible = options.visible?.[id];
122
+ out.push({
123
+ id,
124
+ icon: createElement(icon, { "aria-hidden": true }) as ReactNode,
125
+ title: words.sections[id].title,
126
+ help: words.sections[id].help,
127
+ ...(visible === undefined ? null : { visible }),
128
+ });
129
+ }
130
+ // A left-out section's followers keep its place.
131
+ placeAfter(id);
132
+ }
133
+ const placed = new Set<string>(out.map((g) => g.id));
134
+ const stuck = own.filter((s) => !placed.has(s.id)).map((s) => s.id);
135
+ if (stuck.length) throw new Error(`adminSections: ${stuck.join(", ")} follow each other in a circle`);
136
+ return out;
137
+ }
@@ -0,0 +1,84 @@
1
+ import { useId } from "react";
2
+ import type { ReactElement, ReactNode } from "react";
3
+ import { cn } from "../lib/cn";
4
+ import { List, ListItem } from "../components/list";
5
+ import type { ListItemLinkProps } from "../components/list";
6
+ import type { LabelOverride } from "../i18n/kit-labels";
7
+ import { useAdminAreaLabels } from "./admin-area-labels";
8
+ import type { AdminAreaLabels } from "./admin-area-labels";
9
+
10
+ /** One link of the Tools list. */
11
+ export interface AdminToolLink {
12
+ /** Unique in the list. */
13
+ key: string;
14
+ label: string;
15
+ href: string;
16
+ /** A lucide element, sized by the row. */
17
+ icon?: ReactNode;
18
+ /** `false` leaves the link out — Translations for an admin who doesn't review
19
+ * (§6.11, ka F7). Default: shown. */
20
+ visible?: boolean;
21
+ }
22
+
23
+ export interface AdminToolLinksProps {
24
+ links: readonly AdminToolLink[];
25
+ /**
26
+ * `sidebar` (default): a `<nav>` named and headed "Tools", for `SettingsLayout`'s
27
+ * `sidebarFooter` under the section list on a desktop. `list`: the bare rows, for
28
+ * `SettingsLayout`'s `phoneFooter`, which puts them in a list of their own.
29
+ */
30
+ variant?: "sidebar" | "list";
31
+ /** Your router's link. Default: the `<UiKitProvider linkComponent>`, then `<a>`. */
32
+ renderLink?: (props: ListItemLinkProps) => ReactElement;
33
+ /** Prop > `<UiKitProvider labels={{ adminArea }}>` > English. */
34
+ labels?: LabelOverride<AdminAreaLabels>;
35
+ className?: string;
36
+ }
37
+
38
+ /**
39
+ * The admin area's links to the admin tools that are pages of their own (0.42.0,
40
+ * docs/admin-harmonization.md §2.5 decision 16, §6.11): Translations, and the app's task
41
+ * pages (kastlan's Data import). The feedback inbox is not one of them: the top bar's
42
+ * feedback menu reaches it, and the overview's tiles link to it.
43
+ *
44
+ * Draw it twice from one list — at the foot of the section sidebar and in the phone
45
+ * footer:
46
+ *
47
+ * <SettingsLayout
48
+ * sidebarFooter={<AdminToolLinks links={TOOLS} />}
49
+ * phoneFooter={<AdminToolLinks links={TOOLS} variant="list" />}
50
+ * …
51
+ * />
52
+ *
53
+ * With no visible link it renders nothing.
54
+ */
55
+ export function AdminToolLinks({ links, variant = "sidebar", renderLink, labels: labelsProp, className }: AdminToolLinksProps) {
56
+ const labels = useAdminAreaLabels(labelsProp);
57
+ const headingId = useId();
58
+ const shown = links.filter((l) => l.visible !== false);
59
+ if (shown.length === 0) return null;
60
+ const rows = shown.map((l) => (
61
+ <ListItem
62
+ key={l.key}
63
+ href={l.href}
64
+ renderLink={renderLink}
65
+ title={l.label}
66
+ leading={
67
+ l.icon === undefined ? undefined : (
68
+ <span aria-hidden className="flex shrink-0 text-muted [&_svg]:size-4">
69
+ {l.icon}
70
+ </span>
71
+ )
72
+ }
73
+ />
74
+ ));
75
+ if (variant === "list") return <>{rows}</>;
76
+ return (
77
+ <nav data-slot="admin-tool-links" aria-labelledby={headingId} className={cn("space-y-1", className)}>
78
+ <div id={headingId} className="px-3 text-caption font-semibold uppercase tracking-wide text-muted">
79
+ {labels.tools}
80
+ </div>
81
+ <List density="compact">{rows}</List>
82
+ </nav>
83
+ );
84
+ }
@@ -8,6 +8,7 @@ import { Button } from "../components/button";
8
8
  import { Spinner } from "../components/spinner";
9
9
  import { useBillingLabels } from "./billing-labels";
10
10
  import type { BillingLabels } from "./billing-labels";
11
+ import type { BillingPortalAccess } from "./billing-overview";
11
12
 
12
13
  /**
13
14
  * The billing banners (docs/billing-harmonization.md §3.3, §7, §12.6, §12.21):
@@ -16,7 +17,8 @@ import type { BillingLabels } from "./billing-labels";
16
17
  * - `grant-ending` — from 7 days before `comped_until`: a beta user's 12 months, an
17
18
  * operator's grant;
18
19
  * - `payment-failed` — from the first failed payment (`past_due`), while the provider
19
- * retries;
20
+ * retries; since 0.42, for an admin who isn't the buyer (`portal="buyer_only"`), it
21
+ * names who can update the payment method, with no button;
20
22
  * - `plan-ended` — out of good standing: read-only, never locked (§2.3);
21
23
  * - `guest` — a guest in someone else's read-only item (§12.6);
22
24
  * - `processing` — back from checkout before the webhook landed (§12.21).
@@ -78,6 +80,8 @@ export type BillingBannerProps = BillingBannerBaseProps &
78
80
  /** Calendar days left — `billingDaysLeft(trial_ends_at)`. 0 is today. */
79
81
  daysLeft: number;
80
82
  item?: never;
83
+ portal?: never;
84
+ buyerName?: never;
81
85
  }
82
86
  | {
83
87
  kind: "guest";
@@ -85,12 +89,32 @@ export type BillingBannerProps = BillingBannerBaseProps &
85
89
  * the banner says "for now" and nothing more (§12.6). */
86
90
  item?: string;
87
91
  daysLeft?: never;
92
+ portal?: never;
93
+ buyerName?: never;
88
94
  }
89
95
  | {
90
- kind: "payment-failed" | "plan-ended" | "processing";
96
+ kind: "payment-failed";
97
+ /**
98
+ * 0.42 (§16.7 A, §16.8): `GET /billing/status`'s `portal` (`BillingStanding`).
99
+ * `"buyer_only"` — the viewer isn't the buyer, so the portal's page for the card
100
+ * would answer 403: the banner says who can update the payment method
101
+ * (`paymentFailedAskBuyer`) and shows NO button, whatever `actionHref` or
102
+ * `onAction` say. `"open"` (default): as before.
103
+ */
104
+ portal?: BillingPortalAccess;
105
+ /** 0.42: the status's `buyer_name`, under `"buyer_only"`. Empty: "…the admin who
106
+ * bought the subscription". */
107
+ buyerName?: string | null;
91
108
  daysLeft?: never;
92
109
  item?: never;
93
110
  }
111
+ | {
112
+ kind: "plan-ended" | "processing";
113
+ daysLeft?: never;
114
+ item?: never;
115
+ portal?: never;
116
+ buyerName?: never;
117
+ }
94
118
  );
95
119
 
96
120
  /** The last days, in which an ending trial or grant turns from news into a warning. */
@@ -128,6 +152,8 @@ export function BillingBanner(props: BillingBannerProps) {
128
152
  kind,
129
153
  daysLeft,
130
154
  item,
155
+ portal,
156
+ buyerName,
131
157
  tone,
132
158
  variant = "strip",
133
159
  size,
@@ -147,6 +173,8 @@ export function BillingBanner(props: BillingBannerProps) {
147
173
  let text: string;
148
174
  let icon: ReactNode;
149
175
  let ownAction: string | undefined;
176
+ // 0.42 (§16.7 A): only the buyer can reach the portal's card page.
177
+ const askBuyer = kind === "payment-failed" && portal === "buyer_only";
150
178
  switch (kind) {
151
179
  case "trial-ending":
152
180
  text = labels.trialEnding(days);
@@ -159,7 +187,7 @@ export function BillingBanner(props: BillingBannerProps) {
159
187
  ownAction = labels.choosePlan;
160
188
  break;
161
189
  case "payment-failed":
162
- text = labels.paymentFailed;
190
+ text = askBuyer ? labels.paymentFailedAskBuyer(buyerName || undefined) : labels.paymentFailed;
163
191
  icon = <CreditCard />;
164
192
  ownAction = labels.updatePayment;
165
193
  break;
@@ -182,7 +210,7 @@ export function BillingBanner(props: BillingBannerProps) {
182
210
 
183
211
  const words = actionLabel ?? ownAction;
184
212
  const action =
185
- words === undefined || (actionHref === undefined && onAction === undefined) ? undefined : actionHref !== undefined ? (
213
+ askBuyer || words === undefined || (actionHref === undefined && onAction === undefined) ? undefined : actionHref !== undefined ? (
186
214
  <Button href={actionHref} variant="secondary" size="sm">
187
215
  {words}
188
216
  </Button>
@@ -108,6 +108,13 @@ export interface BillingLabels {
108
108
  choosePlan: string;
109
109
  /** The payment-failed banner's action, to the provider's portal: "Update payment method". */
110
110
  updatePayment: string;
111
+ /**
112
+ * 0.42 (§16.7 A, §16.8): the payment-failed banner for an admin who isn't the buyer
113
+ * (`portal: "buyer_only"`), with no button — only the buyer can change the card.
114
+ * `buyer` is their display name, or `undefined` when they are gone ("the admin who
115
+ * bought the subscription").
116
+ */
117
+ paymentFailedAskBuyer: (buyer?: string) => string;
111
118
  /** The processing banner's action, when the app gives one: "Check again". */
112
119
  checkAgain: string;
113
120
 
@@ -153,6 +160,26 @@ export interface BillingLabels {
153
160
  */
154
161
  notAtProvider: string;
155
162
 
163
+ /* ── The portal for the buyer only, the in-app cancel (0.42, §16) ── */
164
+ /**
165
+ * In place of "Payment and invoices" for an admin who isn't the buyer (`portal:
166
+ * "buyer_only"`, §16.2 decision 3): the provider's portal opens only for the buyer.
167
+ * `buyer` is their display name — or `undefined` when they are gone or have left the
168
+ * company, and the words then say "the admin who bought the subscription".
169
+ */
170
+ buyerHolds: (buyer?: string) => string;
171
+ /** `CancelSubscriptionConfirm`'s title: "Cancel subscription". */
172
+ cancelConfirmTitle: string;
173
+ /** Its body; `date` is the period's end, formatted: "Your subscription ends on
174
+ * 9 Nov 2026. Until then everything works as before." */
175
+ cancelConfirmBody: (date: string) => string;
176
+ /** Its confirm button (§16.4): "Cancel subscription now". German: "Jetzt kündigen",
177
+ * the confirmation button's words in §312k BGB. */
178
+ cancelConfirmAction: string;
179
+ /** In place of "Cancel subscription" while a cancel is scheduled (§16.7 C, `POST
180
+ * /billing/resume`): "Keep subscription". */
181
+ keepSubscription: string;
182
+
156
183
  /* ── The pay page (§14.4) ── */
157
184
  /* Built into the static page `dist/pay/` at the kit's build: it has no React and no
158
185
  provider, so an app's override never reaches it. */
@@ -184,6 +211,15 @@ export interface BillingLabels {
184
211
  /** The confirm button: "Change plan". */
185
212
  switchConfirm: string;
186
213
 
214
+ /* ── The permanent-grant warning (0.42, §16.2 decision 5, §16.8 B) ── */
215
+ /** The warning's title, before a checkout (`PlanPicker`) or a switch
216
+ * (`PlanSwitchConfirm`) under a grant without an end: "Your free access continues". */
217
+ grantWarningTitle: string;
218
+ /** What the purchase does under it: nothing to the plan while the grant runs. */
219
+ grantWarningBody: string;
220
+ /** `PlanPicker`'s button that goes on to the checkout: "Buy anyway". */
221
+ grantWarningAction: string;
222
+
187
223
  /* ── Offline (§12.5) ── */
188
224
  /** Changes refused as `billing_read_only` inside a sync reply, kept queued and sent
189
225
  * after payment: "3 changes waiting for a plan". */
@@ -271,6 +307,10 @@ export const DEFAULT_BILLING_LABELS: BillingLabels = {
271
307
  processing: "Your payment is being processed. Your plan starts as soon as it’s confirmed; this page updates by itself.",
272
308
  choosePlan: "Choose a plan",
273
309
  updatePayment: "Update payment method",
310
+ paymentFailedAskBuyer: (buyer) =>
311
+ buyer
312
+ ? `The payment failed. ${buyer} can update the payment method.`
313
+ : "The payment failed. The admin who bought the subscription can update the payment method.",
274
314
  checkAgain: "Check again",
275
315
 
276
316
  lockReason: "Your plan has ended. Choose a plan to make changes again.",
@@ -286,6 +326,14 @@ export const DEFAULT_BILLING_LABELS: BillingLabels = {
286
326
  manage: "Payment and invoices",
287
327
  cancel: "Cancel subscription",
288
328
  notAtProvider: "Nothing to manage yet. Payments and invoices appear here once you have a paid plan.",
329
+ buyerHolds: (buyer) =>
330
+ buyer
331
+ ? `The payment method and the invoices are with ${buyer}, who bought the subscription.`
332
+ : "The payment method and the invoices are with the admin who bought the subscription.",
333
+ cancelConfirmTitle: "Cancel subscription",
334
+ cancelConfirmBody: (date) => `Your subscription ends on ${date}. Until then everything works as before.`,
335
+ cancelConfirmAction: "Cancel subscription now",
336
+ keepSubscription: "Keep subscription",
289
337
 
290
338
  payOpening: "Opening the secure checkout…",
291
339
  payNothing: "There’s no payment to make here. To choose a plan, go back to the app.",
@@ -300,6 +348,11 @@ export const DEFAULT_BILLING_LABELS: BillingLabels = {
300
348
  switchNextCharge: (date) => `Next charge on ${date}`,
301
349
  switchConfirm: "Change plan",
302
350
 
351
+ grantWarningTitle: "Your free access continues",
352
+ grantWarningBody:
353
+ "You have free access with no end date. A purchase won’t change your plan while the free access runs: you would pay for a plan that doesn’t apply.",
354
+ grantWarningAction: "Buy anyway",
355
+
303
356
  waitingChanges: (count) =>
304
357
  count === 1 ? "1 change waiting for a plan" : `${count} changes waiting for a plan`,
305
358
  discardWaiting: "Discard waiting changes",