@alepha/ui 0.25.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 (136) hide show
  1. package/README.md +12 -0
  2. package/components.json +20 -0
  3. package/package.json +85 -0
  4. package/src/components/action-error-toaster/action-error-toaster.tsx +70 -0
  5. package/src/components/admin/admin-audits.tsx +247 -0
  6. package/src/components/admin/admin-files.tsx +346 -0
  7. package/src/components/admin/admin-jobs-executions-panel.tsx +235 -0
  8. package/src/components/admin/admin-jobs-status-badge.tsx +33 -0
  9. package/src/components/admin/admin-jobs.tsx +294 -0
  10. package/src/components/admin/admin-keys.tsx +162 -0
  11. package/src/components/admin/admin-notifications.tsx +130 -0
  12. package/src/components/admin/admin-page.tsx +24 -0
  13. package/src/components/admin/admin-parameters.tsx +864 -0
  14. package/src/components/admin/admin-payments.tsx +93 -0
  15. package/src/components/admin/admin-sessions.tsx +174 -0
  16. package/src/components/admin/admin-user-detail-audits-tab.tsx +82 -0
  17. package/src/components/admin/admin-user-detail-identity-aside.tsx +218 -0
  18. package/src/components/admin/admin-user-detail-overview-tab.tsx +87 -0
  19. package/src/components/admin/admin-user-detail-password-dialog.tsx +85 -0
  20. package/src/components/admin/admin-user-detail-password-schema.ts +11 -0
  21. package/src/components/admin/admin-user-detail-profile-schema.ts +19 -0
  22. package/src/components/admin/admin-user-detail-provider-labels.ts +15 -0
  23. package/src/components/admin/admin-user-detail-security-tab.tsx +146 -0
  24. package/src/components/admin/admin-user-detail-sessions-tab.tsx +93 -0
  25. package/src/components/admin/admin-user-detail.tsx +606 -0
  26. package/src/components/admin/admin-users-roles-picker.tsx +126 -0
  27. package/src/components/admin/admin-users-status-filter.tsx +51 -0
  28. package/src/components/admin/admin-users.tsx +518 -0
  29. package/src/components/admin/diff-lines.spec.ts +58 -0
  30. package/src/components/admin/diff-lines.ts +58 -0
  31. package/src/components/admin/parameter-diff-dialog.tsx +119 -0
  32. package/src/components/admin/parameter-history-item.tsx +252 -0
  33. package/src/components/admin/parameter-json-dialog.tsx +93 -0
  34. package/src/components/admin/parameter-save-dialog.tsx +126 -0
  35. package/src/components/admin/use-confirmed-action.tsx +93 -0
  36. package/src/components/alepha-table/__tests__/use-table-selection.browser.spec.tsx +92 -0
  37. package/src/components/alepha-table/alepha-table.tsx +1158 -0
  38. package/src/components/alepha-table/use-table-selection.ts +95 -0
  39. package/src/components/app-shell/app-shell.tsx +568 -0
  40. package/src/components/auth/__tests__/auth-router.spec.ts +52 -0
  41. package/src/components/auth/auth-login.tsx +382 -0
  42. package/src/components/auth/auth-register.tsx +786 -0
  43. package/src/components/auth/auth-reset-password.tsx +349 -0
  44. package/src/components/auth/auth-router.tsx +126 -0
  45. package/src/components/auth/auth-verify-email.tsx +179 -0
  46. package/src/components/auto-form/auto-form.tsx +867 -0
  47. package/src/components/brand-icon/brand-icon.tsx +104 -0
  48. package/src/components/button-dark/button-dark.tsx +78 -0
  49. package/src/components/button-language/button-language.tsx +98 -0
  50. package/src/components/button-theme/button-theme.tsx +148 -0
  51. package/src/components/button-user/button-user.tsx +214 -0
  52. package/src/components/captcha/turnstile-widget.tsx +157 -0
  53. package/src/components/control/control.tsx +735 -0
  54. package/src/components/control-array/control-array.tsx +700 -0
  55. package/src/components/control-base/__tests__/form-field-a11y.browser.spec.tsx +93 -0
  56. package/src/components/control-base/field-i18n.ts +60 -0
  57. package/src/components/control-base/form-field.tsx +275 -0
  58. package/src/components/control-base/grid.tsx +59 -0
  59. package/src/components/control-base/icon-hint.tsx +64 -0
  60. package/src/components/control-date/control-date.tsx +190 -0
  61. package/src/components/control-number/control-number.tsx +136 -0
  62. package/src/components/control-object/control-object.tsx +200 -0
  63. package/src/components/control-select/control-select.tsx +774 -0
  64. package/src/components/control-upload/control-upload.tsx +475 -0
  65. package/src/components/file-image/file-image.tsx +52 -0
  66. package/src/components/language-toggle/language-toggle.tsx +66 -0
  67. package/src/components/markdown-view/markdown-view.css +114 -0
  68. package/src/components/markdown-view/markdown-view.tsx +92 -0
  69. package/src/components/nav-shell/nav-page.tsx +56 -0
  70. package/src/components/nav-shell/nav-shell.tsx +72 -0
  71. package/src/components/nav-shell/nav-tree-util.ts +62 -0
  72. package/src/components/nav-shell/spotlight.tsx +163 -0
  73. package/src/components/nav-shell/use-nav-breadcrumbs.ts +52 -0
  74. package/src/components/nav-shell/use-nav-entries.ts +101 -0
  75. package/src/components/nav-shell/use-nav-tree.ts +61 -0
  76. package/src/components/ui/accordion.tsx +77 -0
  77. package/src/components/ui/alert-dialog.tsx +186 -0
  78. package/src/components/ui/alert.tsx +75 -0
  79. package/src/components/ui/aspect-ratio.tsx +22 -0
  80. package/src/components/ui/avatar.tsx +106 -0
  81. package/src/components/ui/badge.tsx +51 -0
  82. package/src/components/ui/breadcrumb.tsx +121 -0
  83. package/src/components/ui/button-group.tsx +86 -0
  84. package/src/components/ui/button.tsx +83 -0
  85. package/src/components/ui/calendar.tsx +235 -0
  86. package/src/components/ui/card.tsx +102 -0
  87. package/src/components/ui/carousel.tsx +241 -0
  88. package/src/components/ui/chart.tsx +370 -0
  89. package/src/components/ui/checkbox.tsx +27 -0
  90. package/src/components/ui/collapsible.tsx +19 -0
  91. package/src/components/ui/combobox.tsx +298 -0
  92. package/src/components/ui/command.tsx +196 -0
  93. package/src/components/ui/context-menu.tsx +271 -0
  94. package/src/components/ui/dialog.tsx +153 -0
  95. package/src/components/ui/direction.tsx +4 -0
  96. package/src/components/ui/drawer.tsx +130 -0
  97. package/src/components/ui/dropdown-menu.tsx +269 -0
  98. package/src/components/ui/empty.tsx +100 -0
  99. package/src/components/ui/hover-card.tsx +50 -0
  100. package/src/components/ui/input-group.tsx +157 -0
  101. package/src/components/ui/input-otp.tsx +83 -0
  102. package/src/components/ui/input.tsx +19 -0
  103. package/src/components/ui/item.tsx +200 -0
  104. package/src/components/ui/kbd.tsx +26 -0
  105. package/src/components/ui/label.tsx +19 -0
  106. package/src/components/ui/menubar.tsx +283 -0
  107. package/src/components/ui/navigation-menu.tsx +170 -0
  108. package/src/components/ui/pagination.tsx +133 -0
  109. package/src/components/ui/popover.tsx +87 -0
  110. package/src/components/ui/progress.tsx +82 -0
  111. package/src/components/ui/radio-group.tsx +35 -0
  112. package/src/components/ui/resizable.tsx +49 -0
  113. package/src/components/ui/scroll-area.tsx +51 -0
  114. package/src/components/ui/segmented.tsx +232 -0
  115. package/src/components/ui/select.tsx +201 -0
  116. package/src/components/ui/separator.tsx +22 -0
  117. package/src/components/ui/sheet.tsx +133 -0
  118. package/src/components/ui/sidebar.tsx +723 -0
  119. package/src/components/ui/skeleton.tsx +13 -0
  120. package/src/components/ui/slider.tsx +51 -0
  121. package/src/components/ui/sonner.tsx +46 -0
  122. package/src/components/ui/spinner.tsx +15 -0
  123. package/src/components/ui/switch.tsx +29 -0
  124. package/src/components/ui/table.tsx +115 -0
  125. package/src/components/ui/tabs.tsx +79 -0
  126. package/src/components/ui/textarea.tsx +17 -0
  127. package/src/components/ui/toggle-group.tsx +86 -0
  128. package/src/components/ui/toggle.tsx +44 -0
  129. package/src/components/ui/tooltip.tsx +63 -0
  130. package/src/components/use-dialog/use-dialog.tsx +244 -0
  131. package/src/components/use-toast/use-toast.tsx +89 -0
  132. package/src/hooks/use-mobile.ts +21 -0
  133. package/src/lib/__tests__/i18n-fr.spec.ts +72 -0
  134. package/src/lib/i18n-fr.ts +500 -0
  135. package/src/lib/utils.ts +6 -0
  136. package/src/styles.css +129 -0
