@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.
- package/README.md +12 -0
- package/components.json +20 -0
- package/package.json +85 -0
- package/src/components/action-error-toaster/action-error-toaster.tsx +70 -0
- package/src/components/admin/admin-audits.tsx +247 -0
- package/src/components/admin/admin-files.tsx +346 -0
- package/src/components/admin/admin-jobs-executions-panel.tsx +235 -0
- package/src/components/admin/admin-jobs-status-badge.tsx +33 -0
- package/src/components/admin/admin-jobs.tsx +294 -0
- package/src/components/admin/admin-keys.tsx +162 -0
- package/src/components/admin/admin-notifications.tsx +130 -0
- package/src/components/admin/admin-page.tsx +24 -0
- package/src/components/admin/admin-parameters.tsx +864 -0
- package/src/components/admin/admin-payments.tsx +93 -0
- package/src/components/admin/admin-sessions.tsx +174 -0
- package/src/components/admin/admin-user-detail-audits-tab.tsx +82 -0
- package/src/components/admin/admin-user-detail-identity-aside.tsx +218 -0
- package/src/components/admin/admin-user-detail-overview-tab.tsx +87 -0
- package/src/components/admin/admin-user-detail-password-dialog.tsx +85 -0
- package/src/components/admin/admin-user-detail-password-schema.ts +11 -0
- package/src/components/admin/admin-user-detail-profile-schema.ts +19 -0
- package/src/components/admin/admin-user-detail-provider-labels.ts +15 -0
- package/src/components/admin/admin-user-detail-security-tab.tsx +146 -0
- package/src/components/admin/admin-user-detail-sessions-tab.tsx +93 -0
- package/src/components/admin/admin-user-detail.tsx +606 -0
- package/src/components/admin/admin-users-roles-picker.tsx +126 -0
- package/src/components/admin/admin-users-status-filter.tsx +51 -0
- package/src/components/admin/admin-users.tsx +518 -0
- package/src/components/admin/diff-lines.spec.ts +58 -0
- package/src/components/admin/diff-lines.ts +58 -0
- package/src/components/admin/parameter-diff-dialog.tsx +119 -0
- package/src/components/admin/parameter-history-item.tsx +252 -0
- package/src/components/admin/parameter-json-dialog.tsx +93 -0
- package/src/components/admin/parameter-save-dialog.tsx +126 -0
- package/src/components/admin/use-confirmed-action.tsx +93 -0
- package/src/components/alepha-table/__tests__/use-table-selection.browser.spec.tsx +92 -0
- package/src/components/alepha-table/alepha-table.tsx +1158 -0
- package/src/components/alepha-table/use-table-selection.ts +95 -0
- package/src/components/app-shell/app-shell.tsx +568 -0
- package/src/components/auth/__tests__/auth-router.spec.ts +52 -0
- package/src/components/auth/auth-login.tsx +382 -0
- package/src/components/auth/auth-register.tsx +786 -0
- package/src/components/auth/auth-reset-password.tsx +349 -0
- package/src/components/auth/auth-router.tsx +126 -0
- package/src/components/auth/auth-verify-email.tsx +179 -0
- package/src/components/auto-form/auto-form.tsx +867 -0
- package/src/components/brand-icon/brand-icon.tsx +104 -0
- package/src/components/button-dark/button-dark.tsx +78 -0
- package/src/components/button-language/button-language.tsx +98 -0
- package/src/components/button-theme/button-theme.tsx +148 -0
- package/src/components/button-user/button-user.tsx +214 -0
- package/src/components/captcha/turnstile-widget.tsx +157 -0
- package/src/components/control/control.tsx +735 -0
- package/src/components/control-array/control-array.tsx +700 -0
- package/src/components/control-base/__tests__/form-field-a11y.browser.spec.tsx +93 -0
- package/src/components/control-base/field-i18n.ts +60 -0
- package/src/components/control-base/form-field.tsx +275 -0
- package/src/components/control-base/grid.tsx +59 -0
- package/src/components/control-base/icon-hint.tsx +64 -0
- package/src/components/control-date/control-date.tsx +190 -0
- package/src/components/control-number/control-number.tsx +136 -0
- package/src/components/control-object/control-object.tsx +200 -0
- package/src/components/control-select/control-select.tsx +774 -0
- package/src/components/control-upload/control-upload.tsx +475 -0
- package/src/components/file-image/file-image.tsx +52 -0
- package/src/components/language-toggle/language-toggle.tsx +66 -0
- package/src/components/markdown-view/markdown-view.css +114 -0
- package/src/components/markdown-view/markdown-view.tsx +92 -0
- package/src/components/nav-shell/nav-page.tsx +56 -0
- package/src/components/nav-shell/nav-shell.tsx +72 -0
- package/src/components/nav-shell/nav-tree-util.ts +62 -0
- package/src/components/nav-shell/spotlight.tsx +163 -0
- package/src/components/nav-shell/use-nav-breadcrumbs.ts +52 -0
- package/src/components/nav-shell/use-nav-entries.ts +101 -0
- package/src/components/nav-shell/use-nav-tree.ts +61 -0
- package/src/components/ui/accordion.tsx +77 -0
- package/src/components/ui/alert-dialog.tsx +186 -0
- package/src/components/ui/alert.tsx +75 -0
- package/src/components/ui/aspect-ratio.tsx +22 -0
- package/src/components/ui/avatar.tsx +106 -0
- package/src/components/ui/badge.tsx +51 -0
- package/src/components/ui/breadcrumb.tsx +121 -0
- package/src/components/ui/button-group.tsx +86 -0
- package/src/components/ui/button.tsx +83 -0
- package/src/components/ui/calendar.tsx +235 -0
- package/src/components/ui/card.tsx +102 -0
- package/src/components/ui/carousel.tsx +241 -0
- package/src/components/ui/chart.tsx +370 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/collapsible.tsx +19 -0
- package/src/components/ui/combobox.tsx +298 -0
- package/src/components/ui/command.tsx +196 -0
- package/src/components/ui/context-menu.tsx +271 -0
- package/src/components/ui/dialog.tsx +153 -0
- package/src/components/ui/direction.tsx +4 -0
- package/src/components/ui/drawer.tsx +130 -0
- package/src/components/ui/dropdown-menu.tsx +269 -0
- package/src/components/ui/empty.tsx +100 -0
- package/src/components/ui/hover-card.tsx +50 -0
- package/src/components/ui/input-group.tsx +157 -0
- package/src/components/ui/input-otp.tsx +83 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/item.tsx +200 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/menubar.tsx +283 -0
- package/src/components/ui/navigation-menu.tsx +170 -0
- package/src/components/ui/pagination.tsx +133 -0
- package/src/components/ui/popover.tsx +87 -0
- package/src/components/ui/progress.tsx +82 -0
- package/src/components/ui/radio-group.tsx +35 -0
- package/src/components/ui/resizable.tsx +49 -0
- package/src/components/ui/scroll-area.tsx +51 -0
- package/src/components/ui/segmented.tsx +232 -0
- package/src/components/ui/select.tsx +201 -0
- package/src/components/ui/separator.tsx +22 -0
- package/src/components/ui/sheet.tsx +133 -0
- package/src/components/ui/sidebar.tsx +723 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +51 -0
- package/src/components/ui/sonner.tsx +46 -0
- package/src/components/ui/spinner.tsx +15 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/table.tsx +115 -0
- package/src/components/ui/tabs.tsx +79 -0
- package/src/components/ui/textarea.tsx +17 -0
- package/src/components/ui/toggle-group.tsx +86 -0
- package/src/components/ui/toggle.tsx +44 -0
- package/src/components/ui/tooltip.tsx +63 -0
- package/src/components/use-dialog/use-dialog.tsx +244 -0
- package/src/components/use-toast/use-toast.tsx +89 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/lib/__tests__/i18n-fr.spec.ts +72 -0
- package/src/lib/i18n-fr.ts +500 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles.css +129 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import { AdminPage } from "@alepha/ui/components/admin/admin-page";
|
|
6
|
+
import { AlephaTable } from "@alepha/ui/components/alepha-table/alepha-table";
|
|
7
|
+
import { Badge } from "@alepha/ui/components/ui/badge";
|
|
8
|
+
import type {
|
|
9
|
+
AdminPaymentController,
|
|
10
|
+
IntentResource,
|
|
11
|
+
} from "alepha/api/payments";
|
|
12
|
+
import { useClient } from "alepha/react";
|
|
13
|
+
import { useI18n } from "alepha/react/i18n";
|
|
14
|
+
import { useCallback } from "react";
|
|
15
|
+
|
|
16
|
+
const formatAmount = (cents: number, currency = "USD") => {
|
|
17
|
+
return new Intl.NumberFormat("en-US", {
|
|
18
|
+
style: "currency",
|
|
19
|
+
currency,
|
|
20
|
+
}).format((cents ?? 0) / 100);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function AdminPayments() {
|
|
24
|
+
const client = useClient<AdminPaymentController>();
|
|
25
|
+
const { l, tr } = useI18n();
|
|
26
|
+
|
|
27
|
+
const fetcher = useCallback(
|
|
28
|
+
async (params: { page: number; size: number; sort?: string }) => {
|
|
29
|
+
return client.listIntents({ query: params });
|
|
30
|
+
},
|
|
31
|
+
[client],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<AdminPage>
|
|
36
|
+
<AlephaTable<IntentResource>
|
|
37
|
+
className="min-h-0 flex-1"
|
|
38
|
+
persistenceKey="admin.payments"
|
|
39
|
+
fetch={fetcher}
|
|
40
|
+
columns={{
|
|
41
|
+
createdAt: {
|
|
42
|
+
label: tr("admin.payments.colWhen", { default: "When" }),
|
|
43
|
+
sortable: true,
|
|
44
|
+
cell: (p) => (
|
|
45
|
+
<span className="text-muted-foreground text-xs">
|
|
46
|
+
{String(l(p.createdAt, { date: "fromNow" }))}
|
|
47
|
+
</span>
|
|
48
|
+
),
|
|
49
|
+
},
|
|
50
|
+
amount: {
|
|
51
|
+
label: tr("admin.payments.colAmount", { default: "Amount" }),
|
|
52
|
+
align: "right",
|
|
53
|
+
cell: (p) => (
|
|
54
|
+
<span className="font-medium tabular-nums">
|
|
55
|
+
{formatAmount(p.amount, p.currency)}
|
|
56
|
+
</span>
|
|
57
|
+
),
|
|
58
|
+
},
|
|
59
|
+
customer: {
|
|
60
|
+
label: tr("admin.payments.colCustomer", { default: "Customer" }),
|
|
61
|
+
cell: (p) => (
|
|
62
|
+
<span className="text-muted-foreground font-mono text-xs">
|
|
63
|
+
{p.userId?.slice(0, 8) ?? "—"}
|
|
64
|
+
</span>
|
|
65
|
+
),
|
|
66
|
+
},
|
|
67
|
+
provider: {
|
|
68
|
+
label: tr("admin.payments.colProvider", { default: "Provider" }),
|
|
69
|
+
cell: (p) => (
|
|
70
|
+
<code className="text-xs">{p.providerRef ?? "—"}</code>
|
|
71
|
+
),
|
|
72
|
+
},
|
|
73
|
+
status: {
|
|
74
|
+
label: tr("admin.payments.colStatus", { default: "Status" }),
|
|
75
|
+
cell: (p) => {
|
|
76
|
+
const s = p.status;
|
|
77
|
+
const variant =
|
|
78
|
+
s === "captured" || s === "refunded"
|
|
79
|
+
? "default"
|
|
80
|
+
: s === "failed" ||
|
|
81
|
+
s === "cancelled" ||
|
|
82
|
+
s === "expired" ||
|
|
83
|
+
s === "voided"
|
|
84
|
+
? "destructive"
|
|
85
|
+
: "outline";
|
|
86
|
+
return <Badge variant={variant}>{s}</Badge>;
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
</AdminPage>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
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 { useDialog } from "@alepha/ui/components/use-dialog/use-dialog";
|
|
9
|
+
import { useToast } from "@alepha/ui/components/use-toast/use-toast";
|
|
10
|
+
import type { AdminSessionController, SessionResource } from "alepha/api/users";
|
|
11
|
+
import { useAction, useClient } from "alepha/react";
|
|
12
|
+
import { useI18n } from "alepha/react/i18n";
|
|
13
|
+
import { LogOut } from "lucide-react";
|
|
14
|
+
import { useCallback } from "react";
|
|
15
|
+
|
|
16
|
+
export function AdminSessions() {
|
|
17
|
+
const client = useClient<AdminSessionController>();
|
|
18
|
+
const toast = useToast();
|
|
19
|
+
const dialog = useDialog();
|
|
20
|
+
const { l, tr } = useI18n();
|
|
21
|
+
|
|
22
|
+
const fetcher = useCallback(
|
|
23
|
+
async (params: { page: number; size: number; sort?: string }) => {
|
|
24
|
+
return client.findSessions({ query: params });
|
|
25
|
+
},
|
|
26
|
+
[client],
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const revoke = useConfirmedAction<[SessionResource, () => void]>(
|
|
30
|
+
{
|
|
31
|
+
confirm: {
|
|
32
|
+
title: tr("admin.sessions.revokeTitle", { default: "Revoke session" }),
|
|
33
|
+
description: tr("admin.sessions.revokeConfirm", {
|
|
34
|
+
default: "The user will be signed out from this session.",
|
|
35
|
+
}),
|
|
36
|
+
destructive: true,
|
|
37
|
+
},
|
|
38
|
+
handler: async (s, refresh) => {
|
|
39
|
+
await client.deleteSession({ params: { id: s.id } });
|
|
40
|
+
refresh();
|
|
41
|
+
},
|
|
42
|
+
success: tr("admin.sessions.revoked", { default: "Session revoked" }),
|
|
43
|
+
},
|
|
44
|
+
[client, tr],
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const bulkRevoke = useAction<
|
|
48
|
+
[SessionResource[], { clearSelection: () => void; refresh: () => void }]
|
|
49
|
+
>(
|
|
50
|
+
{
|
|
51
|
+
handler: async (items, ctx) => {
|
|
52
|
+
if (items.length === 0) return;
|
|
53
|
+
const ok = await dialog.confirm({
|
|
54
|
+
title: tr("admin.sessions.bulkRevokeTitle", {
|
|
55
|
+
default: "Revoke sessions",
|
|
56
|
+
}),
|
|
57
|
+
description: tr("admin.sessions.bulkRevokeConfirm", {
|
|
58
|
+
default: `Revoke ${items.length} session(s)? Affected users will be signed out.`,
|
|
59
|
+
args: [String(items.length)],
|
|
60
|
+
}),
|
|
61
|
+
destructive: true,
|
|
62
|
+
});
|
|
63
|
+
if (!ok) return;
|
|
64
|
+
const res = await client.deleteSessions({
|
|
65
|
+
body: { ids: items.map((s) => s.id) },
|
|
66
|
+
});
|
|
67
|
+
toast.success(
|
|
68
|
+
tr("admin.sessions.bulkRevoked", {
|
|
69
|
+
default: `${res.deleted.length} session(s) revoked`,
|
|
70
|
+
args: [String(res.deleted.length)],
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
ctx.clearSelection();
|
|
74
|
+
ctx.refresh();
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
[client, dialog, toast, tr],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<AdminPage>
|
|
82
|
+
<AlephaTable<SessionResource>
|
|
83
|
+
className="min-h-0 flex-1"
|
|
84
|
+
persistenceKey="admin.sessions"
|
|
85
|
+
fetch={fetcher}
|
|
86
|
+
bulkActions={[
|
|
87
|
+
{
|
|
88
|
+
label: tr("admin.sessions.bulkRevoke", {
|
|
89
|
+
default: "Revoke selected",
|
|
90
|
+
}),
|
|
91
|
+
icon: LogOut,
|
|
92
|
+
destructive: true,
|
|
93
|
+
onClick: (items, ctx) => bulkRevoke.run(items, ctx),
|
|
94
|
+
},
|
|
95
|
+
]}
|
|
96
|
+
columns={{
|
|
97
|
+
user: {
|
|
98
|
+
label: tr("admin.sessions.colUser", { default: "User" }),
|
|
99
|
+
cell: (s) => {
|
|
100
|
+
const label =
|
|
101
|
+
s.user?.email ||
|
|
102
|
+
s.user?.username ||
|
|
103
|
+
[s.user?.firstName, s.user?.lastName]
|
|
104
|
+
.filter(Boolean)
|
|
105
|
+
.join(" ") ||
|
|
106
|
+
null;
|
|
107
|
+
return label ? (
|
|
108
|
+
<span className="font-medium">{label}</span>
|
|
109
|
+
) : (
|
|
110
|
+
<span className="text-muted-foreground font-mono text-xs">
|
|
111
|
+
{s.userId?.slice(0, 8) ?? "—"}
|
|
112
|
+
</span>
|
|
113
|
+
);
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
ip: {
|
|
117
|
+
label: tr("admin.sessions.colIp", { default: "IP" }),
|
|
118
|
+
cell: (s) => (
|
|
119
|
+
<span className="flex items-center gap-1.5">
|
|
120
|
+
<code className="text-xs">{s.ip ?? "—"}</code>
|
|
121
|
+
{s.country ? (
|
|
122
|
+
<span className="text-muted-foreground text-xs uppercase">
|
|
123
|
+
{s.country}
|
|
124
|
+
</span>
|
|
125
|
+
) : null}
|
|
126
|
+
</span>
|
|
127
|
+
),
|
|
128
|
+
},
|
|
129
|
+
userAgent: {
|
|
130
|
+
label: tr("admin.sessions.colDevice", { default: "Device" }),
|
|
131
|
+
cell: (s) => {
|
|
132
|
+
const ua = s.userAgent;
|
|
133
|
+
const text = ua
|
|
134
|
+
? [ua.browser, ua.os].filter(Boolean).join(" • ") || "—"
|
|
135
|
+
: "—";
|
|
136
|
+
return (
|
|
137
|
+
<span className="text-muted-foreground line-clamp-1 text-xs">
|
|
138
|
+
{text}
|
|
139
|
+
</span>
|
|
140
|
+
);
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
createdAt: {
|
|
144
|
+
label: tr("admin.sessions.colStarted", { default: "Started" }),
|
|
145
|
+
sortable: true,
|
|
146
|
+
cell: (s) => (
|
|
147
|
+
<span className="text-muted-foreground text-xs">
|
|
148
|
+
{String(l(s.createdAt, { date: "fromNow" }))}
|
|
149
|
+
</span>
|
|
150
|
+
),
|
|
151
|
+
},
|
|
152
|
+
expiresAt: {
|
|
153
|
+
label: tr("admin.sessions.colExpires", { default: "Expires" }),
|
|
154
|
+
cell: (s) => (
|
|
155
|
+
<span className="text-muted-foreground text-xs">
|
|
156
|
+
{String(l(s.expiresAt, { date: "fromNow" }))}
|
|
157
|
+
</span>
|
|
158
|
+
),
|
|
159
|
+
},
|
|
160
|
+
}}
|
|
161
|
+
rowActions={(s) => [
|
|
162
|
+
{
|
|
163
|
+
label: tr("admin.sessions.revoke", { default: "Revoke" }),
|
|
164
|
+
icon: LogOut,
|
|
165
|
+
destructive: true,
|
|
166
|
+
onClick: (_s, { refresh }) => revoke.run(s, refresh),
|
|
167
|
+
},
|
|
168
|
+
]}
|
|
169
|
+
/>
|
|
170
|
+
</AdminPage>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export default AdminSessions;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import { AlephaTable } from "@alepha/ui/components/alepha-table/alepha-table";
|
|
6
|
+
import { Badge } from "@alepha/ui/components/ui/badge";
|
|
7
|
+
import type { AuditEntity } from "alepha/api/audits";
|
|
8
|
+
import { useI18n } from "alepha/react/i18n";
|
|
9
|
+
|
|
10
|
+
export interface AdminUserDetailAuditsTabProps {
|
|
11
|
+
/**
|
|
12
|
+
* Scopes the table's persisted column/sort state to this user.
|
|
13
|
+
*/
|
|
14
|
+
userId: string;
|
|
15
|
+
fetch: React.ComponentProps<typeof AlephaTable<AuditEntity>>["fetch"];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Audit tab: read-only trail of actions recorded against the user.
|
|
20
|
+
*/
|
|
21
|
+
export const AdminUserDetailAuditsTab = (
|
|
22
|
+
props: AdminUserDetailAuditsTabProps,
|
|
23
|
+
) => {
|
|
24
|
+
const { tr, l } = useI18n();
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div className="flex min-h-0 flex-1 flex-col overflow-hidden p-6">
|
|
28
|
+
<AlephaTable<AuditEntity>
|
|
29
|
+
className="min-h-0 flex-1"
|
|
30
|
+
persistenceKey={`admin.userDetail.${props.userId}.audits`}
|
|
31
|
+
fetch={props.fetch}
|
|
32
|
+
columns={{
|
|
33
|
+
createdAt: {
|
|
34
|
+
label: tr("admin.userDetail.colWhen", {
|
|
35
|
+
default: "When",
|
|
36
|
+
}),
|
|
37
|
+
sortable: true,
|
|
38
|
+
cell: (a) => (
|
|
39
|
+
<span className="text-muted-foreground text-xs">
|
|
40
|
+
{String(l(a.createdAt, { date: "fromNow" }))}
|
|
41
|
+
</span>
|
|
42
|
+
),
|
|
43
|
+
},
|
|
44
|
+
action: {
|
|
45
|
+
label: tr("admin.userDetail.colAction", {
|
|
46
|
+
default: "Action",
|
|
47
|
+
}),
|
|
48
|
+
cell: (a) => (
|
|
49
|
+
<code className="text-xs font-medium">{a.action}</code>
|
|
50
|
+
),
|
|
51
|
+
},
|
|
52
|
+
resource: {
|
|
53
|
+
label: tr("admin.userDetail.colResource", {
|
|
54
|
+
default: "Resource",
|
|
55
|
+
}),
|
|
56
|
+
cell: (a) => (
|
|
57
|
+
<span className="font-mono text-xs">
|
|
58
|
+
{a.resourceType
|
|
59
|
+
? `${a.resourceType}:${a.resourceId ?? "—"}`
|
|
60
|
+
: "—"}
|
|
61
|
+
</span>
|
|
62
|
+
),
|
|
63
|
+
},
|
|
64
|
+
status: {
|
|
65
|
+
label: tr("admin.userDetail.colAuditStatus", {
|
|
66
|
+
default: "Status",
|
|
67
|
+
}),
|
|
68
|
+
cell: (a) => (
|
|
69
|
+
<Badge variant={a.success ? "default" : "destructive"}>
|
|
70
|
+
{a.success
|
|
71
|
+
? tr("admin.userDetail.ok", { default: "OK" })
|
|
72
|
+
: tr("admin.userDetail.failed", {
|
|
73
|
+
default: "Failed",
|
|
74
|
+
})}
|
|
75
|
+
</Badge>
|
|
76
|
+
),
|
|
77
|
+
},
|
|
78
|
+
}}
|
|
79
|
+
/>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Avatar,
|
|
7
|
+
AvatarFallback,
|
|
8
|
+
AvatarImage,
|
|
9
|
+
} from "@alepha/ui/components/ui/avatar";
|
|
10
|
+
import { Badge } from "@alepha/ui/components/ui/badge";
|
|
11
|
+
import { Button } from "@alepha/ui/components/ui/button";
|
|
12
|
+
import type { UserResource } from "alepha/api/users";
|
|
13
|
+
import { useI18n } from "alepha/react/i18n";
|
|
14
|
+
import { Check, Copy, ShieldCheck } from "lucide-react";
|
|
15
|
+
import { useEffect, useRef, useState } from "react";
|
|
16
|
+
|
|
17
|
+
export interface AdminUserDetailIdentityAsideProps {
|
|
18
|
+
user: UserResource;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Identity sheet shown alongside the user detail tabs.
|
|
23
|
+
*
|
|
24
|
+
* Admin-style: a dense label/value list rather than a marketing hero. Only
|
|
25
|
+
* fields with a value are listed; ID and Status always show. Display order is
|
|
26
|
+
* ID → username → email → (phone) → status → name → roles → dates.
|
|
27
|
+
*/
|
|
28
|
+
export const AdminUserDetailIdentityAside = (
|
|
29
|
+
props: AdminUserDetailIdentityAsideProps,
|
|
30
|
+
) => {
|
|
31
|
+
const { tr, l } = useI18n();
|
|
32
|
+
const user = props.user;
|
|
33
|
+
|
|
34
|
+
const [copiedId, setCopiedId] = useState(false);
|
|
35
|
+
const copyTimer = useRef<ReturnType<typeof setTimeout> | undefined>(
|
|
36
|
+
undefined,
|
|
37
|
+
);
|
|
38
|
+
// Clear the copy-feedback reset timer on unmount.
|
|
39
|
+
useEffect(
|
|
40
|
+
() => () => {
|
|
41
|
+
if (copyTimer.current) clearTimeout(copyTimer.current);
|
|
42
|
+
},
|
|
43
|
+
[],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const copyId = async () => {
|
|
47
|
+
try {
|
|
48
|
+
await navigator.clipboard.writeText(user.id);
|
|
49
|
+
setCopiedId(true);
|
|
50
|
+
if (copyTimer.current) clearTimeout(copyTimer.current);
|
|
51
|
+
copyTimer.current = setTimeout(() => setCopiedId(false), 1_500);
|
|
52
|
+
} catch {
|
|
53
|
+
// clipboard may be unavailable (insecure context); ignore
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const initial = (user.email || user.username || user.firstName || "?")
|
|
58
|
+
.charAt(0)
|
|
59
|
+
.toUpperCase();
|
|
60
|
+
const displayName =
|
|
61
|
+
user.email ||
|
|
62
|
+
[user.firstName, user.lastName].filter(Boolean).join(" ") ||
|
|
63
|
+
user.username ||
|
|
64
|
+
user.id.slice(0, 8);
|
|
65
|
+
const fullName = [user.firstName, user.lastName].filter(Boolean).join(" ");
|
|
66
|
+
|
|
67
|
+
const rows: Array<{ label: string; value: React.ReactNode }> = [];
|
|
68
|
+
|
|
69
|
+
rows.push({
|
|
70
|
+
label: String(tr("admin.userDetail.id", { default: "ID" })),
|
|
71
|
+
value: (
|
|
72
|
+
<div className="flex items-center gap-1">
|
|
73
|
+
<code
|
|
74
|
+
className="text-muted-foreground min-w-0 flex-1 truncate font-mono text-xs"
|
|
75
|
+
title={user.id}
|
|
76
|
+
>
|
|
77
|
+
{user.id}
|
|
78
|
+
</code>
|
|
79
|
+
<Button
|
|
80
|
+
type="button"
|
|
81
|
+
variant="ghost"
|
|
82
|
+
size="icon-xs"
|
|
83
|
+
onClick={copyId}
|
|
84
|
+
aria-label={String(
|
|
85
|
+
tr("admin.userDetail.copyId", { default: "Copy ID" }),
|
|
86
|
+
)}
|
|
87
|
+
className="text-muted-foreground hover:text-foreground shrink-0"
|
|
88
|
+
>
|
|
89
|
+
{copiedId ? (
|
|
90
|
+
<Check className="size-3.5" />
|
|
91
|
+
) : (
|
|
92
|
+
<Copy className="size-3.5" />
|
|
93
|
+
)}
|
|
94
|
+
</Button>
|
|
95
|
+
</div>
|
|
96
|
+
),
|
|
97
|
+
});
|
|
98
|
+
if (user.username) {
|
|
99
|
+
rows.push({
|
|
100
|
+
label: String(tr("admin.userDetail.username", { default: "Username" })),
|
|
101
|
+
value: (
|
|
102
|
+
<span className="block truncate" title={user.username}>
|
|
103
|
+
@{user.username}
|
|
104
|
+
</span>
|
|
105
|
+
),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (user.email) {
|
|
109
|
+
rows.push({
|
|
110
|
+
label: String(tr("admin.userDetail.email", { default: "Email" })),
|
|
111
|
+
value: (
|
|
112
|
+
<a
|
|
113
|
+
href={`mailto:${user.email}`}
|
|
114
|
+
className="text-primary block truncate hover:underline"
|
|
115
|
+
title={user.email}
|
|
116
|
+
>
|
|
117
|
+
{user.email}
|
|
118
|
+
</a>
|
|
119
|
+
),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (user.phoneNumber) {
|
|
123
|
+
rows.push({
|
|
124
|
+
label: String(tr("admin.userDetail.phone", { default: "Phone" })),
|
|
125
|
+
value: (
|
|
126
|
+
<a
|
|
127
|
+
href={`tel:${user.phoneNumber}`}
|
|
128
|
+
className="text-primary block truncate font-mono hover:underline"
|
|
129
|
+
>
|
|
130
|
+
{user.phoneNumber}
|
|
131
|
+
</a>
|
|
132
|
+
),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
rows.push({
|
|
136
|
+
label: String(tr("admin.userDetail.fieldStatus", { default: "Status" })),
|
|
137
|
+
value: (
|
|
138
|
+
<div className="flex flex-wrap items-center gap-1">
|
|
139
|
+
<Badge variant={user.enabled ? "default" : "destructive"}>
|
|
140
|
+
{user.enabled
|
|
141
|
+
? tr("admin.userDetail.active", { default: "Active" })
|
|
142
|
+
: tr("admin.userDetail.disabledBadge", { default: "Disabled" })}
|
|
143
|
+
</Badge>
|
|
144
|
+
{user.emailVerified && (
|
|
145
|
+
<Badge variant="outline" className="gap-1">
|
|
146
|
+
<ShieldCheck className="size-3" />
|
|
147
|
+
{tr("admin.userDetail.verified", { default: "Verified" })}
|
|
148
|
+
</Badge>
|
|
149
|
+
)}
|
|
150
|
+
</div>
|
|
151
|
+
),
|
|
152
|
+
});
|
|
153
|
+
rows.push({
|
|
154
|
+
label: String(tr("admin.userDetail.name", { default: "Name" })),
|
|
155
|
+
value: (
|
|
156
|
+
<span className="block truncate">
|
|
157
|
+
{fullName || <span className="text-muted-foreground">—</span>}
|
|
158
|
+
</span>
|
|
159
|
+
),
|
|
160
|
+
});
|
|
161
|
+
if (user.roles?.length) {
|
|
162
|
+
rows.push({
|
|
163
|
+
label: String(tr("admin.userDetail.roles", { default: "Roles" })),
|
|
164
|
+
value: <span className="block">{user.roles.join(", ")}</span>,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
rows.push({
|
|
168
|
+
label: String(tr("admin.userDetail.lastLogin", { default: "Last login" })),
|
|
169
|
+
value: (
|
|
170
|
+
<span className="block">
|
|
171
|
+
{user.lastLoginAt
|
|
172
|
+
? String(l(user.lastLoginAt, { date: "lll" }))
|
|
173
|
+
: tr("admin.userDetail.never", { default: "Never" })}
|
|
174
|
+
</span>
|
|
175
|
+
),
|
|
176
|
+
});
|
|
177
|
+
rows.push({
|
|
178
|
+
label: String(tr("admin.userDetail.created", { default: "Created" })),
|
|
179
|
+
value: (
|
|
180
|
+
<span className="block">
|
|
181
|
+
{String(l(user.createdAt, { date: "lll" }))}
|
|
182
|
+
</span>
|
|
183
|
+
),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<div className="flex flex-col gap-4">
|
|
188
|
+
<div className="flex items-center gap-3">
|
|
189
|
+
<Avatar className="size-10 rounded-md after:rounded-md">
|
|
190
|
+
{user.picture && (
|
|
191
|
+
<AvatarImage
|
|
192
|
+
src={user.picture}
|
|
193
|
+
alt={String(displayName)}
|
|
194
|
+
className="rounded-md"
|
|
195
|
+
/>
|
|
196
|
+
)}
|
|
197
|
+
<AvatarFallback className="rounded-md">{initial}</AvatarFallback>
|
|
198
|
+
</Avatar>
|
|
199
|
+
<span
|
|
200
|
+
className="min-w-0 flex-1 truncate text-sm font-semibold tracking-tight"
|
|
201
|
+
title={String(displayName)}
|
|
202
|
+
>
|
|
203
|
+
{displayName}
|
|
204
|
+
</span>
|
|
205
|
+
</div>
|
|
206
|
+
<dl className="flex flex-col gap-3 border-t pt-4 text-sm">
|
|
207
|
+
{rows.map((row) => (
|
|
208
|
+
<div key={row.label} className="flex flex-col gap-0.5">
|
|
209
|
+
<dt className="text-muted-foreground text-[11px] font-medium uppercase tracking-wide">
|
|
210
|
+
{row.label}
|
|
211
|
+
</dt>
|
|
212
|
+
<dd className="min-w-0">{row.value}</dd>
|
|
213
|
+
</div>
|
|
214
|
+
))}
|
|
215
|
+
</dl>
|
|
216
|
+
</div>
|
|
217
|
+
);
|
|
218
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import { AutoForm } from "@alepha/ui/components/auto-form/auto-form";
|
|
6
|
+
import type { FormModel } from "alepha/react/form";
|
|
7
|
+
import { useI18n } from "alepha/react/i18n";
|
|
8
|
+
import { ShieldCheck } from "lucide-react";
|
|
9
|
+
import type { profileSchema } from "./admin-user-detail-profile-schema.ts";
|
|
10
|
+
|
|
11
|
+
export interface AdminUserDetailOverviewTabProps {
|
|
12
|
+
form: FormModel<typeof profileSchema>;
|
|
13
|
+
/**
|
|
14
|
+
* Role metadata for the roles picker. `default: true` roles are offered
|
|
15
|
+
* but not togglable.
|
|
16
|
+
*/
|
|
17
|
+
availableRoles: ReadonlyArray<{ name: string; default?: boolean }>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Overview tab: the editable profile form.
|
|
22
|
+
*/
|
|
23
|
+
export const AdminUserDetailOverviewTab = (
|
|
24
|
+
props: AdminUserDetailOverviewTabProps,
|
|
25
|
+
) => {
|
|
26
|
+
const { tr } = useI18n();
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className="min-h-0 flex-1 overflow-auto">
|
|
30
|
+
<div className="flex max-w-6xl flex-col gap-6 p-6">
|
|
31
|
+
<AutoForm
|
|
32
|
+
form={props.form}
|
|
33
|
+
card
|
|
34
|
+
icon="user"
|
|
35
|
+
title={tr("admin.userDetail.profile", { default: "Profile" })}
|
|
36
|
+
description={tr("admin.userDetail.profileSub", {
|
|
37
|
+
default: "Identity and contact info.",
|
|
38
|
+
})}
|
|
39
|
+
submitLabel={tr("admin.userDetail.save", {
|
|
40
|
+
default: "Save changes",
|
|
41
|
+
})}
|
|
42
|
+
disabledIfPristine
|
|
43
|
+
fields={{
|
|
44
|
+
username: {
|
|
45
|
+
label: String(
|
|
46
|
+
tr("admin.userDetail.username", { default: "Username" }),
|
|
47
|
+
),
|
|
48
|
+
},
|
|
49
|
+
email: {
|
|
50
|
+
label: String(tr("admin.userDetail.email", { default: "Email" })),
|
|
51
|
+
},
|
|
52
|
+
emailVerified: {
|
|
53
|
+
label: String(
|
|
54
|
+
tr("admin.userDetail.emailVerified", {
|
|
55
|
+
default: "Email verified",
|
|
56
|
+
}),
|
|
57
|
+
),
|
|
58
|
+
},
|
|
59
|
+
firstName: {
|
|
60
|
+
label: String(
|
|
61
|
+
tr("admin.userDetail.firstName", {
|
|
62
|
+
default: "First name",
|
|
63
|
+
}),
|
|
64
|
+
),
|
|
65
|
+
},
|
|
66
|
+
lastName: {
|
|
67
|
+
label: String(
|
|
68
|
+
tr("admin.userDetail.lastName", {
|
|
69
|
+
default: "Last name",
|
|
70
|
+
}),
|
|
71
|
+
),
|
|
72
|
+
},
|
|
73
|
+
roles: {
|
|
74
|
+
label: String(tr("admin.userDetail.roles", { default: "Roles" })),
|
|
75
|
+
icon: ShieldCheck,
|
|
76
|
+
items: props.availableRoles.map((r) => ({
|
|
77
|
+
value: r.name,
|
|
78
|
+
label: r.name,
|
|
79
|
+
disabled: r.default,
|
|
80
|
+
})),
|
|
81
|
+
},
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
};
|