@eifi1/ui-kit 0.29.0 → 0.30.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 (187) hide show
  1. package/README.md +26 -4
  2. package/dist/account/account-parts.d.ts +21 -0
  3. package/dist/account/account-parts.js +40 -0
  4. package/dist/account/account-parts.js.map +1 -0
  5. package/dist/account/data-export-setting.d.ts +73 -0
  6. package/dist/account/data-export-setting.js +113 -0
  7. package/dist/account/data-export-setting.js.map +1 -0
  8. package/dist/account/delete-account-setting.d.ts +91 -0
  9. package/dist/account/delete-account-setting.js +199 -0
  10. package/dist/account/delete-account-setting.js.map +1 -0
  11. package/dist/account/email-change-setting.d.ts +136 -0
  12. package/dist/account/email-change-setting.js +277 -0
  13. package/dist/account/email-change-setting.js.map +1 -0
  14. package/dist/account/sessions-setting.d.ts +110 -0
  15. package/dist/account/sessions-setting.js +146 -0
  16. package/dist/account/sessions-setting.js.map +1 -0
  17. package/dist/admin/admin-action-confirm.d.ts +91 -0
  18. package/dist/admin/admin-action-confirm.js +276 -0
  19. package/dist/admin/admin-action-confirm.js.map +1 -0
  20. package/dist/admin/admin-action-log.d.ts +105 -0
  21. package/dist/admin/admin-action-log.js +153 -0
  22. package/dist/admin/admin-action-log.js.map +1 -0
  23. package/dist/admin/admin-parts.d.ts +40 -0
  24. package/dist/admin/admin-parts.js +45 -0
  25. package/dist/admin/admin-parts.js.map +1 -0
  26. package/dist/admin/invitations-panel.d.ts +91 -0
  27. package/dist/admin/invitations-panel.js +289 -0
  28. package/dist/admin/invitations-panel.js.map +1 -0
  29. package/dist/admin/reviewer-scope-editor.d.ts +91 -0
  30. package/dist/admin/reviewer-scope-editor.js +134 -0
  31. package/dist/admin/reviewer-scope-editor.js.map +1 -0
  32. package/dist/admin/role-select.d.ts +91 -0
  33. package/dist/admin/role-select.js +128 -0
  34. package/dist/admin/role-select.js.map +1 -0
  35. package/dist/admin/transfer-ownership-dialog.d.ts +91 -0
  36. package/dist/admin/transfer-ownership-dialog.js +83 -0
  37. package/dist/admin/transfer-ownership-dialog.js.map +1 -0
  38. package/dist/admin/user-roster.d.ts +91 -0
  39. package/dist/admin/user-roster.js +285 -0
  40. package/dist/admin/user-roster.js.map +1 -0
  41. package/dist/auth/auth-errors.d.ts +85 -6
  42. package/dist/auth/auth-errors.js +62 -2
  43. package/dist/auth/auth-errors.js.map +1 -1
  44. package/dist/auth/forgot-password-form.d.ts +10 -3
  45. package/dist/auth/forgot-password-form.js +6 -3
  46. package/dist/auth/forgot-password-form.js.map +1 -1
  47. package/dist/auth/register-form.d.ts +17 -12
  48. package/dist/auth/register-form.js +6 -4
  49. package/dist/auth/register-form.js.map +1 -1
  50. package/dist/auth/reset-password-form.d.ts +10 -3
  51. package/dist/auth/reset-password-form.js +6 -3
  52. package/dist/auth/reset-password-form.js.map +1 -1
  53. package/dist/auth/sign-in-form.d.ts +61 -9
  54. package/dist/auth/sign-in-form.js +94 -13
  55. package/dist/auth/sign-in-form.js.map +1 -1
  56. package/dist/auth/verify-email.d.ts +7 -2
  57. package/dist/auth/verify-email.js +44 -8
  58. package/dist/auth/verify-email.js.map +1 -1
  59. package/dist/chart.d.ts +16 -11
  60. package/dist/components/account-chips.d.ts +47 -7
  61. package/dist/components/account-chips.js +19 -3
  62. package/dist/components/account-chips.js.map +1 -1
  63. package/dist/components/account-settings-labels.d.ts +12 -1
  64. package/dist/components/account-settings-labels.js +4 -1
  65. package/dist/components/account-settings-labels.js.map +1 -1
  66. package/dist/components/account-settings.d.ts +61 -6
  67. package/dist/components/account-settings.js +115 -15
  68. package/dist/components/account-settings.js.map +1 -1
  69. package/dist/components/amount-input.d.ts +17 -12
  70. package/dist/components/button-group.d.ts +17 -12
  71. package/dist/components/calculator.d.ts +17 -12
  72. package/dist/components/confirm-dialog.d.ts +17 -12
  73. package/dist/components/copy-button.d.ts +14 -9
  74. package/dist/components/danger-confirm.d.ts +17 -12
  75. package/dist/components/facing-pair.d.ts +17 -12
  76. package/dist/components/file-button.d.ts +17 -12
  77. package/dist/components/file-dropzone.d.ts +17 -12
  78. package/dist/components/form-actions.d.ts +17 -12
  79. package/dist/components/iban-input.d.ts +17 -12
  80. package/dist/components/language-select.d.ts +17 -12
  81. package/dist/components/legal-page.d.ts +17 -12
  82. package/dist/components/legal.d.ts +17 -12
  83. package/dist/components/money-field.d.ts +17 -12
  84. package/dist/components/number-field.d.ts +17 -12
  85. package/dist/components/number-input.d.ts +17 -12
  86. package/dist/components/numpad-sheet.d.ts +17 -12
  87. package/dist/components/phone-input.d.ts +17 -12
  88. package/dist/components/series-chart.d.ts +17 -12
  89. package/dist/components/settings-fields.d.ts +16 -11
  90. package/dist/components/share-card.d.ts +16 -11
  91. package/dist/components/text-link.d.ts +17 -12
  92. package/dist/components/time-input.d.ts +17 -12
  93. package/dist/components/ui.d.ts +13 -8
  94. package/dist/{register-form-V1OeNlMr.d.ts → delete-account-setting-CGVMckMw.d.ts} +6616 -5645
  95. package/dist/feedback/feedback-attachment.d.ts +17 -12
  96. package/dist/feedback/feedback-context.d.ts +17 -12
  97. package/dist/feedback/feedback-crash.d.ts +17 -12
  98. package/dist/feedback/feedback-dialog.d.ts +17 -12
  99. package/dist/feedback/feedback-inbox.d.ts +17 -12
  100. package/dist/feedback/feedback-labels.d.ts +17 -12
  101. package/dist/feedback/feedback-menu.d.ts +17 -12
  102. package/dist/feedback/feedback-record.d.ts +17 -12
  103. package/dist/feedback/feedback-row-detail.d.ts +17 -12
  104. package/dist/feedback/feedback-status-undo.d.ts +17 -12
  105. package/dist/feedback/feedback-submit.d.ts +17 -12
  106. package/dist/feedback/feedback-swipe.d.ts +17 -12
  107. package/dist/feedback/feedback-table.d.ts +14 -9
  108. package/dist/feedback/feedback-thread.d.ts +17 -12
  109. package/dist/feedback.d.ts +17 -12
  110. package/dist/hooks/use-anchored-panel.d.ts +6 -2
  111. package/dist/hooks/use-anchored-panel.js +2 -1
  112. package/dist/hooks/use-anchored-panel.js.map +1 -1
  113. package/dist/hooks/use-file-drop.d.ts +17 -12
  114. package/dist/i18n/defaults.d.ts +17 -12
  115. package/dist/i18n/defaults.js +22 -0
  116. package/dist/i18n/defaults.js.map +1 -1
  117. package/dist/i18n/german.d.ts +17 -12
  118. package/dist/i18n/german.js +215 -11
  119. package/dist/i18n/german.js.map +1 -1
  120. package/dist/i18n/kit-labels.d.ts +10 -5
  121. package/dist/i18n/kit-labels.js.map +1 -1
  122. package/dist/i18n/languages.d.ts +11 -6
  123. package/dist/i18n/locales/de-CH.d.ts +17 -12
  124. package/dist/i18n/locales/en.d.ts +17 -12
  125. package/dist/i18n/locales/es.d.ts +17 -12
  126. package/dist/i18n/locales/es.js +207 -9
  127. package/dist/i18n/locales/es.js.map +1 -1
  128. package/dist/i18n/locales/fr.d.ts +17 -12
  129. package/dist/i18n/locales/fr.js +209 -6
  130. package/dist/i18n/locales/fr.js.map +1 -1
  131. package/dist/i18n/locales/hu.d.ts +17 -12
  132. package/dist/i18n/locales/hu.js +207 -11
  133. package/dist/i18n/locales/hu.js.map +1 -1
  134. package/dist/i18n/locales/it.d.ts +17 -12
  135. package/dist/i18n/locales/it.js +209 -6
  136. package/dist/i18n/locales/it.js.map +1 -1
  137. package/dist/i18n/locales/zh.d.ts +17 -12
  138. package/dist/i18n/locales/zh.js +200 -6
  139. package/dist/i18n/locales/zh.js.map +1 -1
  140. package/dist/i18n/review.d.ts +17 -12
  141. package/dist/i18n/review.js +37 -1
  142. package/dist/i18n/review.js.map +1 -1
  143. package/dist/index.d.ts +8 -3
  144. package/dist/index.js +53 -0
  145. package/dist/index.js.map +1 -1
  146. package/dist/rhf/fields.d.ts +17 -12
  147. package/dist/rhf/form.d.ts +17 -12
  148. package/dist/rhf.d.ts +17 -12
  149. package/dist/shell/app-shell.d.ts +17 -12
  150. package/dist/shell/top-bar-brand.d.ts +17 -12
  151. package/dist/shell.d.ts +11 -6
  152. package/dist/wizard/stepper-nav.d.ts +17 -12
  153. package/dist/wizard.d.ts +17 -12
  154. package/package.json +1 -1
  155. package/src/account/account-parts.ts +67 -0
  156. package/src/account/data-export-setting.tsx +218 -0
  157. package/src/account/delete-account-setting.tsx +362 -0
  158. package/src/account/email-change-setting.tsx +457 -0
  159. package/src/account/sessions-setting.tsx +283 -0
  160. package/src/admin/admin-action-confirm.tsx +495 -0
  161. package/src/admin/admin-action-log.tsx +297 -0
  162. package/src/admin/admin-parts.ts +82 -0
  163. package/src/admin/invitations-panel.tsx +516 -0
  164. package/src/admin/reviewer-scope-editor.tsx +234 -0
  165. package/src/admin/role-select.tsx +286 -0
  166. package/src/admin/transfer-ownership-dialog.tsx +172 -0
  167. package/src/admin/user-roster.tsx +573 -0
  168. package/src/auth/auth-errors.ts +165 -8
  169. package/src/auth/forgot-password-form.tsx +21 -5
  170. package/src/auth/register-form.tsx +24 -6
  171. package/src/auth/reset-password-form.tsx +19 -5
  172. package/src/auth/sign-in-form.tsx +207 -35
  173. package/src/auth/verify-email.tsx +59 -8
  174. package/src/components/account-chips.tsx +64 -7
  175. package/src/components/account-settings-labels.ts +15 -1
  176. package/src/components/account-settings.tsx +199 -23
  177. package/src/hooks/use-anchored-panel.ts +14 -3
  178. package/src/i18n/defaults.ts +22 -0
  179. package/src/i18n/german.ts +241 -5
  180. package/src/i18n/kit-labels.tsx +33 -0
  181. package/src/i18n/locales/es.ts +230 -3
  182. package/src/i18n/locales/fr.ts +232 -0
  183. package/src/i18n/locales/hu.ts +224 -5
  184. package/src/i18n/locales/it.ts +230 -0
  185. package/src/i18n/locales/zh.ts +205 -0
  186. package/src/i18n/review.ts +36 -0
  187. package/src/index.ts +93 -0
