@alepha/ui 0.25.0 → 0.25.2

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 (104) hide show
  1. package/package.json +4 -5
  2. package/src/components/account/__tests__/account-router.spec.ts +201 -0
  3. package/src/components/account/account-connections.tsx +103 -0
  4. package/src/components/account/account-delete-dialog.tsx +184 -0
  5. package/src/components/account/account-header.tsx +57 -0
  6. package/src/components/account/account-keys.tsx +221 -0
  7. package/src/components/account/account-layout.tsx +63 -0
  8. package/src/components/account/account-password-dialog.tsx +152 -0
  9. package/src/components/account/account-profile.tsx +229 -0
  10. package/src/components/account/account-router-options.tsx +74 -0
  11. package/src/components/account/account-router-page.tsx +69 -0
  12. package/src/components/account/account-router.tsx +214 -0
  13. package/src/components/account/account-security.tsx +150 -0
  14. package/src/components/account/account-sessions.tsx +140 -0
  15. package/src/components/admin/__tests__/admin-keys-token-dialog.browser.spec.tsx +62 -0
  16. package/src/components/admin/__tests__/admin-layout.browser.spec.tsx +82 -0
  17. package/src/components/admin/__tests__/admin-router-page.spec.ts +54 -0
  18. package/src/components/admin/__tests__/admin-router.spec.ts +208 -0
  19. package/src/components/admin/__tests__/admin-user-cell.browser.spec.tsx +99 -0
  20. package/src/components/admin/__tests__/admin-user-detail.spec.ts +29 -0
  21. package/src/components/admin/admin-analytics-query-panel.tsx +149 -0
  22. package/src/components/admin/admin-analytics-results.tsx +95 -0
  23. package/src/components/admin/admin-analytics.tsx +104 -0
  24. package/src/components/admin/admin-audits.tsx +12 -15
  25. package/src/components/admin/admin-files.tsx +10 -18
  26. package/src/components/admin/admin-jobs-executions-panel.tsx +2 -1
  27. package/src/components/admin/admin-jobs.tsx +3 -1
  28. package/src/components/admin/admin-keys-token-dialog.tsx +123 -0
  29. package/src/components/admin/admin-keys.tsx +54 -3
  30. package/src/components/admin/admin-layout.tsx +107 -0
  31. package/src/components/admin/admin-payments.tsx +4 -5
  32. package/src/components/admin/admin-router-options.tsx +130 -0
  33. package/src/components/admin/admin-router-page.tsx +74 -0
  34. package/src/components/admin/admin-router.tsx +379 -0
  35. package/src/components/admin/admin-sessions.tsx +2 -16
  36. package/src/components/admin/admin-user-cell.tsx +70 -0
  37. package/src/components/admin/admin-user-detail-overview-tab.tsx +28 -0
  38. package/src/components/admin/admin-user-detail-profile-policy.spec.ts +146 -0
  39. package/src/components/admin/admin-user-detail-profile-policy.ts +147 -0
  40. package/src/components/admin/admin-user-detail-security-tab.tsx +1 -1
  41. package/src/components/admin/admin-user-detail.tsx +76 -32
  42. package/src/components/admin/admin-users-status-filter.tsx +2 -0
  43. package/src/components/admin/admin-workflows-execution-sheet.tsx +277 -0
  44. package/src/components/admin/admin-workflows-executions-panel.tsx +170 -0
  45. package/src/components/admin/admin-workflows-status-badge.tsx +40 -0
  46. package/src/components/admin/admin-workflows.tsx +207 -0
  47. package/src/components/alepha-table/alepha-table.tsx +73 -17
  48. package/src/components/app-actions/__tests__/app-actions.browser.spec.tsx +79 -0
  49. package/src/components/app-actions/app-actions.tsx +113 -0
  50. package/src/components/app-shell/app-shell.tsx +122 -0
  51. package/src/components/auth/auth-reset-password.tsx +81 -8
  52. package/src/components/button-user/button-user.tsx +58 -1
  53. package/src/components/control/control.tsx +14 -71
  54. package/src/components/control-password/control-password.tsx +87 -0
  55. package/src/components/control-select/__tests__/control-select-clear-label.browser.spec.tsx +101 -0
  56. package/src/components/control-select/__tests__/control-select-deselect.browser.spec.tsx +126 -0
  57. package/src/components/control-select/__tests__/control-select-searchable.browser.spec.tsx +142 -0
  58. package/src/components/control-select/control-select.tsx +133 -111
  59. package/src/components/control-upload/control-upload.tsx +27 -1
  60. package/src/components/markdown-view/markdown-view.tsx +6 -0
  61. package/src/components/nav-shell/nav-page.tsx +3 -3
  62. package/src/components/settings/__tests__/settings-nav.browser.spec.tsx +123 -0
  63. package/src/components/settings/__tests__/settings-section.browser.spec.tsx +130 -0
  64. package/src/components/settings/settings-danger-section.tsx +59 -0
  65. package/src/components/settings/settings-layout.tsx +56 -0
  66. package/src/components/settings/settings-nav.tsx +131 -0
  67. package/src/components/settings/settings-row.tsx +81 -0
  68. package/src/components/settings/settings-section.tsx +64 -0
  69. package/src/components/ui/alert-dialog.tsx +1 -1
  70. package/src/components/ui/avatar.tsx +2 -0
  71. package/src/components/ui/breadcrumb.tsx +1 -1
  72. package/src/components/ui/calendar.tsx +11 -6
  73. package/src/components/ui/card.tsx +5 -5
  74. package/src/components/ui/carousel.tsx +4 -4
  75. package/src/components/ui/chart.tsx +2 -0
  76. package/src/components/ui/collapsible.tsx +2 -0
  77. package/src/components/ui/combobox.tsx +3 -1
  78. package/src/components/ui/context-menu.tsx +3 -3
  79. package/src/components/ui/dialog.tsx +6 -1
  80. package/src/components/ui/direction.tsx +2 -0
  81. package/src/components/ui/drawer.tsx +134 -37
  82. package/src/components/ui/dropdown-menu.tsx +13 -3
  83. package/src/components/ui/empty.tsx +4 -1
  84. package/src/components/ui/input-otp.tsx +2 -0
  85. package/src/components/ui/menubar.tsx +2 -2
  86. package/src/components/ui/pagination.tsx +2 -2
  87. package/src/components/ui/popover.tsx +2 -0
  88. package/src/components/ui/radio-group.tsx +2 -0
  89. package/src/components/ui/scroll-area.tsx +2 -0
  90. package/src/components/ui/select.tsx +1 -1
  91. package/src/components/ui/separator.tsx +2 -0
  92. package/src/components/ui/sheet.tsx +4 -1
  93. package/src/components/ui/sidebar.tsx +1 -1
  94. package/src/components/ui/spinner.tsx +1 -0
  95. package/src/components/ui/switch.tsx +2 -0
  96. package/src/components/ui/tabs.tsx +2 -0
  97. package/src/components/ui/toggle-group.tsx +2 -0
  98. package/src/components/ui/tooltip.tsx +2 -0
  99. package/src/lib/__tests__/rehype-safe-img.spec.ts +121 -0
  100. package/src/lib/i18n-fr.ts +68 -0
  101. package/src/lib/rehype-safe-img.ts +150 -0
  102. package/src/lib/resize-image.ts +135 -0
  103. package/src/styles.css +126 -1
  104. /package/src/components/{admin/admin-user-detail-provider-labels.ts → auth/provider-labels.ts} +0 -0