@@ -0,0 +1,294 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { JobExecutionsPanel } from "@alepha/ui/components/admin/admin-jobs-executions-panel";
6
+ import { AdminPage } from "@alepha/ui/components/admin/admin-page";
7
+ import { AlephaTable } from "@alepha/ui/components/alepha-table/alepha-table";
8
+ import { Control } from "@alepha/ui/components/control/control";
9
+ import { Badge } from "@alepha/ui/components/ui/badge";
10
+ import {
11
+ Sheet,
12
+ SheetContent,
13
+ SheetDescription,
14
+ SheetHeader,
15
+ SheetTitle,
16
+ } from "@alepha/ui/components/ui/sheet";
17
+ import { useToast } from "@alepha/ui/components/use-toast/use-toast";
18
+ import { type Infer, type Page, z } from "alepha";
19
+ import type { AdminJobController, JobRegistration } from "alepha/api/jobs";
20
+ import { useAction, useClient } from "alepha/react";
21
+ import { useI18n } from "alepha/react/i18n";
22
+ import { Play, Search, Timer } from "lucide-react";
23
+ import { useCallback, useState } from "react";
24
+
25
+ const POLL_MS = 30_000;
26
+
27
+ const jobFiltersSchema = z.object({
28
+ search: z.string().optional(),
29
+ type: z.string().optional(),
30
+ priority: z.string().optional(),
31
+ });
32
+ type JobFilters = Infer<typeof jobFiltersSchema>;
33
+
34
+ /**
35
+ * Wrap an in-memory array as a `Page<T>` so it can feed `AlephaTable`'s
36
+ * fetcher without server-side pagination — appropriate for bounded
37
+ * datasets like the job registry (usually <50 entries).
38
+ */
39
+ function asPage<T>(items: T[]): Page<T> {
40
+ return {
41
+ content: items,
42
+ page: {
43
+ number: 0,
44
+ size: items.length,
45
+ offset: 0,
46
+ numberOfElements: items.length,
47
+ totalElements: items.length,
48
+ totalPages: 1,
49
+ isEmpty: items.length === 0,
50
+ isFirst: true,
51
+ isLast: true,
52
+ },
53
+ };
54
+ }
55
+
56
+ function applyJobFilters(
57
+ jobs: JobRegistration[],
58
+ filters?: JobFilters,
59
+ sort?: string,
60
+ ): JobRegistration[] {
61
+ let out = jobs;
62
+ const q = filters?.search?.trim().toLowerCase();
63
+ if (q) {
64
+ out = out.filter(
65
+ (j) =>
66
+ j.name.toLowerCase().includes(q) ||
67
+ (j.description?.toLowerCase().includes(q) ?? false),
68
+ );
69
+ }
70
+ if (filters?.type) out = out.filter((j) => j.type === filters.type);
71
+ if (filters?.priority) {
72
+ out = out.filter((j) => j.priority === filters.priority);
73
+ }
74
+ if (sort) {
75
+ const desc = sort.startsWith("-");
76
+ const field = (desc ? sort.slice(1) : sort) as keyof JobRegistration;
77
+ out = [...out].sort((a, b) => {
78
+ const av = (a as any)[field] ?? "";
79
+ const bv = (b as any)[field] ?? "";
80
+ const cmp = av < bv ? -1 : av > bv ? 1 : 0;
81
+ return desc ? -cmp : cmp;
82
+ });
83
+ }
84
+ return out;
85
+ }
86
+
87
+ export function AdminJobs() {
88
+ const client = useClient<AdminJobController>();
89
+ const { l, tr } = useI18n();
90
+ const toast = useToast();
91
+ const [openJob, setOpenJob] = useState<JobRegistration | null>(null);
92
+
93
+ const fetcher = useCallback(
94
+ async (params: { sort?: string; filters?: JobFilters }) => {
95
+ const jobs = await client.listJobs();
96
+ return asPage(applyJobFilters(jobs, params.filters, params.sort));
97
+ },
98
+ [client],
99
+ );
100
+
101
+ const triggerAction = useAction<[JobRegistration], void>(
102
+ {
103
+ handler: async (job) => {
104
+ await client.triggerJob({ params: { name: job.name }, body: {} });
105
+ toast.success(
106
+ tr("admin.jobs.triggered", {
107
+ default: `Triggered ${job.name}`,
108
+ args: [job.name],
109
+ }),
110
+ );
111
+ },
112
+ },
113
+ [client, toast, tr],
114
+ );
115
+
116
+ const trigger = useCallback(
117
+ async (job: JobRegistration, refresh: () => void) => {
118
+ await triggerAction.run(job);
119
+ refresh();
120
+ },
121
+ [triggerAction.run],
122
+ );
123
+
124
+ return (
125
+ <AdminPage>
126
+ <AlephaTable<JobRegistration>
127
+ className="min-h-0 flex-1"
128
+ persistenceKey="admin.jobs"
129
+ pollMs={POLL_MS}
130
+ rowKey={(j) => j.name}
131
+ fetch={fetcher}
132
+ onRowClick={(j) => setOpenJob(j)}
133
+ filters={{
134
+ schema: jobFiltersSchema,
135
+ render: (form) => (
136
+ <div className="flex items-center gap-2">
137
+ <div className="w-72">
138
+ <Control
139
+ input={form.input.search}
140
+ label=""
141
+ icon={Search}
142
+ placeholder={String(
143
+ tr("admin.jobs.searchPlaceholder", { default: "Search…" }),
144
+ )}
145
+ />
146
+ </div>
147
+ <Control
148
+ input={form.input.type}
149
+ label=""
150
+ clearable
151
+ clearLabel={String(
152
+ tr("admin.jobs.typeAll", { default: "All types" }),
153
+ )}
154
+ triggerClassName="w-36"
155
+ items={[
156
+ { value: "cron", label: "cron" },
157
+ { value: "queue", label: "queue" },
158
+ { value: "direct", label: "direct" },
159
+ ]}
160
+ />
161
+ <Control
162
+ input={form.input.priority}
163
+ label=""
164
+ clearable
165
+ clearLabel={String(
166
+ tr("admin.jobs.priorityAll", { default: "All priorities" }),
167
+ )}
168
+ triggerClassName="w-40"
169
+ items={[
170
+ { value: "critical", label: "critical" },
171
+ { value: "high", label: "high" },
172
+ { value: "normal", label: "normal" },
173
+ { value: "low", label: "low" },
174
+ ]}
175
+ />
176
+ </div>
177
+ ),
178
+ }}
179
+ columns={{
180
+ name: {
181
+ label: tr("admin.jobs.colName", { default: "Name" }),
182
+ sortable: true,
183
+ cell: (j) => (
184
+ <div className="flex min-w-0 flex-col">
185
+ <span className="truncate font-medium">{j.name}</span>
186
+ {j.description && (
187
+ <span className="text-muted-foreground truncate text-xs">
188
+ {j.description}
189
+ </span>
190
+ )}
191
+ </div>
192
+ ),
193
+ },
194
+ type: {
195
+ label: tr("admin.jobs.colType", { default: "Type" }),
196
+ sortable: true,
197
+ cell: (j) => (
198
+ <Badge variant={j.type === "cron" ? "default" : "secondary"}>
199
+ {j.type}
200
+ </Badge>
201
+ ),
202
+ },
203
+ cron: {
204
+ label: tr("admin.jobs.colSchedule", { default: "Schedule" }),
205
+ cell: (j) =>
206
+ j.cron ? (
207
+ <code className="text-xs">{j.cron}</code>
208
+ ) : (
209
+ <span className="text-muted-foreground">—</span>
210
+ ),
211
+ },
212
+ priority: {
213
+ label: tr("admin.jobs.colPriority", { default: "Priority" }),
214
+ sortable: true,
215
+ cell: (j) => <Badge variant="outline">{j.priority}</Badge>,
216
+ },
217
+ lastRun: {
218
+ label: tr("admin.jobs.colLastRun", { default: "Last run" }),
219
+ cell: (j) => (
220
+ <span className="text-muted-foreground text-xs">
221
+ {j.recent.lastRun
222
+ ? String(l(j.recent.lastRun, { date: "fromNow" }))
223
+ : tr("admin.jobs.unknown", { default: "unknown" })}
224
+ </span>
225
+ ),
226
+ },
227
+ ok: {
228
+ label: tr("admin.jobs.colOk", { default: "OK" }),
229
+ align: "right",
230
+ cell: (j) => j.recent.ok,
231
+ },
232
+ errors: {
233
+ label: tr("admin.jobs.colErrors", { default: "Errors" }),
234
+ align: "right",
235
+ cell: (j) => (
236
+ <span
237
+ className={j.recent.error > 0 ? "text-destructive" : undefined}
238
+ >
239
+ {j.recent.error}
240
+ </span>
241
+ ),
242
+ },
243
+ }}
244
+ rowActions={(j) => [
245
+ {
246
+ label: tr("admin.jobs.trigger", { default: "Trigger now" }),
247
+ icon: Play,
248
+ onClick: (_j, { refresh }) => trigger(j, refresh),
249
+ },
250
+ {
251
+ label: tr("admin.jobs.viewExecutions", {
252
+ default: "View executions",
253
+ }),
254
+ icon: Timer,
255
+ onClick: () => setOpenJob(j),
256
+ },
257
+ ]}
258
+ emptyMessage={String(
259
+ tr("admin.jobs.none", { default: "No jobs registered." }),
260
+ )}
261
+ />
262
+
263
+ <Sheet
264
+ open={openJob !== null}
265
+ onOpenChange={(open) => {
266
+ if (!open) setOpenJob(null);
267
+ }}
268
+ >
269
+ <SheetContent
270
+ side="right"
271
+ className="flex w-full flex-col gap-0 data-[side=right]:sm:max-w-[50vw]"
272
+ >
273
+ {openJob && (
274
+ <>
275
+ <SheetHeader>
276
+ <SheetTitle>{openJob.name}</SheetTitle>
277
+ <SheetDescription>
278
+ {tr("admin.jobs.execsDescription", {
279
+ default: "Recent executions for this job.",
280
+ })}
281
+ </SheetDescription>
282
+ </SheetHeader>
283
+ <div className="flex min-h-0 flex-1 flex-col p-4">
284
+ <JobExecutionsPanel jobName={openJob.name} />
285
+ </div>
286
+ </>
287
+ )}
288
+ </SheetContent>
289
+ </Sheet>
290
+ </AdminPage>
291
+ );
292
+ }
293
+
294
+ export default AdminJobs;
@@ -0,0 +1,162 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { AdminPage } from "@alepha/ui/components/admin/admin-page";
6
+ import { useConfirmedAction } from "@alepha/ui/components/admin/use-confirmed-action";
7
+ import { AlephaTable } from "@alepha/ui/components/alepha-table/alepha-table";
8
+ import { Badge } from "@alepha/ui/components/ui/badge";
9
+ import { useDialog } from "@alepha/ui/components/use-dialog/use-dialog";
10
+ import { useToast } from "@alepha/ui/components/use-toast/use-toast";
11
+ import type {
12
+ AdminApiKeyController,
13
+ AdminApiKeyResource,
14
+ } from "alepha/api/keys";
15
+ import { useAction, useClient } from "alepha/react";
16
+ import { useI18n } from "alepha/react/i18n";
17
+ import { Trash2 } from "lucide-react";
18
+ import { useCallback } from "react";
19
+
20
+ export function AdminKeys() {
21
+ const client = useClient<AdminApiKeyController>();
22
+ const toast = useToast();
23
+ const dialog = useDialog();
24
+ const { l, tr } = useI18n();
25
+
26
+ const fetcher = useCallback(
27
+ async (params: { page: number; size: number; sort?: string }) => {
28
+ return client.findApiKeys({ query: params });
29
+ },
30
+ [client],
31
+ );
32
+
33
+ const revoke = useConfirmedAction<[AdminApiKeyResource, () => void]>(
34
+ {
35
+ confirm: (k) => ({
36
+ title: tr("admin.keys.revokeTitle", { default: "Revoke API key" }),
37
+ description: tr("admin.keys.revokeConfirm", {
38
+ default: `Revoke "${k.name}"? Any apps using this key will lose access.`,
39
+ args: [k.name],
40
+ }),
41
+ destructive: true,
42
+ }),
43
+ handler: async (k, refresh) => {
44
+ await client.revokeApiKey({ params: { id: k.id } });
45
+ refresh();
46
+ },
47
+ success: tr("admin.keys.revoked", { default: "API key revoked" }),
48
+ },
49
+ [client, tr],
50
+ );
51
+
52
+ const bulkRevoke = useAction<
53
+ [AdminApiKeyResource[], { clearSelection: () => void; refresh: () => void }]
54
+ >(
55
+ {
56
+ handler: async (items, ctx) => {
57
+ const targets = items.filter((k) => !k.revokedAt);
58
+ if (targets.length === 0) {
59
+ toast.error(
60
+ tr("admin.keys.noneSelected", {
61
+ default: "No active API keys in selection",
62
+ }),
63
+ );
64
+ return;
65
+ }
66
+ const ok = await dialog.confirm({
67
+ title: tr("admin.keys.bulkRevokeTitle", {
68
+ default: "Revoke API keys",
69
+ }),
70
+ description: tr("admin.keys.bulkRevokeConfirm", {
71
+ default: `Revoke ${targets.length} API key(s)? Any apps using these keys will lose access.`,
72
+ args: [String(targets.length)],
73
+ }),
74
+ destructive: true,
75
+ });
76
+ if (!ok) return;
77
+ const res = await client.revokeApiKeys({
78
+ body: { ids: targets.map((k) => k.id) },
79
+ });
80
+ toast.success(
81
+ tr("admin.keys.bulkRevoked", {
82
+ default: `${res.revoked.length} API key(s) revoked`,
83
+ args: [String(res.revoked.length)],
84
+ }),
85
+ );
86
+ ctx.clearSelection();
87
+ ctx.refresh();
88
+ },
89
+ },
90
+ [client, dialog, toast, tr],
91
+ );
92
+
93
+ return (
94
+ <AdminPage>
95
+ <AlephaTable<AdminApiKeyResource>
96
+ className="min-h-0 flex-1"
97
+ persistenceKey="admin.keys"
98
+ fetch={fetcher}
99
+ bulkActions={[
100
+ {
101
+ label: tr("admin.keys.bulkRevoke", {
102
+ default: "Revoke selected",
103
+ }),
104
+ icon: Trash2,
105
+ destructive: true,
106
+ onClick: (items, ctx) => bulkRevoke.run(items, ctx),
107
+ },
108
+ ]}
109
+ columns={{
110
+ name: {
111
+ label: tr("admin.keys.colName", { default: "Name" }),
112
+ cell: (k) => <span className="font-medium">{k.name}</span>,
113
+ },
114
+ tokenPrefix: {
115
+ label: tr("admin.keys.colPrefix", { default: "Prefix" }),
116
+ cell: (k) => (
117
+ <code className="text-xs">{k.tokenPrefix ?? "—"}</code>
118
+ ),
119
+ },
120
+ owner: {
121
+ label: tr("admin.keys.colOwner", { default: "Owner" }),
122
+ cell: (k) => <span className="text-sm">{k.userId ?? "—"}</span>,
123
+ },
124
+ roles: {
125
+ label: tr("admin.keys.colScopes", { default: "Roles" }),
126
+ cell: (k) =>
127
+ Array.isArray(k.roles) && k.roles.length ? (
128
+ <div className="flex flex-wrap gap-1">
129
+ {k.roles.map((s: string) => (
130
+ <Badge key={s} variant="secondary">
131
+ {s}
132
+ </Badge>
133
+ ))}
134
+ </div>
135
+ ) : (
136
+ <span className="text-muted-foreground text-xs">—</span>
137
+ ),
138
+ },
139
+ createdAt: {
140
+ label: tr("admin.keys.colCreated", { default: "Created" }),
141
+ sortable: true,
142
+ cell: (k) => (
143
+ <span className="text-muted-foreground text-xs">
144
+ {String(l(k.createdAt, { date: "fromNow" }))}
145
+ </span>
146
+ ),
147
+ },
148
+ }}
149
+ rowActions={(k) => [
150
+ {
151
+ label: tr("admin.keys.revoke", { default: "Revoke" }),
152
+ icon: Trash2,
153
+ destructive: true,
154
+ onClick: (_k, { refresh }) => revoke.run(k, refresh),
155
+ },
156
+ ]}
157
+ />
158
+ </AdminPage>
159
+ );
160
+ }
161
+
162
+ export default AdminKeys;
@@ -0,0 +1,130 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { AdminPage } from "@alepha/ui/components/admin/admin-page";
6
+ import { useConfirmedAction } from "@alepha/ui/components/admin/use-confirmed-action";
7
+ import { AlephaTable } from "@alepha/ui/components/alepha-table/alepha-table";
8
+ import { Badge } from "@alepha/ui/components/ui/badge";
9
+ import { useToast } from "@alepha/ui/components/use-toast/use-toast";
10
+ import type {
11
+ AdminNotificationController,
12
+ NotificationResource,
13
+ } from "alepha/api/notifications";
14
+ import { useClient } from "alepha/react";
15
+ import { useI18n } from "alepha/react/i18n";
16
+ import { Trash2 } from "lucide-react";
17
+ import { useCallback } from "react";
18
+
19
+ export function AdminNotifications() {
20
+ const client = useClient<AdminNotificationController>();
21
+ const toast = useToast();
22
+ const { l, tr } = useI18n();
23
+
24
+ const fetcher = useCallback(
25
+ async (params: { page: number; size: number; sort?: string }) => {
26
+ return client.findNotifications({ query: params });
27
+ },
28
+ [client],
29
+ );
30
+
31
+ const bulkDelete = useConfirmedAction<
32
+ [
33
+ NotificationResource[],
34
+ { clearSelection: () => void; refresh: () => void },
35
+ ]
36
+ >(
37
+ {
38
+ confirm: (items) => ({
39
+ title: tr("admin.notifications.bulkDeleteTitle", {
40
+ default: "Delete notifications",
41
+ }),
42
+ description: tr("admin.notifications.bulkDeleteConfirm", {
43
+ default: `Delete ${items.length} notification record(s)? This cannot be undone.`,
44
+ args: [String(items.length)],
45
+ }),
46
+ destructive: true,
47
+ }),
48
+ handler: async (items, ctx) => {
49
+ if (items.length === 0) return;
50
+ const res = await client.deleteNotifications({
51
+ body: { ids: items.map((n) => n.id) },
52
+ });
53
+ toast.success(
54
+ tr("admin.notifications.bulkDeleted", {
55
+ default: `${res.deleted.length} notification(s) deleted`,
56
+ args: [String(res.deleted.length)],
57
+ }),
58
+ );
59
+ ctx.clearSelection();
60
+ ctx.refresh();
61
+ },
62
+ },
63
+ [client, toast, tr],
64
+ );
65
+
66
+ return (
67
+ <AdminPage>
68
+ <AlephaTable<NotificationResource>
69
+ className="min-h-0 flex-1"
70
+ persistenceKey="admin.notifications"
71
+ fetch={fetcher}
72
+ bulkActions={[
73
+ {
74
+ label: tr("admin.notifications.bulkDelete", {
75
+ default: "Delete selected",
76
+ }),
77
+ icon: Trash2,
78
+ destructive: true,
79
+ onClick: (items, ctx) => bulkDelete.run(items, ctx),
80
+ },
81
+ ]}
82
+ columns={{
83
+ createdAt: {
84
+ label: tr("admin.notifications.colWhen", { default: "When" }),
85
+ sortable: true,
86
+ cell: (n) => (
87
+ <span className="text-muted-foreground text-xs">
88
+ {String(l(n.createdAt, { date: "fromNow" }))}
89
+ </span>
90
+ ),
91
+ },
92
+ type: {
93
+ label: tr("admin.notifications.colType", { default: "Type" }),
94
+ cell: (n) => <Badge variant="secondary">{n.type ?? "—"}</Badge>,
95
+ },
96
+ contact: {
97
+ label: tr("admin.notifications.colRecipient", {
98
+ default: "Recipient",
99
+ }),
100
+ cell: (n) => <span className="text-sm">{n.contact ?? "—"}</span>,
101
+ },
102
+ template: {
103
+ label: tr("admin.notifications.colTemplate", {
104
+ default: "Template",
105
+ }),
106
+ cell: (n) => <span className="text-sm">{n.template ?? "—"}</span>,
107
+ },
108
+ status: {
109
+ label: tr("admin.notifications.colStatus", { default: "Status" }),
110
+ cell: (n) => {
111
+ // `job_executions.status` — the outbox never wrote
112
+ // "sent"/"delivered"/"failed", so every badge used to fall
113
+ // through to the neutral outline variant.
114
+ const s = n.status ?? "pending";
115
+ const variant =
116
+ s === "ok"
117
+ ? "default"
118
+ : s === "error"
119
+ ? "destructive"
120
+ : "outline";
121
+ return <Badge variant={variant as never}>{s}</Badge>;
122
+ },
123
+ },
124
+ }}
125
+ />
126
+ </AdminPage>
127
+ );
128
+ }
129
+
130
+ export default AdminNotifications;
@@ -0,0 +1,24 @@
1
+ import { cn } from "@alepha/ui/lib/utils";
2
+ import type { ReactNode } from "react";
3
+
4
+ export interface AdminPageProps {
5
+ children: ReactNode;
6
+ /**
7
+ * Extra classes merged onto the standard page shell. Most pages won't need
8
+ * this — the default `p-6 flex min-h-0 flex-1 flex-col gap-3` shell is what
9
+ * the admin list/detail pages share.
10
+ */
11
+ className?: string;
12
+ }
13
+
14
+ /**
15
+ * Standard admin page shell — the `p-6`, column-flex, scroll-bounding wrapper
16
+ * that every admin page used to copy-paste.
17
+ */
18
+ export const AdminPage = (props: AdminPageProps) => (
19
+ <div
20
+ className={cn("flex min-h-0 flex-1 flex-col gap-3 p-6", props.className)}
21
+ >
22
+ {props.children}
23
+ </div>
24
+ );