@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,606 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { AdminUserDetailAuditsTab } from "@alepha/ui/components/admin/admin-user-detail-audits-tab";
6
+ import { AdminUserDetailIdentityAside } from "@alepha/ui/components/admin/admin-user-detail-identity-aside";
7
+ import { AdminUserDetailOverviewTab } from "@alepha/ui/components/admin/admin-user-detail-overview-tab";
8
+ import { AdminUserDetailPasswordDialog } from "@alepha/ui/components/admin/admin-user-detail-password-dialog";
9
+ import { AdminUserDetailSecurityTab } from "@alepha/ui/components/admin/admin-user-detail-security-tab";
10
+ import { AdminUserDetailSessionsTab } from "@alepha/ui/components/admin/admin-user-detail-sessions-tab";
11
+ import { Button } from "@alepha/ui/components/ui/button";
12
+ import { Segmented } from "@alepha/ui/components/ui/segmented";
13
+ import { Skeleton } from "@alepha/ui/components/ui/skeleton";
14
+ import { useDialog } from "@alepha/ui/components/use-dialog/use-dialog";
15
+ import { useToast } from "@alepha/ui/components/use-toast/use-toast";
16
+ import { z } from "alepha";
17
+ import type { AdminAuditController } from "alepha/api/audits";
18
+ import type {
19
+ AdminIdentityController,
20
+ AdminSessionController,
21
+ AdminUserController,
22
+ IdentityResource,
23
+ SessionResource,
24
+ UpdateUser,
25
+ } from "alepha/api/users";
26
+ import { useAction, useClient, useQuery } from "alepha/react";
27
+ import { useAuth } from "alepha/react/auth";
28
+ import { FormValidationError, useForm, useFormState } from "alepha/react/form";
29
+ import { useI18n } from "alepha/react/i18n";
30
+ import { useQueryParams, useRouter, useRouterState } from "alepha/react/router";
31
+ import { HttpError } from "alepha/server";
32
+ import {
33
+ ArrowLeft,
34
+ History,
35
+ Monitor,
36
+ ShieldCheck,
37
+ Trash2,
38
+ User,
39
+ UserCheck,
40
+ UserX,
41
+ } from "lucide-react";
42
+ import { useCallback, useEffect, useState } from "react";
43
+ import { passwordSchema } from "./admin-user-detail-password-schema.ts";
44
+ import {
45
+ type ProfileForm,
46
+ profileSchema,
47
+ } from "./admin-user-detail-profile-schema.ts";
48
+ import { PROVIDER_LABELS } from "./admin-user-detail-provider-labels.ts";
49
+
50
+ export interface AdminUserDetailProps {
51
+ /**
52
+ * Realm name to scope all admin queries. Defaults to the configured
53
+ * user realm.
54
+ */
55
+ userRealmName?: string;
56
+ /**
57
+ * Path to the users list page, for the "Back" link. Defaults to
58
+ * `/admin/users`.
59
+ */
60
+ backPath?: string;
61
+ }
62
+
63
+ type TabKey = "overview" | "security" | "sessions" | "audits";
64
+ const tabSchema = z.object({ tab: z.string().optional() });
65
+
66
+ /**
67
+ * Composition root for the admin user detail page.
68
+ *
69
+ * Owns the data (queries, forms, mutations) and the shell — top bar, tab
70
+ * selection, identity aside. Each tab body lives in its own file beside this
71
+ * one; they render what they are given and hold no fetching of their own.
72
+ */
73
+ export const AdminUserDetail = (props: AdminUserDetailProps) => {
74
+ const router = useRouter();
75
+ const routerState = useRouterState();
76
+ const userId = String(routerState.params.id ?? "");
77
+ const userClient = useClient<AdminUserController>();
78
+ const sessionClient = useClient<AdminSessionController>();
79
+ const identityClient = useClient<AdminIdentityController>();
80
+ const auditClient = useClient<AdminAuditController>();
81
+ const { tr } = useI18n();
82
+ const toast = useToast();
83
+ const { user: currentUser } = useAuth();
84
+ const dialog = useDialog();
85
+
86
+ const [passwordOpen, setPasswordOpen] = useState(false);
87
+ // Tab selection is bound to the URL (`?tab=<key>`) via useQueryParams in
88
+ // querystring mode, which uses replaceState — switching tabs does not add
89
+ // a browser-history entry.
90
+ const [tabQuery, setTabQuery] = useQueryParams(tabSchema, {
91
+ format: "querystring",
92
+ });
93
+ const tab = (tabQuery.tab as TabKey) ?? "overview";
94
+ const setTab = (next: TabKey) => setTabQuery({ tab: next });
95
+
96
+ const isSelf = currentUser?.id === userId;
97
+ const backPath = props.backPath ?? "/admin/users";
98
+
99
+ // -- Load user, roles, identities -----------------------------------------
100
+ // All three are read-only fetches via useQuery: each runs on mount, re-runs
101
+ // when realm/id change, aborts on unmount via the passed signal, and exposes
102
+ // refetch() — so the mutations below just call the relevant refetch()
103
+ // instead of bumping a manual reload key.
104
+
105
+ const userQuery = useQuery(
106
+ {
107
+ handler: ({ signal }) =>
108
+ userClient.getUser(
109
+ {
110
+ params: { id: userId },
111
+ query: { userRealmName: props.userRealmName },
112
+ },
113
+ { request: { signal } },
114
+ ),
115
+ onError: (err) => {
116
+ toast.error(
117
+ tr("admin.userDetail.loadError", { default: "Failed to load user" }),
118
+ );
119
+ console.error(err);
120
+ },
121
+ },
122
+ [userClient, userId, props.userRealmName],
123
+ );
124
+ const user = userQuery.data;
125
+
126
+ const rolesQuery = useQuery(
127
+ {
128
+ handler: ({ signal }) =>
129
+ userClient.findRoles(
130
+ { query: { userRealmName: props.userRealmName } },
131
+ { request: { signal } },
132
+ ),
133
+ // Role metadata is non-blocking — swallow errors so the page still loads.
134
+ onError: () => {},
135
+ },
136
+ [userClient, props.userRealmName],
137
+ );
138
+ const availableRoles = rolesQuery.data ?? [];
139
+
140
+ const identitiesQuery = useQuery(
141
+ {
142
+ handler: ({ signal }) =>
143
+ identityClient.findIdentities(
144
+ { query: { userId, size: 100, userRealmName: props.userRealmName } },
145
+ { request: { signal } },
146
+ ),
147
+ // Identities may fail if the controller isn't mounted — non-blocking.
148
+ onError: () => {},
149
+ },
150
+ [identityClient, userId, props.userRealmName],
151
+ );
152
+ const identities = identitiesQuery.data?.content ?? [];
153
+
154
+ // -- Profile form ---------------------------------------------------------
155
+
156
+ const form = useForm({
157
+ schema: profileSchema,
158
+ initialValues: {
159
+ username: user?.username ?? "",
160
+ email: user?.email ?? "",
161
+ firstName: user?.firstName ?? "",
162
+ lastName: user?.lastName ?? "",
163
+ emailVerified: user?.emailVerified ?? false,
164
+ roles: user?.roles ?? [],
165
+ },
166
+ handler: async (values: ProfileForm) => {
167
+ // Required-field guards (kept in handler, not in schema, so
168
+ // useForm's initial-decode doesn't crash on the empty mount).
169
+ const username = (values.username ?? "").trim();
170
+ const email = (values.email ?? "").trim();
171
+ if (!username) {
172
+ throw new FormValidationError({
173
+ message: tr("admin.userDetail.usernameRequired", {
174
+ default: "Username is required",
175
+ }),
176
+ path: "/username",
177
+ });
178
+ }
179
+ if (!email) {
180
+ throw new FormValidationError({
181
+ message: tr("admin.userDetail.emailRequired", {
182
+ default: "Email is required",
183
+ }),
184
+ path: "/email",
185
+ });
186
+ }
187
+
188
+ // Changing the email invalidates the verified flag — server-side
189
+ // enforcement is also recommended, but mirror it client-side so
190
+ // the UI is immediately consistent.
191
+ const emailChanged = user && email !== (user.email ?? "");
192
+ const body: UpdateUser = {
193
+ username,
194
+ email,
195
+ firstName: (values.firstName ?? "").trim(),
196
+ lastName: (values.lastName ?? "").trim(),
197
+ roles: values.roles ?? [],
198
+ emailVerified: emailChanged ? false : Boolean(values.emailVerified),
199
+ };
200
+
201
+ try {
202
+ await userClient.updateUser({
203
+ params: { id: userId },
204
+ query: { userRealmName: props.userRealmName },
205
+ body,
206
+ });
207
+ toast.success(
208
+ tr("admin.userDetail.saved", { default: "Profile saved" }),
209
+ );
210
+ await userQuery.refetch();
211
+ } catch (err) {
212
+ const message =
213
+ err instanceof HttpError
214
+ ? err.message
215
+ : tr("admin.userDetail.saveError", {
216
+ default: "Failed to save profile",
217
+ });
218
+ toast.error(message);
219
+ throw err;
220
+ }
221
+ },
222
+ });
223
+
224
+ // Reset the form's initial values whenever the loaded user changes.
225
+ // setInitialValues (vs per-field .set) is required so the AutoForm
226
+ // "Reset" button snaps the form back to the server snapshot rather
227
+ // than the empty values captured at mount.
228
+ useEffect(() => {
229
+ if (!user) return;
230
+ form.setInitialValues({
231
+ username: user.username ?? "",
232
+ email: user.email ?? "",
233
+ firstName: user.firstName ?? "",
234
+ lastName: user.lastName ?? "",
235
+ emailVerified: user.emailVerified ?? false,
236
+ roles: user.roles ?? [],
237
+ });
238
+ // eslint-disable-next-line react-hooks/exhaustive-deps
239
+ }, [userQuery.data]);
240
+
241
+ // -- Set password ---------------------------------------------------------
242
+
243
+ const passwordForm = useForm({
244
+ schema: passwordSchema,
245
+ handler: async ({ password }) => {
246
+ await userClient.setUserPassword({
247
+ params: { id: userId },
248
+ query: { userRealmName: props.userRealmName },
249
+ body: { password },
250
+ });
251
+ toast.success(
252
+ tr("admin.userDetail.passwordSet", {
253
+ default: "Password updated",
254
+ }),
255
+ );
256
+ passwordForm.input.password.set?.("");
257
+ setPasswordOpen(false);
258
+ },
259
+ });
260
+ const { loading: passwordSubmitting } = useFormState(passwordForm, [
261
+ "loading",
262
+ ]);
263
+
264
+ // -- Enable/disable -------------------------------------------------------
265
+
266
+ const toggleEnabled = useAction(
267
+ {
268
+ handler: async () => {
269
+ if (!user || isSelf) return;
270
+ const enable = !user.enabled;
271
+ const label =
272
+ user.email ||
273
+ user.username ||
274
+ tr("admin.userDetail.thisUser", {
275
+ default: "this user",
276
+ });
277
+ const ok = await dialog.confirm({
278
+ title: enable
279
+ ? tr("admin.userDetail.enableTitle", { default: "Enable user" })
280
+ : tr("admin.userDetail.disableTitle", { default: "Disable user" }),
281
+ description: enable
282
+ ? tr("admin.userDetail.enableConfirm", {
283
+ default: `Enable ${label}?`,
284
+ args: [String(label)],
285
+ })
286
+ : tr("admin.userDetail.disableConfirm", {
287
+ default: `Disable ${label}? They will no longer be able to sign in.`,
288
+ args: [String(label)],
289
+ }),
290
+ destructive: !enable,
291
+ });
292
+ if (!ok) return;
293
+ await userClient.updateUser({
294
+ params: { id: userId },
295
+ query: { userRealmName: props.userRealmName },
296
+ body: { enabled: enable },
297
+ });
298
+ await userQuery.refetch();
299
+ toast.success(
300
+ enable
301
+ ? tr("admin.userDetail.enabled", { default: "User enabled" })
302
+ : tr("admin.userDetail.disabled", { default: "User disabled" }),
303
+ );
304
+ },
305
+ },
306
+ [user, isSelf],
307
+ );
308
+
309
+ // -- Delete ---------------------------------------------------------------
310
+
311
+ const deleteUser = useAction(
312
+ {
313
+ handler: async () => {
314
+ if (!user || isSelf) return;
315
+ const label =
316
+ user.email ||
317
+ user.username ||
318
+ tr("admin.userDetail.thisUser", {
319
+ default: "this user",
320
+ });
321
+ const ok = await dialog.confirm({
322
+ title: tr("admin.userDetail.deleteTitle", { default: "Delete user" }),
323
+ description: tr("admin.userDetail.deleteConfirm", {
324
+ default: `Permanently delete ${label}? This action cannot be undone.`,
325
+ args: [String(label)],
326
+ }),
327
+ destructive: true,
328
+ confirmLabel: String(
329
+ tr("admin.userDetail.deleteCta", { default: "Delete" }),
330
+ ),
331
+ });
332
+ if (!ok) return;
333
+ await userClient.deleteUser({
334
+ params: { id: userId },
335
+ query: { userRealmName: props.userRealmName },
336
+ });
337
+ toast.success(
338
+ tr("admin.userDetail.deleted", { default: "User deleted" }),
339
+ );
340
+ await router.push(backPath);
341
+ },
342
+ },
343
+ [user, isSelf],
344
+ );
345
+
346
+ // -- Remove social auth ---------------------------------------------------
347
+
348
+ const removeIdentity = useAction<[IdentityResource]>(
349
+ {
350
+ handler: async (identity) => {
351
+ const provider =
352
+ PROVIDER_LABELS[identity.provider] ?? identity.provider;
353
+ const ok = await dialog.confirm({
354
+ title: tr("admin.userDetail.removeIdentityTitle", {
355
+ default: "Remove connection",
356
+ }),
357
+ description: tr("admin.userDetail.removeIdentityConfirm", {
358
+ default: `Remove the ${provider} connection? The user will no longer be able to sign in with it.`,
359
+ args: [provider],
360
+ }),
361
+ destructive: true,
362
+ });
363
+ if (!ok) return;
364
+ await identityClient.deleteIdentity({
365
+ params: { id: identity.id },
366
+ query: { userRealmName: props.userRealmName },
367
+ });
368
+ toast.success(
369
+ tr("admin.userDetail.identityRemoved", {
370
+ default: "Connection removed",
371
+ }),
372
+ );
373
+ await identitiesQuery.refetch();
374
+ },
375
+ },
376
+ [props.userRealmName],
377
+ );
378
+
379
+ // -- Sessions / audits fetchers -------------------------------------------
380
+
381
+ const sessionsFetcher = useCallback(
382
+ (params: { page: number; size: number; sort?: string }) =>
383
+ sessionClient.findSessions({
384
+ query: { ...params, userId, userRealmName: props.userRealmName },
385
+ }),
386
+ [sessionClient, userId, props.userRealmName],
387
+ );
388
+
389
+ const auditsFetcher = useCallback(
390
+ (params: { page: number; size: number; sort?: string }) =>
391
+ auditClient.findByUser({ params: { userId }, query: params }),
392
+ [auditClient, userId],
393
+ );
394
+
395
+ const revokeSession = useAction<[SessionResource, () => void]>(
396
+ {
397
+ handler: async (s, refresh) => {
398
+ const ok = await dialog.confirm({
399
+ title: tr("admin.userDetail.revokeTitle", {
400
+ default: "Revoke session",
401
+ }),
402
+ description: tr("admin.userDetail.revokeConfirm", {
403
+ default:
404
+ "Revoke this session? The user will be signed out on the matching device.",
405
+ }),
406
+ destructive: true,
407
+ });
408
+ if (!ok) return;
409
+ await sessionClient.deleteSession({
410
+ params: { id: s.id },
411
+ query: { userRealmName: props.userRealmName },
412
+ });
413
+ refresh();
414
+ },
415
+ },
416
+ [props.userRealmName],
417
+ );
418
+
419
+ const bulkRevokeSessions = useAction<
420
+ [SessionResource[], { refresh: () => void; clearSelection: () => void }]
421
+ >(
422
+ {
423
+ handler: async (items, ctx) => {
424
+ const ok = await dialog.confirm({
425
+ title: tr("admin.userDetail.bulkRevokeTitle", {
426
+ default: "Revoke sessions",
427
+ }),
428
+ description: tr("admin.userDetail.bulkRevokeConfirm", {
429
+ default: `Revoke ${items.length} sessions?`,
430
+ args: [String(items.length)],
431
+ }),
432
+ destructive: true,
433
+ });
434
+ if (!ok) return;
435
+ await sessionClient.deleteSessions({
436
+ query: { userRealmName: props.userRealmName },
437
+ body: { ids: items.map((s) => s.id) },
438
+ });
439
+ ctx.clearSelection();
440
+ ctx.refresh();
441
+ },
442
+ },
443
+ [props.userRealmName],
444
+ );
445
+
446
+ // -- Render ---------------------------------------------------------------
447
+
448
+ if (userQuery.loading && !user) {
449
+ return (
450
+ <div className="flex flex-col gap-4 p-6">
451
+ <Skeleton className="h-10 w-72" />
452
+ <Skeleton className="h-40 w-full" />
453
+ <Skeleton className="h-40 w-full" />
454
+ </div>
455
+ );
456
+ }
457
+
458
+ if (!user) {
459
+ return (
460
+ <div className="flex flex-col items-start gap-3 p-6">
461
+ <p className="text-muted-foreground text-sm">
462
+ {tr("admin.userDetail.notFound", { default: "User not found." })}
463
+ </p>
464
+ <Button variant="outline" onClick={() => router.push(backPath)}>
465
+ <ArrowLeft className="size-4" />
466
+ {tr("admin.userDetail.back", { default: "Back to users" })}
467
+ </Button>
468
+ </div>
469
+ );
470
+ }
471
+
472
+ // A `credentials` identity means a password is set. Password sign-in lives
473
+ // in its own card; the social providers are everything else.
474
+ const hasPassword = identities.some((id) => id.provider === "credentials");
475
+ const socialIdentities = identities.filter(
476
+ (id) => id.provider !== "credentials",
477
+ );
478
+
479
+ const tabOptions = [
480
+ {
481
+ value: "overview",
482
+ label: (
483
+ <span className="inline-flex items-center gap-1.5">
484
+ <User className="size-4" />
485
+ {tr("admin.userDetail.tabOverview", { default: "Overview" })}
486
+ </span>
487
+ ),
488
+ },
489
+ {
490
+ value: "security",
491
+ label: (
492
+ <span className="inline-flex items-center gap-1.5">
493
+ <ShieldCheck className="size-4" />
494
+ {tr("admin.userDetail.tabSecurity", { default: "Security" })}
495
+ </span>
496
+ ),
497
+ },
498
+ {
499
+ value: "sessions",
500
+ label: (
501
+ <span className="inline-flex items-center gap-1.5">
502
+ <Monitor className="size-4" />
503
+ {tr("admin.userDetail.tabSessions", { default: "Sessions" })}
504
+ </span>
505
+ ),
506
+ },
507
+ {
508
+ value: "audits",
509
+ label: (
510
+ <span className="inline-flex items-center gap-1.5">
511
+ <History className="size-4" />
512
+ {tr("admin.userDetail.tabAudits", { default: "Audit log" })}
513
+ </span>
514
+ ),
515
+ },
516
+ ];
517
+
518
+ return (
519
+ <div className="flex h-full min-h-0 flex-1 overflow-hidden">
520
+ {/* Aside (full height) ------------------------------------------- */}
521
+ <aside className="border-border bg-background hidden w-72 shrink-0 flex-col gap-4 overflow-auto border-r p-6 md:flex">
522
+ <AdminUserDetailIdentityAside user={user} />
523
+ </aside>
524
+
525
+ {/* Right column: top bar + tab content --------------------------- */}
526
+ <div className="flex min-h-0 flex-1 flex-col">
527
+ <div className="bg-background flex h-14 shrink-0 items-center gap-2 border-b px-4">
528
+ <Segmented
529
+ size="sm"
530
+ options={tabOptions}
531
+ value={tab}
532
+ onChange={(v) => setTab(v as typeof tab)}
533
+ />
534
+ <div className="ml-auto flex items-center gap-2">
535
+ <Button
536
+ variant="outline"
537
+ size="sm"
538
+ loading={toggleEnabled.loading}
539
+ disabled={isSelf}
540
+ onClick={() => toggleEnabled.run()}
541
+ >
542
+ {user.enabled ? (
543
+ <>
544
+ <UserX className="size-4" />
545
+ {tr("admin.userDetail.disable", { default: "Disable" })}
546
+ </>
547
+ ) : (
548
+ <>
549
+ <UserCheck className="size-4" />
550
+ {tr("admin.userDetail.enable", { default: "Enable" })}
551
+ </>
552
+ )}
553
+ </Button>
554
+ <Button
555
+ variant="destructive"
556
+ size="sm"
557
+ loading={deleteUser.loading}
558
+ disabled={isSelf}
559
+ onClick={() => deleteUser.run()}
560
+ >
561
+ <Trash2 className="size-4" />
562
+ {tr("admin.userDetail.delete", { default: "Delete user" })}
563
+ </Button>
564
+ </div>
565
+ </div>
566
+ {tab === "overview" && (
567
+ <AdminUserDetailOverviewTab
568
+ form={form}
569
+ availableRoles={availableRoles}
570
+ />
571
+ )}
572
+
573
+ {tab === "security" && (
574
+ <AdminUserDetailSecurityTab
575
+ hasPassword={hasPassword}
576
+ socialIdentities={socialIdentities}
577
+ removeIdentity={removeIdentity}
578
+ onChangePassword={() => setPasswordOpen(true)}
579
+ />
580
+ )}
581
+
582
+ {tab === "sessions" && (
583
+ <AdminUserDetailSessionsTab
584
+ userId={userId}
585
+ fetch={sessionsFetcher}
586
+ revokeSession={revokeSession}
587
+ bulkRevokeSessions={bulkRevokeSessions}
588
+ />
589
+ )}
590
+
591
+ {tab === "audits" && (
592
+ <AdminUserDetailAuditsTab userId={userId} fetch={auditsFetcher} />
593
+ )}
594
+ </div>
595
+
596
+ <AdminUserDetailPasswordDialog
597
+ open={passwordOpen}
598
+ onOpenChange={setPasswordOpen}
599
+ form={passwordForm}
600
+ submitting={passwordSubmitting}
601
+ />
602
+ </div>
603
+ );
604
+ };
605
+
606
+ export default AdminUserDetail;