@@ -0,0 +1,95 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Badge } from "@alepha/ui/components/ui/badge";
6
+ import {
7
+ Table,
8
+ TableBody,
9
+ TableCell,
10
+ TableHead,
11
+ TableHeader,
12
+ TableRow,
13
+ } from "@alepha/ui/components/ui/table";
14
+ import type {
15
+ AdminAnalyticsResult,
16
+ AdminDatasetDescriptor,
17
+ } from "alepha/api/analytics";
18
+ import { useI18n } from "alepha/react/i18n";
19
+
20
+ export interface AdminAnalyticsResultsProps {
21
+ dataset: AdminDatasetDescriptor;
22
+ result: AdminAnalyticsResult;
23
+ }
24
+
25
+ /**
26
+ * Aggregate rows as a plain table, with the sampling-honesty badge the
27
+ * result schema carries: `estimated` with `sampleInterval > 1` means the
28
+ * numbers are reconstructed; `estimated` with an interval of 1 means the
29
+ * backend samples but did not in this window.
30
+ */
31
+ export function AdminAnalyticsResults(props: AdminAnalyticsResultsProps) {
32
+ const { tr } = useI18n();
33
+ const columns = Object.keys(props.result.rows[0] ?? {});
34
+ const sampleInterval = props.result.sampleInterval ?? 1;
35
+
36
+ return (
37
+ <div className="flex min-h-0 flex-1 flex-col gap-2">
38
+ <div className="flex items-center gap-2">
39
+ <span className="text-muted-foreground text-sm">
40
+ {tr("admin.analytics.rowCount", {
41
+ default: "$1 rows",
42
+ args: [String(props.result.rows.length)],
43
+ })}
44
+ </span>
45
+ {props.result.estimated && sampleInterval > 1 && (
46
+ <Badge variant="outline">
47
+ {tr("admin.analytics.estimated", {
48
+ default: "Estimated (sampled ×$1)",
49
+ args: [String(sampleInterval)],
50
+ })}
51
+ </Badge>
52
+ )}
53
+ {props.result.estimated && sampleInterval <= 1 && (
54
+ <Badge variant="outline">
55
+ {tr("admin.analytics.exactSample", {
56
+ default: "Exact (no sampling in window)",
57
+ })}
58
+ </Badge>
59
+ )}
60
+ </div>
61
+ {props.result.rows.length === 0 ? (
62
+ <div className="text-muted-foreground py-8 text-center text-sm">
63
+ {tr("admin.analytics.empty", {
64
+ default: "No data for this query.",
65
+ })}
66
+ </div>
67
+ ) : (
68
+ <div className="overflow-auto rounded-md border">
69
+ <Table>
70
+ <TableHeader>
71
+ <TableRow>
72
+ {columns.map((column) => (
73
+ <TableHead key={column}>{column}</TableHead>
74
+ ))}
75
+ </TableRow>
76
+ </TableHeader>
77
+ <TableBody>
78
+ {props.result.rows.map((row, index) => (
79
+ <TableRow key={`${index}-${String(row[columns[0]] ?? "")}`}>
80
+ {columns.map((column) => (
81
+ <TableCell key={column} className="tabular-nums">
82
+ {String(row[column] ?? "—")}
83
+ </TableCell>
84
+ ))}
85
+ </TableRow>
86
+ ))}
87
+ </TableBody>
88
+ </Table>
89
+ </div>
90
+ )}
91
+ </div>
92
+ );
93
+ }
94
+
95
+ export default AdminAnalyticsResults;
@@ -0,0 +1,104 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { AdminAnalyticsQueryPanel } from "@alepha/ui/components/admin/admin-analytics-query-panel";
6
+ import { AdminAnalyticsResults } from "@alepha/ui/components/admin/admin-analytics-results";
7
+ import { AdminPage } from "@alepha/ui/components/admin/admin-page";
8
+ import {
9
+ Select,
10
+ SelectContent,
11
+ SelectItem,
12
+ SelectTrigger,
13
+ SelectValue,
14
+ } from "@alepha/ui/components/ui/select";
15
+ import type {
16
+ AdminAnalyticsController,
17
+ AdminAnalyticsResult,
18
+ AdminDatasetDescriptor,
19
+ } from "alepha/api/analytics";
20
+ import { useClient } from "alepha/react";
21
+ import { useI18n } from "alepha/react/i18n";
22
+ import { useEffect, useState } from "react";
23
+
24
+ /**
25
+ * Generic analytics explorer over every `$analytics()` dataset the app
26
+ * declares. Datasets, dimensions and measures all come from the admin API's
27
+ * JSON-Schema descriptors — nothing here is app-specific.
28
+ */
29
+ export function AdminAnalytics() {
30
+ const client = useClient<AdminAnalyticsController>();
31
+ const { tr } = useI18n();
32
+ const [datasets, setDatasets] = useState<AdminDatasetDescriptor[]>();
33
+ const [selected, setSelected] = useState<string>();
34
+ const [result, setResult] = useState<AdminAnalyticsResult>();
35
+
36
+ useEffect(() => {
37
+ client.listDatasets().then((list) => {
38
+ setDatasets(list);
39
+ setSelected((current) => current ?? list[0]?.name);
40
+ });
41
+ }, [client]);
42
+
43
+ const dataset = datasets?.find((d) => d.name === selected);
44
+
45
+ return (
46
+ <AdminPage>
47
+ <div className="flex items-center gap-3">
48
+ <Select
49
+ // `?? null`, never `undefined`: an initial `undefined` mounts the
50
+ // root uncontrolled, and the later programmatic selection no longer
51
+ // drives the trigger. `null` is Base UI's controlled "nothing
52
+ // selected".
53
+ value={selected ?? null}
54
+ // Base UI resolves the trigger label from `items`: without it, a
55
+ // programmatically selected value renders as the placeholder until
56
+ // the popup has been opened once, because the list items live in an
57
+ // unmounted popup.
58
+ items={(datasets ?? []).map((d) => ({
59
+ value: d.name,
60
+ label: d.name,
61
+ }))}
62
+ onValueChange={(name) => {
63
+ setSelected(name ?? undefined);
64
+ setResult(undefined);
65
+ }}
66
+ >
67
+ <SelectTrigger className="w-64">
68
+ <SelectValue
69
+ placeholder={tr("admin.analytics.pickDataset", {
70
+ default: "Pick a dataset",
71
+ })}
72
+ />
73
+ </SelectTrigger>
74
+ <SelectContent>
75
+ {(datasets ?? []).map((d) => (
76
+ <SelectItem key={d.name} value={d.name}>
77
+ {d.name}
78
+ </SelectItem>
79
+ ))}
80
+ </SelectContent>
81
+ </Select>
82
+ {datasets?.length === 0 && (
83
+ <span className="text-muted-foreground text-sm">
84
+ {tr("admin.analytics.noDatasets", {
85
+ default: "No analytics datasets are declared in this app.",
86
+ })}
87
+ </span>
88
+ )}
89
+ </div>
90
+ {dataset && (
91
+ <AdminAnalyticsQueryPanel
92
+ key={dataset.name}
93
+ dataset={dataset}
94
+ onResult={setResult}
95
+ />
96
+ )}
97
+ {dataset && result && (
98
+ <AdminAnalyticsResults dataset={dataset} result={result} />
99
+ )}
100
+ </AdminPage>
101
+ );
102
+ }
103
+
104
+ export default AdminAnalytics;
@@ -3,6 +3,7 @@ import * as React from "react";
3
3
  void React;