@@ -0,0 +1,573 @@
1
+ import { useMemo } from "react";
2
+ import type { ReactNode } from "react";
3
+ import { MoreHorizontal } from "lucide-react";
4
+ import type { LucideIcon } from "lucide-react";
5
+ import { cn } from "../lib/cn";
6
+ import type { DateInput } from "../lib/format";
7
+ import type { PersonName } from "../lib/person-name";
8
+ import { useKitLabels, useKitLocale } from "../i18n/kit-labels";
9
+ import { AccountStateChip, RoleChip, dateColumn } from "../components/account-chips";
10
+ import type { AccountState, RoleVocabulary } from "../components/account-chips";
11
+ import type { ChipTone } from "../components/chip";
12
+ import type { DataTableColumn } from "../components/data-table";
13
+ import { encodeSorts } from "../components/data-table-sort";
14
+ import type { SortState } from "../components/data-table-sort";
15
+ import { Popover } from "../components/popover";
16
+ import { Button, IconButton } from "../components/ui";
17
+ import { UserAvatar } from "../components/user-avatar";
18
+ import { personLabel } from "./admin-parts";
19
+ import { RoleSelect } from "./role-select";
20
+ import type { RoleLock } from "./role-select";
21
+
22
+ /**
23
+ * The admin's user list (docs/user-admin-harmonization.md §3): a column preset for the
24
+ * kit's `DataTable`, not a table of its own.
25
+ *
26
+ * keksdose built its roster by hand (1150 lines, its own Badge), Kurvenschmiede on the
27
+ * kit `DataTable` with the 0.18 chips, kastlan as a settings page. What the three share
28
+ * is the row — name over address, a role, the account's states, created, last login, the
29
+ * app's own columns, and a handful of actions — so that is what the kit draws, and the
30
+ * table, its paging, its sort and its filters stay the app's `DataTable` wiring:
31
+ *
32
+ * ```tsx
33
+ * const columns = useUserRosterColumns<AdminUserRow, Role>({ roles: ROLES, actions, extra });
34
+ * <DataTable rows={page.users} columns={columns} rowKey={(r) => r.id}
35
+ * serverPagination={{ page, pageSize, total: page.total, onPageChange }}
36
+ * sorts={sorts} onSortsChange={setSorts} />
37
+ * // GET /admin/users?sort=${userRosterSort(sorts)}&…
38
+ * ```
39
+ *
40
+ * The column keys ARE the server's sort keys (§3.1): `name`, `email`, `role`, `created`,
41
+ * `last_login` — so {@link userRosterSort} turns the table's sort state into the query
42
+ * as it is. Phone cards come from the same columns: the identity is the card's headline,
43
+ * the role, states, last login and the actions are its fields, created is left off.
44
+ */
45
+
46
+ /* ── Rows and states ────────────────────────────────────────────────────────── */
47
+
48
+ /**
49
+ * The fields of the contract's `AdminUserRow` the preset reads (§3.2, the auth
50
+ * contract's `UserResponse` core). An app's row has more — its `extra` — and the
51
+ * preset passes the whole row to every callback.
52
+ */
53
+ export interface UserRosterRow extends AdminUserStateFields {
54
+ id: string | number;
55
+ email: string;
56
+ first_name?: string | null;
57
+ last_name?: string | null;
58
+ /** The derived whole name — only the fallback when both parts are blank. */
59
+ display_name?: string | null;
60
+ /** keksdose, Kurvenschmiede: one role. */
61
+ role?: string | null;
62
+ /** kastlan: the account's roles in the current company. Wins over `role`. */
63
+ roles?: readonly string[] | null;
64
+ created_at?: DateInput;
65
+ /** Account-wide; kastlan's comes from its session rows (§3.2). */
66
+ last_login_at?: DateInput;
67
+ }
68
+
69
+ /** The state fields of the contract's row that {@link adminUserStates} maps (§3.2). */
70
+ export interface AdminUserStateFields {
71
+ is_active?: boolean;
72
+ email_verified?: boolean;
73
+ password_change_required_at?: string | null;
74
+ /** `after_days` mode: the day the account is erased (§6.4). */
75
+ deletion_scheduled_at?: string | null;
76
+ /** When the user asked. The only deletion field in kastlan's `operator` mode, where
77
+ * nothing is scheduled. */
78
+ deletion_requested_at?: string | null;
79
+ }
80
+
81
+ /** One state chip of a row: an {@link AccountState}, or one with its `date` (the
82
+ * `deletion` day), a `tone` or the app's own words. */
83
+ export type RosterState =
84
+ | AccountState
85
+ | { state: AccountState; date?: DateInput; tone?: ChipTone; label?: ReactNode };
86
+
87
+ /**
88
+ * The contract's row as state chips (§3.2: "map 1:1 to the kit's AccountStateChip"):
89
+ *
90
+ * - marked for deletion → `deletion` with the scheduled day (none in `operator` mode),
91
+ * IN PLACE of `inactive` — such an account is always deactivated (§2.1);
92
+ * - else `active` / `inactive` from `is_active`;
93
+ * - `unverified` when `email_verified` is `false` (not when it is missing);
94
+ * - `passwordChange` while `password_change_required_at` is set.
95
+ */
96
+ export function adminUserStates(row: AdminUserStateFields): RosterState[] {
97
+ const out: RosterState[] = [];
98
+ if (row.deletion_scheduled_at || row.deletion_requested_at) {
99
+ out.push({ state: "deletion", date: row.deletion_scheduled_at ?? null });
100
+ } else if (row.is_active !== undefined) {
101
+ out.push(row.is_active ? "active" : "inactive");
102
+ }
103
+ if (row.email_verified === false) out.push("unverified");
104
+ if (row.password_change_required_at) out.push("passwordChange");
105
+ return out;
106
+ }
107
+
108
+ /** The server's sort keys, which are the preset's column keys (§3.1). */
109
+ export const USER_ROSTER_SORT_KEYS = ["name", "email", "role", "created", "last_login"] as const;
110
+ export type UserRosterSortKey = (typeof USER_ROSTER_SORT_KEYS)[number];
111
+
112
+ /**
113
+ * The table's sort state as the `sort` query parameter of `GET /admin/users` (§3.1), in
114
+ * the DataTable's own encoding ({@link encodeSorts}: `"last_login.desc"`), which
115
+ * server-kit 0.4 reads beside the `-key` form. Only the first criterion on one of the
116
+ * server's keys: an app's own column (`owned`) is the client's to sort, and the query
117
+ * takes one key — a shift-clicked second criterion is not sent. `undefined` when nothing
118
+ * the server knows is sorted, so its default order applies.
119
+ */
120
+ export function userRosterSort(sorts: readonly SortState[]): string | undefined {
121
+ const first = sorts.find((s) => (USER_ROSTER_SORT_KEYS as readonly string[]).includes(s.key));
122
+ return first ? (encodeSorts([first]) ?? undefined) : undefined;
123
+ }
124
+
125
+ /* ── Labels ─────────────────────────────────────────────────────────────────── */
126
+
127
+ /** The `userRoster` namespace: the preset's headers and the action menu's words. */
128
+ export interface UserRosterLabels {
129
+ /** The identity column — the name with the address under it. */
130
+ name: string;
131
+ /** The separate address column (`emailColumn`). */
132
+ email: string;
133
+ role: string;
134
+ state: string;
135
+ created: string;
136
+ lastLogin: string;
137
+ /** A last login that never happened. */
138
+ never: string;
139
+ /** The actions column's (hidden) header. */
140
+ actions: string;
141
+ /** The action menu's button and panel — "Actions for Ada Example". */
142
+ actionsFor: (name: string) => string;
143
+ }
144
+
145
+ export const DEFAULT_USER_ROSTER_LABELS: UserRosterLabels = {
146
+ name: "Name",
147
+ email: "Email",
148
+ role: "Role",
149
+ state: "State",
150
+ created: "Created",
151
+ lastLogin: "Last login",
152
+ never: "Never",
153
+ actions: "Actions",
154
+ actionsFor: (name) => `Actions for ${name}`,
155
+ };
156
+
157
+ /* ── UserIdentityCell ───────────────────────────────────────────────────────── */
158
+
159
+ export interface UserIdentityCellProps {
160
+ /** First and last name (auth §3.2), shown in the READER's order. */
161
+ person?: PersonName | null;
162
+ /** A whole name, for an API that still sends `display_name` only. */
163
+ name?: string | null;
164
+ email?: string | null;
165
+ /** The initials avatar before the name. Default true. */
166
+ avatar?: boolean;
167
+ /** After the name, on its line — a "You" chip, a demo mark. */
168
+ badge?: ReactNode;
169
+ /** Over the provider's locale. */
170
+ locale?: string;
171
+ className?: string;
172
+ }
173
+
174
+ /**
175
+ * Who an account is, in one cell (§3.3): the initials avatar, the name in the reader's
176
+ * order ({@link formatPersonName} — "Example Ada" in Hungarian) and the address under it
177
+ * — the cell both rosters drew by hand. An account with no name yet (a migrated row
178
+ * before `CompleteNameDialog`, an invitee) shows its address once, as the name.
179
+ *
180
+ * Both lines carry `data-private`, so keksdose's demo blur reaches them.
181
+ */
182
+ export function UserIdentityCell({
183
+ person,
184
+ name,
185
+ email,
186
+ avatar = true,
187
+ badge,
188
+ locale: localeProp,
189
+ className,
190
+ }: UserIdentityCellProps) {
191
+ const locale = useKitLocale(localeProp);
192
+ const named = personLabel({ first: person?.first, last: person?.last, name }, locale);
193
+ const address = (email ?? "").trim();
194
+ return (
195
+ <div className={cn("flex min-w-0 items-center gap-2.5", className)}>
196
+ {avatar && <UserAvatar person={person} name={name} email={email} size="sm" />}
197
+ <div className="min-w-0">
198
+ <div className="flex min-w-0 items-center gap-1.5">
199
+ <span data-private className="truncate font-medium text-[var(--text-primary)]">
200
+ {named || address}
201
+ </span>
202
+ {badge}
203
+ </div>
204
+ {named && address && (
205
+ <div data-private className="truncate text-xs text-[var(--text-muted)]">
206
+ {address}
207
+ </div>
208
+ )}
209
+ </div>
210
+ </div>
211
+ );
212
+ }
213
+
214
+ /* ── The row's actions ──────────────────────────────────────────────────────── */
215
+
216
+ /** One entry of a row's action menu (§4). */
217
+ export interface UserRowAction {
218
+ /** React key. Default: the label. */
219
+ key?: string;
220
+ label: string;
221
+ /** Runs it — usually opens `AdminActionConfirm` with the level the server states. */
222
+ onSelect: () => void;
223
+ icon?: LucideIcon;
224
+ /** `danger` for deactivate, transfer, erase. */
225
+ tone?: "default" | "danger";
226
+ /** Why it is not available for this row ("You can’t deactivate yourself"). The entry
227
+ * stays in the menu, focusable, and says so — an action that silently vanished
228
+ * would leave the admin looking for it. */
229
+ disabledReason?: ReactNode;
230
+ /** Leave it out for this row. */
231
+ hidden?: boolean;
232
+ }
233
+
234
+ /** What `actions(row)` may return: entries, and `false` / `null` for the ones a
235
+ * condition left out (`row.is_active && {…}`). */
236
+ export type UserRowActionList = readonly (UserRowAction | false | null | undefined)[];
237
+
238
+ export interface UserRowActionsProps {
239
+ actions: UserRowActionList;
240
+ /** The account's name, for the menu's name — "Actions for Ada Example". */
241
+ name: string;
242
+ labels?: Partial<UserRosterLabels>;
243
+ }
244
+
245
+ /**
246
+ * A row's actions as one "…" button and a menu of them: keksdose had a strip of icon
247
+ * buttons in the expanded row, Kurvenschmiede five text buttons in a cell — neither fits
248
+ * a phone card, and both grow with every action §2.4 adds. The menu is portalled, so a
249
+ * table's scroller cannot clip it; Escape and an outside press close it, and focus goes
250
+ * back to the button, which is where a confirmation dialog then returns it.
251
+ */
252
+ export function UserRowActions({ actions, name, labels: labelsProp }: UserRowActionsProps) {
253
+ const labels = useKitLabels("userRoster", DEFAULT_USER_ROSTER_LABELS, labelsProp);
254
+ const entries = actions.filter((a): a is UserRowAction => Boolean(a) && !(a as UserRowAction).hidden);
255
+ if (entries.length === 0) return null;
256
+ const title = labels.actionsFor(name);
257
+ return (
258
+ <Popover
259
+ width={240}
260
+ aria-label={title}
261
+ className="p-1"
262
+ trigger={({ open, toggle, ref }) => (
263
+ <IconButton
264
+ ref={ref}
265
+ size="xs"
266
+ label={title}
267
+ aria-haspopup="dialog"
268
+ aria-expanded={open}
269
+ stopPropagation
270
+ onClick={toggle}
271
+ >
272
+ <MoreHorizontal />
273
+ </IconButton>
274
+ )}
275
+ >
276
+ {(close) => (
277
+ <ul className="space-y-0.5">
278
+ {entries.map((action) => {
279
+ const Icon = action.icon;
280
+ return (
281
+ <li key={action.key ?? action.label}>
282
+ <Button
283
+ type="button"
284
+ variant="ghost"
285
+ size="sm"
286
+ stretch
287
+ tone={action.tone === "danger" ? "danger" : undefined}
288
+ disabledReason={action.disabledReason}
289
+ className="justify-start"
290
+ onClick={() => {
291
+ close();
292
+ action.onSelect();
293
+ }}
294
+ >
295
+ {Icon && <Icon className="size-4 shrink-0" aria-hidden />}
296
+ {action.label}
297
+ </Button>
298
+ </li>
299
+ );
300
+ })}
301
+ </ul>
302
+ )}
303
+ </Popover>
304
+ );
305
+ }
306
+
307
+ /* ── The preset ─────────────────────────────────────────────────────────────── */
308
+
309
+ /** How a row's role may be changed inline: `true`, or with reasons. */
310
+ export interface RoleEditing<R extends string> {
311
+ /** Why the whole select is locked for this row — `"self"`, `"last_admin"`, or words. */
312
+ disabledReason?: RoleLock;
313
+ /** Why one role cannot be chosen for this row (a string: it goes inside an option). */
314
+ optionDisabledReason?: (role: R) => string | undefined;
315
+ /** The roles that may be chosen. Default: the whole vocabulary. */
316
+ offered?: readonly R[];
317
+ }
318
+
319
+ export interface UserRosterColumnsOptions<T extends UserRosterRow, R extends string = string> {
320
+ /** The app's roles, as `RoleChip` reads them. */
321
+ roles: RoleVocabulary<R>;
322
+ /** The row's state chips. Default {@link adminUserStates}, which reads the contract's
323
+ * fields (`is_active`, `email_verified`, `password_change_required_at`,
324
+ * `deletion_scheduled_at`, `deletion_requested_at`). */
325
+ stateOf?: (row: T) => readonly RosterState[];
326
+ /** The app's own columns — keksdose's plan and key custody, Kurvenschmiede's owned
327
+ * counts — after the dates, before the actions. */
328
+ extra?: readonly DataTableColumn<T>[];
329
+ /** The row's action menu (§4). Left out: no actions column. */
330
+ actions?: (row: T) => UserRowActionList;
331
+ /**
332
+ * Whether this row's role is a select rather than a chip, and with which reasons.
333
+ * Left out, or `false`: a chip. kastlan's several roles are never a select here — they
334
+ * are a "Manage roles" action that opens `RolesEditor`.
335
+ */
336
+ editableRole?: (row: T) => boolean | RoleEditing<R>;
337
+ /** A role was picked in a row's select. The app confirms (`acknowledge`) and sends it. */
338
+ onRoleChange?: (row: T, role: R) => void;
339
+ /** The row's role(s). Default `row.roles ?? row.role`. */
340
+ roleOf?: (row: T) => R | readonly R[] | null | undefined;
341
+ /** A separate, sortable "Email" column (the server's `email` sort key) beside the
342
+ * identity. Default false: the address is under the name already. */
343
+ emailColumn?: boolean;
344
+ /** The words, already resolved. Default English; {@link useUserRosterColumns} reads
345
+ * the provider's `userRoster` namespace. */
346
+ labels?: Partial<UserRosterLabels>;
347
+ }
348
+
349
+ function rolesOf<T extends UserRosterRow, R extends string>(
350
+ row: T,
351
+ roleOf: UserRosterColumnsOptions<T, R>["roleOf"],
352
+ ): R[] {
353
+ const raw = roleOf ? roleOf(row) : ((row.roles ?? row.role) as R | readonly R[] | null | undefined);
354
+ if (raw === null || raw === undefined || raw === "") return [];
355
+ return typeof raw === "string" ? [raw as R] : [...(raw as readonly R[])];
356
+ }
357
+
358
+ /** The row's name in the reader's order — a component, because the order is the
359
+ * READER's and the locale comes from the provider. */
360
+ function RowName<T extends UserRosterRow>({ row, children }: { row: T; children: (name: string) => ReactNode }) {
361
+ const locale = useKitLocale();
362
+ const name = personLabel(
363
+ { first: row.first_name, last: row.last_name, name: row.display_name, email: row.email },
364
+ locale,
365
+ );
366
+ return <>{children(name)}</>;
367
+ }
368
+
369
+ function StateChips({ states }: { states: readonly RosterState[] }) {
370
+ if (states.length === 0) return null;
371
+ return (
372
+ <div className="flex flex-wrap gap-1">
373
+ {states.map((entry) => {
374
+ const spec = typeof entry === "string" ? { state: entry } : entry;
375
+ return (
376
+ <AccountStateChip key={spec.state} state={spec.state} date={spec.date} tone={spec.tone} size="xs">
377
+ {spec.label}
378
+ </AccountStateChip>
379
+ );
380
+ })}
381
+ </div>
382
+ );
383
+ }
384
+
385
+ /**
386
+ * The roster's columns, in the contract's order (§3.3):
387
+ *
388
+ * | key | cell | sort | phone |
389
+ * |---|---|---|---|
390
+ * | `name` | {@link UserIdentityCell} | last, first | the card's headline |
391
+ * | `email` | the address (`emailColumn` only) | address | hidden |
392
+ * | `role` | `RoleChip`(s), or {@link RoleSelect} where `editableRole` | role | field |
393
+ * | `state` | `AccountStateChip`s from `stateOf` | — | field |
394
+ * | `created` | `dateColumn` | instant | hidden |
395
+ * | `last_login` | `dateColumn`, relative, "Never" | instant | field |
396
+ * | …`extra` | the app's | the app's | the app's |
397
+ * | `actions` | {@link UserRowActions} | — | field |
398
+ *
399
+ * Pure: hand it resolved words, or use {@link useUserRosterColumns}. The keys are stable,
400
+ * so an app may drop or move a column (`columns.filter((c) => c.key !== "created")`).
401
+ * Under `serverPagination` the `sortBy`s only make the headers clickable; the app sends
402
+ * the sort ({@link userRosterSort}).
403
+ */
404
+ export function userRosterColumns<T extends UserRosterRow, R extends string = string>({
405
+ roles,
406
+ stateOf = adminUserStates,
407
+ extra = [],
408
+ actions,
409
+ editableRole,
410
+ onRoleChange,
411
+ roleOf,
412
+ emailColumn = false,
413
+ labels: labelsProp,
414
+ }: UserRosterColumnsOptions<T, R>): DataTableColumn<T>[] {
415
+ const labels: UserRosterLabels = { ...DEFAULT_USER_ROSTER_LABELS, ...labelsProp };
416
+ const roleWords = (row: T) =>
417
+ rolesOf(row, roleOf)
418
+ .map((role) => roles[role]?.label ?? role)
419
+ .join(", ");
420
+ const columns: DataTableColumn<T>[] = [
421
+ {
422
+ key: "name",
423
+ header: labels.name,
424
+ cell: (row) => (
425
+ <UserIdentityCell
426
+ person={{ first: row.first_name, last: row.last_name }}
427
+ name={row.display_name}
428
+ email={row.email}
429
+ />
430
+ ),
431
+ // By last name, then first (auth §3.2), as the server sorts `name`.
432
+ sortBy: (row) => `${row.last_name ?? ""} ${row.first_name ?? ""}`.trim().toLocaleLowerCase() || row.email,
433
+ // Either part, in either order, or the address (auth §10.6).
434
+ filterBy: (row) =>
435
+ [row.first_name, row.last_name, row.last_name, row.first_name, row.display_name, row.email]
436
+ .filter(Boolean)
437
+ .join(" "),
438
+ mobilePrimary: true,
439
+ },
440
+ ];
441
+ if (emailColumn) {
442
+ columns.push({
443
+ key: "email",
444
+ header: labels.email,
445
+ className: "whitespace-nowrap",
446
+ cell: (row) => (
447
+ <span data-private className="text-[var(--text-secondary)]">
448
+ {row.email}
449
+ </span>
450
+ ),
451
+ sortBy: (row) => row.email.toLowerCase(),
452
+ filterBy: (row) => row.email,
453
+ mobileHidden: true,
454
+ });
455
+ }
456
+ columns.push(
457
+ {
458
+ key: "role",
459
+ header: labels.role,
460
+ cell: (row) => {
461
+ const held = rolesOf(row, roleOf);
462
+ const editing = held.length <= 1 ? editableRole?.(row) : false;
463
+ if (editing && onRoleChange) {
464
+ const rules: RoleEditing<R> = editing === true ? {} : editing;
465
+ return (
466
+ <RowName row={row}>
467
+ {(name) => (
468
+ <RoleSelect<R>
469
+ size="sm"
470
+ name={name}
471
+ value={held[0] ?? null}
472
+ roles={roles}
473
+ offered={rules.offered}
474
+ disabledReason={rules.disabledReason}
475
+ optionDisabledReason={rules.optionDisabledReason}
476
+ onChange={(role) => onRoleChange(row, role)}
477
+ />
478
+ )}
479
+ </RowName>
480
+ );
481
+ }
482
+ if (held.length === 0) return null;
483
+ return (
484
+ <div className="flex flex-wrap gap-1">
485
+ {held.map((role) => (
486
+ <RoleChip<R> key={role} value={role} roles={roles} size="xs" />
487
+ ))}
488
+ </div>
489
+ );
490
+ },
491
+ sortBy: roleWords,
492
+ filter: {
493
+ type: "select",
494
+ getValue: (row) => rolesOf(row, roleOf)[0] ?? "",
495
+ options: (Object.keys(roles) as R[]).map((value) => ({ value, label: roles[value].label })),
496
+ },
497
+ },
498
+ {
499
+ key: "state",
500
+ header: labels.state,
501
+ cell: (row) => <StateChips states={stateOf(row)} />,
502
+ },
503
+ dateColumn<T>({
504
+ key: "created",
505
+ header: labels.created,
506
+ value: (row) => row.created_at ?? null,
507
+ column: { mobileHidden: true },
508
+ }),
509
+ // How long ago rather than a date — the question is "recently?" — with the exact
510
+ // time in a tooltip (keksdose's last-seen column, Kurvenschmiede's).
511
+ dateColumn<T>({
512
+ key: "last_login",
513
+ header: labels.lastLogin,
514
+ value: (row) => row.last_login_at ?? null,
515
+ display: "relative",
516
+ empty: labels.never,
517
+ }),
518
+ ...extra,
519
+ );
520
+ if (actions) {
521
+ columns.push({
522
+ key: "actions",
523
+ header: <span className="sr-only">{labels.actions}</span>,
524
+ headerText: labels.actions,
525
+ // The caller's own words only: the menu reads the provider's itself, and the
526
+ // English defaults merged in above must not shadow them.
527
+ cell: (row) => (
528
+ <RowName row={row}>
529
+ {(name) => <UserRowActions actions={actions(row)} name={name} labels={labelsProp} />}
530
+ </RowName>
531
+ ),
532
+ className: "w-px whitespace-nowrap text-end",
533
+ headClassName: "w-px",
534
+ // The menu button keeps its own click: a row link must not wrap it.
535
+ noRowLink: true,
536
+ });
537
+ }
538
+ return columns;
539
+ }
540
+
541
+ /**
542
+ * {@link userRosterColumns} with the `userRoster` words from the provider, memoised on
543
+ * the options — pass stable callbacks (`useCallback`) and a module-level vocabulary, or
544
+ * the columns are rebuilt on every render.
545
+ */
546
+ export function useUserRosterColumns<T extends UserRosterRow, R extends string = string>({
547
+ roles,
548
+ stateOf,
549
+ extra,
550
+ actions,
551
+ editableRole,
552
+ onRoleChange,
553
+ roleOf,
554
+ emailColumn,
555
+ labels: labelsProp,
556
+ }: UserRosterColumnsOptions<T, R>): DataTableColumn<T>[] {
557
+ const labels = useKitLabels("userRoster", DEFAULT_USER_ROSTER_LABELS, labelsProp);
558
+ return useMemo(
559
+ () =>
560
+ userRosterColumns<T, R>({
561
+ roles,
562
+ stateOf,
563
+ extra,
564
+ actions,
565
+ editableRole,
566
+ onRoleChange,
567
+ roleOf,
568
+ emailColumn,
569
+ labels,
570
+ }),
571
+ [roles, stateOf, extra, actions, editableRole, onRoleChange, roleOf, emailColumn, labels],
572
+ );
573
+ }