4
4
 
5
5
  import { AdminPage } from "@alepha/ui/components/admin/admin-page";
6
+ import { AdminUserCell } from "@alepha/ui/components/admin/admin-user-cell";
6
7
  import { useConfirmedAction } from "@alepha/ui/components/admin/use-confirmed-action";
7
8
  import { AlephaTable } from "@alepha/ui/components/alepha-table/alepha-table";
8
9
  import { Control } from "@alepha/ui/components/control/control";
@@ -13,7 +14,7 @@ import type { AdminAuditController, AuditEntity } from "alepha/api/audits";
13
14
  import { useClient } from "alepha/react";
14
15
  import { useI18n } from "alepha/react/i18n";
15
16
  import { useRouter } from "alepha/react/router";
16
- import { SlidersHorizontal, Trash2, User } from "lucide-react";
17
+ import { CircleDot, SlidersHorizontal, Trash2, User, Zap } from "lucide-react";
17
18
  import { useCallback, useEffect, useState } from "react";
18
19
 
19
20
  const auditFiltersSchema = z.object({
@@ -134,6 +135,7 @@ export function AdminAudits() {
134
135
  input={form.input.status}
135
136
  label=""
136
137
  clearable
138
+ icon={CircleDot}
137
139
  clearLabel={String(
138
140
  tr("admin.audits.statusAll", { default: "All status" }),
139
141
  )}
@@ -155,6 +157,7 @@ export function AdminAudits() {
155
157
  input={form.input.action}
156
158
  label=""
157
159
  clearable
160
+ icon={Zap}
158
161
  clearLabel={String(
159
162
  tr("admin.audits.actionAll", { default: "All actions" }),
160
163
  )}
@@ -213,20 +216,14 @@ export function AdminAudits() {
213
216
  },
214
217
  actor: {
215
218
  label: tr("admin.audits.colActor", { default: "Actor" }),
216
- cell: (a) =>
217
- a.userId ? (
218
- <button
219
- type="button"
220
- onClick={() =>
221
- router.push(`/admin/users/${a.userId}` as never)
222
- }
223
- className="hover:text-primary truncate text-left text-sm underline-offset-2 hover:underline"
224
- >
225
- {a.userEmail ?? a.userId}
226
- </button>
227
- ) : (
228
- <span className="text-sm">{a.userEmail ?? "—"}</span>
229
- ),
219
+ /*
220
+ * Audit rows carry a write-time `userEmail` snapshot rather than
221
+ * a live join — the actor's address as it was when the action
222
+ * happened is itself audit data.
223
+ */
224
+ cell: (a) => (
225
+ <AdminUserCell userId={a.userId} fallbackLabel={a.userEmail} />
226
+ ),
230
227
  },
231
228
  status: {
232
229
  label: tr("admin.audits.colStatus", { default: "Status" }),
@@ -3,6 +3,7 @@ import * as React from "react";
3
3
  void React;
4
4
 
5
5
  import { AdminPage } from "@alepha/ui/components/admin/admin-page";
6
+ import { AdminUserCell } from "@alepha/ui/components/admin/admin-user-cell";
6
7
  import { useConfirmedAction } from "@alepha/ui/components/admin/use-confirmed-action";
7
8
  import { AlephaTable } from "@alepha/ui/components/alepha-table/alepha-table";
8
9
  import { Control } from "@alepha/ui/components/control/control";
@@ -21,7 +22,7 @@ import type {
21
22
  } from "alepha/api/files";
22
23
  import { useAction, useClient, useQuery } from "alepha/react";
23
24
  import { useI18n } from "alepha/react/i18n";
24
- import { Download, Search, Trash2, Upload } from "lucide-react";
25
+ import { Container, Download, Search, Trash2, Upload } from "lucide-react";
25
26
  import {
26
27
  type ChangeEvent,
27
28
  useCallback,
@@ -219,6 +220,7 @@ export function AdminFiles() {
219
220
  input={form.input.bucket}
220
221
  label=""
221
222
  clearable
223
+ icon={Container}
222
224
  clearLabel={String(
223
225
  tr("admin.files.allBuckets", { default: "All buckets" }),
224
226
  )}
@@ -272,23 +274,13 @@ export function AdminFiles() {
272
274
  },
273
275
  user: {
274
276
  label: tr("admin.files.colUser", { default: "Uploaded by" }),
275
- cell: (f) => {
276
- const label =
277
- f.user?.email ||
278
- f.user?.username ||
279
- [f.user?.firstName, f.user?.lastName]
280
- .filter(Boolean)
281
- .join(" ") ||
282
- f.creatorName ||
283
- null;
284
- return label ? (
285
- <span className="truncate">{label}</span>
286
- ) : (
287
- <span className="text-muted-foreground font-mono text-xs">
288
- {f.creator?.slice(0, 8) ?? "—"}
289
- </span>
290
- );
291
- },
277
+ cell: (f) => (
278
+ <AdminUserCell
279
+ userId={f.creator}
280
+ user={f.user}
281
+ fallbackLabel={f.creatorName}
282
+ />
283
+ ),
292
284
  },
293
285
  size: {
294
286
  label: tr("admin.files.colSize", { default: "Size" }),
@@ -6,7 +6,7 @@ import { type Infer, type Page, z } from "alepha";
6
6
  import type { AdminJobController, JobExecutionResource } from "alepha/api/jobs";
7
7
  import { useClient } from "alepha/react";
8
8
  import { useI18n } from "alepha/react/i18n";
9
- import { Ban, RotateCcw } from "lucide-react";
9
+ import { Ban, CircleDot, RotateCcw } from "lucide-react";
10
10
  import { useCallback } from "react";
11
11
 
12
12
  const EXEC_POLL_MS = 10_000;
@@ -121,6 +121,7 @@ export const JobExecutionsPanel = (props: JobExecutionsPanelProps) => {
121
121
  input={form.input.status}
122
122
  label=""
123
123
  clearable
124
+ icon={CircleDot}
124
125
  clearLabel={String(
125
126
  tr("admin.jobs.statusAll", { default: "All statuses" }),
126
127
  )}
@@ -19,7 +19,7 @@ import { type Infer, type Page, z } from "alepha";
19
19
  import type { AdminJobController, JobRegistration } from "alepha/api/jobs";
20
20
  import { useAction, useClient } from "alepha/react";
21
21
  import { useI18n } from "alepha/react/i18n";
22
- import { Play, Search, Timer } from "lucide-react";
22
+ import { Play, Search, Shapes, SignalHigh, Timer } from "lucide-react";
23
23
  import { useCallback, useState } from "react";
24
24
 
25
25
  const POLL_MS = 30_000;
@@ -148,6 +148,7 @@ export function AdminJobs() {
148
148
  input={form.input.type}
149
149
  label=""
150
150
  clearable
151
+ icon={Shapes}
151
152
  clearLabel={String(
152
153
  tr("admin.jobs.typeAll", { default: "All types" }),
153
154
  )}
@@ -162,6 +163,7 @@ export function AdminJobs() {
162
163
  input={form.input.priority}
163
164
  label=""
164
165
  clearable
166
+ icon={SignalHigh}
165
167
  clearLabel={String(
166
168
  tr("admin.jobs.priorityAll", { default: "All priorities" }),
167
169
  )}
@@ -0,0 +1,123 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Button } from "@alepha/ui/components/ui/button";
6
+ import {
7
+ Dialog,
8
+ DialogContent,
9
+ DialogDescription,
10
+ DialogFooter,
11
+ DialogHeader,
12
+ DialogTitle,
13
+ } from "@alepha/ui/components/ui/dialog";
14
+ import {
15
+ Tooltip,
16
+ TooltipContent,
17
+ TooltipProvider,
18
+ TooltipTrigger,
19
+ } from "@alepha/ui/components/ui/tooltip";
20
+ import { useToast } from "@alepha/ui/components/use-toast/use-toast";
21
+ import { useI18n } from "alepha/react/i18n";
22
+ import { Check, Copy } from "lucide-react";
23
+ import { useEffect, useRef, useState } from "react";
24
+
25
+ export interface AdminKeysTokenDialogProps {
26
+ /**
27
+ * The freshly minted token, or `null` when the dialog is closed. The
28
+ * server stores only a hash, so this dialog is the single moment the
29
+ * token is ever readable.
30
+ */
31
+ token: string | null;
32
+ onClose: () => void;
33
+ }
34
+
35
+ /**
36
+ * One-time token reveal shown right after an API key is created.
37
+ */
38
+ export const AdminKeysTokenDialog = (props: AdminKeysTokenDialogProps) => {
39
+ const { tr } = useI18n();
40
+ const toast = useToast();
41
+ const [copied, setCopied] = useState(false);
42
+ const copyTimer = useRef<ReturnType<typeof setTimeout> | undefined>(
43
+ undefined,
44
+ );
45
+
46
+ // Clear the "copied" reset timer on unmount so it can't fire setState on an
47
+ // unmounted component.
48
+ useEffect(
49
+ () => () => {
50
+ if (copyTimer.current) clearTimeout(copyTimer.current);
51
+ },
52
+ [],
53
+ );
54
+
55
+ const onCopy = async () => {
56
+ try {
57
+ await navigator.clipboard.writeText(props.token ?? "");
58
+ setCopied(true);
59
+ if (copyTimer.current) clearTimeout(copyTimer.current);
60
+ copyTimer.current = setTimeout(() => setCopied(false), 1_500);
61
+ } catch {
62
+ toast.error(tr("admin.keys.copyFailed", { default: "Could not copy" }));
63
+ }
64
+ };
65
+
66
+ return (
67
+ <Dialog
68
+ open={props.token != null}
69
+ onOpenChange={(open) => {
70
+ if (!open) props.onClose();
71
+ }}
72
+ >
73
+ <DialogContent>
74
+ <DialogHeader>
75
+ <DialogTitle>
76
+ {tr("admin.keys.tokenTitle", { default: "API key created" })}
77
+ </DialogTitle>
78
+ <DialogDescription>
79
+ {tr("admin.keys.tokenDescription", {
80
+ default:
81
+ "Copy this token now — it is shown only once and cannot be recovered.",
82
+ })}
83
+ </DialogDescription>
84
+ </DialogHeader>
85
+ <div className="flex items-start gap-2">
86
+ <code className="bg-muted min-w-0 flex-1 break-all rounded-md p-3 font-mono text-xs leading-relaxed">
87
+ {props.token}
88
+ </code>
89
+ <TooltipProvider>
90
+ <Tooltip>
91
+ <TooltipTrigger
92
+ render={
93
+ <Button
94
+ type="button"
95
+ variant="outline"
96
+ size="sm"
97
+ className="h-9 w-9 shrink-0 p-0"
98
+ aria-label={tr("admin.keys.copy", { default: "Copy" })}
99
+ onClick={onCopy}
100
+ />
101
+ }
102
+ >
103
+ {copied ? (
104
+ <Check className="size-3.5" />
105
+ ) : (
106
+ <Copy className="size-3.5" />
107
+ )}
108
+ </TooltipTrigger>
109
+ <TooltipContent>
110
+ {tr("admin.keys.copy", { default: "Copy" })}
111
+ </TooltipContent>
112
+ </Tooltip>
113
+ </TooltipProvider>
114
+ </div>
115
+ <DialogFooter>
116
+ <Button type="button" onClick={props.onClose}>
117
+ {tr("admin.keys.tokenDone", { default: "Done" })}
118
+ </Button>
119
+ </DialogFooter>
120
+ </DialogContent>
121
+ </Dialog>
122
+ );
123
+ };
@@ -2,7 +2,9 @@ import * as React from "react";
2
2
 
3
3
  void React;
4
4
 
5
+ import { AdminKeysTokenDialog } from "@alepha/ui/components/admin/admin-keys-token-dialog";
5
6
  import { AdminPage } from "@alepha/ui/components/admin/admin-page";
7
+ import { AdminUserCell } from "@alepha/ui/components/admin/admin-user-cell";
6
8
  import { useConfirmedAction } from "@alepha/ui/components/admin/use-confirmed-action";
7
9
  import { AlephaTable } from "@alepha/ui/components/alepha-table/alepha-table";
8
10
  import { Badge } from "@alepha/ui/components/ui/badge";
@@ -11,17 +13,53 @@ import { useToast } from "@alepha/ui/components/use-toast/use-toast";
11
13
  import type {
12
14
  AdminApiKeyController,
13
15
  AdminApiKeyResource,
16
+ ApiKeyController,
14
17
  } from "alepha/api/keys";
15
18
  import { useAction, useClient } from "alepha/react";
16
19
  import { useI18n } from "alepha/react/i18n";
17
- import { Trash2 } from "lucide-react";
18
- import { useCallback } from "react";
20
+ import { Plus, Trash2 } from "lucide-react";
21
+ import { useCallback, useState } from "react";
19
22
 
20
23
  export function AdminKeys() {
21
24
  const client = useClient<AdminApiKeyController>();
25
+ const userClient = useClient<ApiKeyController>();
22
26
  const toast = useToast();
23
27
  const dialog = useDialog();
24
28
  const { l, tr } = useI18n();
29
+ const [createdToken, setCreatedToken] = useState<string | null>(null);
30
+ const [refreshSignal, setRefreshSignal] = useState(0);
31
+
32
+ const createKey = useAction(
33
+ {
34
+ handler: async () => {
35
+ const name = await dialog.prompt({
36
+ title: tr("admin.keys.createTitle", { default: "Add API key" }),
37
+ description: tr("admin.keys.createDescription", {
38
+ default:
39
+ "The key is created for your account and carries your current roles.",
40
+ }),
41
+ label: tr("admin.keys.createNameLabel", { default: "Name" }),
42
+ placeholder: tr("admin.keys.createNamePlaceholder", {
43
+ default: "e.g. CI pipeline",
44
+ }),
45
+ confirmLabel: tr("admin.keys.createConfirm", { default: "Create" }),
46
+ validate: (value) =>
47
+ value.trim().length === 0
48
+ ? tr("admin.keys.createNameRequired", {
49
+ default: "Name is required",
50
+ })
51
+ : null,
52
+ });
53
+ if (name === null) return;
54
+ const created = await userClient.createApiKey({
55
+ body: { name: name.trim() },
56
+ });
57
+ setCreatedToken(created.token);
58
+ setRefreshSignal((n) => n + 1);
59
+ },
60
+ },
61
+ [userClient, dialog, tr],
62
+ );
25
63
 
26
64
  const fetcher = useCallback(
27
65
  async (params: { page: number; size: number; sort?: string }) => {
@@ -96,6 +134,15 @@ export function AdminKeys() {
96
134
  className="min-h-0 flex-1"
97
135
  persistenceKey="admin.keys"
98
136
  fetch={fetcher}
137
+ refreshSignal={refreshSignal}
138
+ actions={[
139
+ {
140
+ icon: Plus,
141
+ label: tr("admin.keys.create", { default: "Add API key" }),
142
+ disabled: createKey.loading,
143
+ onClick: () => createKey.run(),
144
+ },
145
+ ]}
99
146
  bulkActions={[
100
147
  {
101
148
  label: tr("admin.keys.bulkRevoke", {
@@ -119,7 +166,7 @@ export function AdminKeys() {
119
166
  },
120
167
  owner: {
121
168
  label: tr("admin.keys.colOwner", { default: "Owner" }),
122
- cell: (k) => <span className="text-sm">{k.userId ?? "—"}</span>,
169
+ cell: (k) => <AdminUserCell userId={k.userId} user={k.user} />,
123
170
  },
124
171
  roles: {
125
172
  label: tr("admin.keys.colScopes", { default: "Roles" }),
@@ -155,6 +202,10 @@ export function AdminKeys() {
155
202
  },
156
203
  ]}
157
204
  />
205
+ <AdminKeysTokenDialog
206
+ token={createdToken}
207
+ onClose={() => setCreatedToken(null)}
208
+ />
158
209
  </AdminPage>
159
210
  );
160
211
  }