@ploykit/ui 0.6.0 → 0.6.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 (222) hide show
  1. package/dist/AppProviders.js +2 -2
  2. package/dist/components/ConfirmDialog.js +1 -1
  3. package/dist/components/CronInput.js +3 -3
  4. package/dist/components/DataTable.js +4 -4
  5. package/dist/components/FormField.js +1 -1
  6. package/dist/components/ImpersonationBanner.js +1 -1
  7. package/dist/components/NotificationBell.js +1 -1
  8. package/dist/components/OnboardingChecklist.js +3 -3
  9. package/dist/components/Page.js +2 -2
  10. package/dist/components/ReauthDialog.js +4 -4
  11. package/dist/components/SecretModal.js +2 -2
  12. package/dist/components/SettingsCard.js +2 -2
  13. package/dist/components/SiteBanner.js +1 -1
  14. package/dist/components/SiteBannerLayer.js +1 -1
  15. package/dist/components/StatusBadge.js +1 -1
  16. package/dist/components/UserMenu.js +3 -3
  17. package/dist/components/WorkspaceSwitcher.js +7 -7
  18. package/dist/components/ui/alert-dialog.js +2 -2
  19. package/dist/components/ui/avatar.js +1 -1
  20. package/dist/components/ui/badge.js +1 -1
  21. package/dist/components/ui/breadcrumb.js +1 -1
  22. package/dist/components/ui/button.js +1 -1
  23. package/dist/components/ui/card.js +1 -1
  24. package/dist/components/ui/checkbox.js +1 -1
  25. package/dist/components/ui/dialog.js +2 -2
  26. package/dist/components/ui/dropdown-menu.js +1 -1
  27. package/dist/components/ui/empty.js +1 -1
  28. package/dist/components/ui/field.js +3 -3
  29. package/dist/components/ui/input.js +1 -1
  30. package/dist/components/ui/label.js +1 -1
  31. package/dist/components/ui/popover.js +1 -1
  32. package/dist/components/ui/progress.js +1 -1
  33. package/dist/components/ui/select.js +1 -1
  34. package/dist/components/ui/separator.js +1 -1
  35. package/dist/components/ui/sheet.js +2 -2
  36. package/dist/components/ui/sidebar.js +8 -8
  37. package/dist/components/ui/skeleton.js +1 -1
  38. package/dist/components/ui/switch.js +1 -1
  39. package/dist/components/ui/tabs.js +1 -1
  40. package/dist/components/ui/textarea.js +1 -1
  41. package/dist/components/ui/tooltip.js +1 -1
  42. package/dist/index.js +78 -78
  43. package/dist/layouts/AppShell.js +4 -4
  44. package/dist/layouts/SettingsShell.js +4 -4
  45. package/dist/pages/LoginPage.js +5 -5
  46. package/dist/pages/account/NotificationPreferencesPage.js +3 -3
  47. package/dist/pages/account/ProfileSettingsPage.js +9 -9
  48. package/dist/pages/account/SecuritySettingsPage.js +13 -13
  49. package/dist/pages/account/TokensPage.js +12 -12
  50. package/dist/pages/admin/AdminSettingsPage.js +11 -11
  51. package/dist/pages/admin/AdminShell.js +3 -3
  52. package/dist/pages/admin/AuditPage.js +8 -8
  53. package/dist/pages/admin/OrdersPage.js +12 -12
  54. package/dist/pages/admin/OverviewPage.js +13 -13
  55. package/dist/pages/admin/SSOPage.js +6 -6
  56. package/dist/pages/admin/UserDetailPage.js +13 -13
  57. package/dist/pages/admin/UsersPage.js +13 -13
  58. package/dist/pages/admin/WebhookDeliveriesPage.js +9 -9
  59. package/dist/pages/admin/WorkspaceDetailPage.js +14 -14
  60. package/dist/pages/admin/WorkspacesPage.js +9 -9
  61. package/dist/pages/admin/shared.js +1 -1
  62. package/dist/pages/auth/ForgotPasswordPage.js +4 -4
  63. package/dist/pages/auth/InviteAcceptPage.js +6 -6
  64. package/dist/pages/auth/RegisterPage.js +7 -7
  65. package/dist/pages/auth/ResetPasswordPage.js +5 -5
  66. package/dist/pages/auth/VerifyEmailPage.js +3 -3
  67. package/dist/pages/workspace/BillingPage.js +11 -11
  68. package/dist/pages/workspace/BillingSuccessPage.js +2 -2
  69. package/dist/pages/workspace/MembersPage.js +15 -15
  70. package/dist/pages/workspace/RolePermissionsPage.js +9 -9
  71. package/dist/pages/workspace/SchedulesPage.js +12 -12
  72. package/dist/pages/workspace/UsagePage.js +6 -6
  73. package/dist/pages/workspace/WebhooksPage.js +16 -16
  74. package/dist/pages/workspace/WorkspaceAuditPage.js +7 -7
  75. package/dist/pages/workspace/WorkspaceGeneralPage.js +9 -9
  76. package/package.json +6 -5
  77. package/src/AppProviders.tsx +29 -0
  78. package/src/components/ConfirmDialog.tsx +77 -0
  79. package/src/components/CronInput.tsx +195 -0
  80. package/src/components/DataTable.tsx +152 -0
  81. package/src/components/ErrorBoundary.tsx +46 -0
  82. package/src/components/FormField.tsx +56 -0
  83. package/src/components/ImpersonationBanner.tsx +23 -0
  84. package/src/components/NotificationBell.tsx +135 -0
  85. package/src/components/OnboardingChecklist.tsx +114 -0
  86. package/src/components/Page.tsx +67 -0
  87. package/src/components/ReauthDialog.tsx +94 -0
  88. package/src/components/SecretModal.tsx +147 -0
  89. package/src/components/SettingsCard.tsx +39 -0
  90. package/src/components/SiteBanner.tsx +32 -0
  91. package/src/components/SiteBannerLayer.tsx +29 -0
  92. package/src/components/StatusBadge.tsx +12 -0
  93. package/src/components/UserMenu.tsx +103 -0
  94. package/src/components/WorkspaceSwitcher.tsx +159 -0
  95. package/src/components/__tests__/AppProviders.test.tsx +111 -0
  96. package/src/components/__tests__/CronInput.test.tsx +180 -0
  97. package/src/components/__tests__/DataTable.test.tsx +208 -0
  98. package/src/components/__tests__/ErrorBoundary.test.tsx +61 -0
  99. package/src/components/__tests__/ImpersonationBanner.test.tsx +59 -0
  100. package/src/components/__tests__/NotificationBell.test.tsx +207 -0
  101. package/src/components/__tests__/OnboardingChecklist.test.tsx +97 -0
  102. package/src/components/__tests__/SecretModal.test.tsx +112 -0
  103. package/src/components/__tests__/SiteBannerLayer.test.tsx +44 -0
  104. package/src/components/__tests__/UserMenu.test.tsx +98 -0
  105. package/src/components/__tests__/WorkspaceSwitcher.test.tsx +162 -0
  106. package/src/components/__tests__/form.test.tsx +133 -0
  107. package/src/components/__tests__/semantic-tokens.test.ts +41 -0
  108. package/src/components/__tests__/smoke.test.tsx +11 -0
  109. package/src/components/__tests__/toast.test.tsx +27 -0
  110. package/src/components/toast.tsx +23 -0
  111. package/src/components/ui/__tests__/alert-dialog.test.tsx +66 -0
  112. package/src/components/ui/__tests__/avatar.test.tsx +30 -0
  113. package/src/components/ui/__tests__/checkbox.test.tsx +18 -0
  114. package/src/components/ui/__tests__/dropdown-menu.test.tsx +33 -0
  115. package/src/components/ui/__tests__/field.test.tsx +43 -0
  116. package/src/components/ui/__tests__/overlay-size.test.tsx +84 -0
  117. package/src/components/ui/__tests__/popover.test.tsx +32 -0
  118. package/src/components/ui/__tests__/progress.test.tsx +24 -0
  119. package/src/components/ui/__tests__/select-callback.test.tsx +72 -0
  120. package/src/components/ui/__tests__/select.test.tsx +48 -0
  121. package/src/components/ui/__tests__/sidebar.test.tsx +121 -0
  122. package/src/components/ui/__tests__/stock-mirror.test.ts +39 -0
  123. package/src/components/ui/__tests__/subpath.test.tsx +38 -0
  124. package/src/components/ui/__tests__/switch.test.tsx +24 -0
  125. package/src/components/ui/__tests__/tabs.test.tsx +24 -0
  126. package/src/components/ui/__tests__/textarea.test.tsx +41 -0
  127. package/src/components/ui/alert-dialog.tsx +187 -0
  128. package/src/components/ui/avatar.tsx +108 -0
  129. package/src/components/ui/badge.tsx +51 -0
  130. package/src/components/ui/breadcrumb.tsx +124 -0
  131. package/src/components/ui/button.tsx +57 -0
  132. package/src/components/ui/card.tsx +102 -0
  133. package/src/components/ui/checkbox.tsx +28 -0
  134. package/src/components/ui/dialog.tsx +166 -0
  135. package/src/components/ui/dropdown-menu.tsx +265 -0
  136. package/src/components/ui/empty.tsx +103 -0
  137. package/src/components/ui/field.tsx +238 -0
  138. package/src/components/ui/input.tsx +19 -0
  139. package/src/components/ui/label.tsx +17 -0
  140. package/src/components/ui/popover.tsx +89 -0
  141. package/src/components/ui/progress.tsx +82 -0
  142. package/src/components/ui/select.tsx +235 -0
  143. package/src/components/ui/separator.tsx +24 -0
  144. package/src/components/ui/sheet.tsx +146 -0
  145. package/src/components/ui/sidebar.tsx +723 -0
  146. package/src/components/ui/skeleton.tsx +13 -0
  147. package/src/components/ui/switch.tsx +29 -0
  148. package/src/components/ui/tabs.tsx +79 -0
  149. package/src/components/ui/textarea.tsx +26 -0
  150. package/src/components/ui/tooltip.tsx +63 -0
  151. package/src/dev.css +1 -0
  152. package/src/hooks/use-mobile.ts +19 -0
  153. package/src/index.ts +150 -0
  154. package/src/layouts/AppShell.tsx +163 -0
  155. package/src/layouts/AuthShell.tsx +24 -0
  156. package/src/layouts/SettingsShell.tsx +129 -0
  157. package/src/layouts/__tests__/AppShell.test.tsx +163 -0
  158. package/src/layouts/__tests__/SettingsShell.test.tsx +146 -0
  159. package/src/lib/__tests__/api-error.test.ts +163 -0
  160. package/src/lib/__tests__/utils.test.ts +21 -0
  161. package/src/lib/api-error.ts +98 -0
  162. package/src/lib/utils.ts +109 -0
  163. package/src/pages/LandingPage.tsx +88 -0
  164. package/src/pages/LoginPage.tsx +291 -0
  165. package/src/pages/__tests__/LandingPage.test.tsx +58 -0
  166. package/src/pages/__tests__/LoginPage.test.tsx +229 -0
  167. package/src/pages/__tests__/RegisterPage.test.tsx +138 -0
  168. package/src/pages/__tests__/ssr-smoke.test.tsx +99 -0
  169. package/src/pages/account/NotificationPreferencesPage.tsx +138 -0
  170. package/src/pages/account/ProfileSettingsPage.tsx +189 -0
  171. package/src/pages/account/SecuritySettingsPage.tsx +214 -0
  172. package/src/pages/account/TokensPage.tsx +211 -0
  173. package/src/pages/account/__tests__/NotificationPreferencesPage.test.tsx +150 -0
  174. package/src/pages/account/__tests__/ProfileSettingsPage.test.tsx +173 -0
  175. package/src/pages/account/__tests__/SecuritySettingsPage.test.tsx +212 -0
  176. package/src/pages/account/__tests__/TokensPage.test.tsx +180 -0
  177. package/src/pages/admin/AdminSettingsPage.tsx +564 -0
  178. package/src/pages/admin/AdminShell.tsx +199 -0
  179. package/src/pages/admin/AuditPage.tsx +338 -0
  180. package/src/pages/admin/OrdersPage.tsx +642 -0
  181. package/src/pages/admin/OverviewPage.tsx +559 -0
  182. package/src/pages/admin/SSOPage.tsx +166 -0
  183. package/src/pages/admin/UserDetailPage.tsx +641 -0
  184. package/src/pages/admin/UsersPage.tsx +462 -0
  185. package/src/pages/admin/WebhookDeliveriesPage.tsx +318 -0
  186. package/src/pages/admin/WorkspaceDetailPage.tsx +551 -0
  187. package/src/pages/admin/WorkspacesPage.tsx +299 -0
  188. package/src/pages/admin/__tests__/AdminSettingsPage.test.tsx +260 -0
  189. package/src/pages/admin/__tests__/OrdersPageMarkPaid.test.tsx +207 -0
  190. package/src/pages/admin/__tests__/OverviewPageActivity.test.tsx +213 -0
  191. package/src/pages/admin/__tests__/SSOPage.test.tsx +128 -0
  192. package/src/pages/admin/__tests__/UsersPageActions.test.tsx +188 -0
  193. package/src/pages/admin/__tests__/WorkspaceDetailPageTransfer.test.tsx +170 -0
  194. package/src/pages/admin/__tests__/WorkspacesPagePlans.test.tsx +138 -0
  195. package/src/pages/admin/shared.ts +42 -0
  196. package/src/pages/auth/ForgotPasswordPage.tsx +83 -0
  197. package/src/pages/auth/InviteAcceptPage.tsx +105 -0
  198. package/src/pages/auth/RegisterPage.tsx +204 -0
  199. package/src/pages/auth/ResetPasswordPage.tsx +150 -0
  200. package/src/pages/auth/VerifyEmailPage.tsx +76 -0
  201. package/src/pages/auth/__tests__/ForgotPasswordPage.test.tsx +67 -0
  202. package/src/pages/auth/__tests__/InviteAcceptPage.test.tsx +86 -0
  203. package/src/pages/auth/__tests__/ResetPasswordPage.test.tsx +115 -0
  204. package/src/pages/auth/__tests__/VerifyEmailPage.test.tsx +74 -0
  205. package/src/pages/workspace/BillingPage.tsx +361 -0
  206. package/src/pages/workspace/BillingSuccessPage.tsx +115 -0
  207. package/src/pages/workspace/MembersPage.tsx +568 -0
  208. package/src/pages/workspace/RolePermissionsPage.tsx +202 -0
  209. package/src/pages/workspace/SchedulesPage.tsx +387 -0
  210. package/src/pages/workspace/UsagePage.tsx +207 -0
  211. package/src/pages/workspace/WebhooksPage.tsx +506 -0
  212. package/src/pages/workspace/WorkspaceAuditPage.tsx +229 -0
  213. package/src/pages/workspace/WorkspaceGeneralPage.tsx +184 -0
  214. package/src/pages/workspace/__tests__/BillingPage.test.tsx +302 -0
  215. package/src/pages/workspace/__tests__/BillingSuccessPage.test.tsx +134 -0
  216. package/src/pages/workspace/__tests__/MembersPage.test.tsx +347 -0
  217. package/src/pages/workspace/__tests__/RolePermissionsPage.test.tsx +138 -0
  218. package/src/pages/workspace/__tests__/SchedulesPage.test.tsx +239 -0
  219. package/src/pages/workspace/__tests__/UsagePage.test.tsx +223 -0
  220. package/src/pages/workspace/__tests__/WebhooksPage.test.tsx +309 -0
  221. package/src/pages/workspace/__tests__/WorkspaceAuditPage.test.tsx +112 -0
  222. package/src/pages/workspace/__tests__/WorkspaceGeneralPage.test.tsx +164 -0
@@ -0,0 +1,462 @@
1
+
2
+ import { useEffect, useState } from 'react';
3
+ import { useNavigate, useSearchParams } from 'react-router';
4
+ import {
5
+ MoreHorizontal,
6
+ LogIn,
7
+ ShieldCheck,
8
+ ShieldOff,
9
+ UserCog,
10
+ UserRoundSearch,
11
+ } from 'lucide-react';
12
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
13
+ import type { components } from '@ploykit/client';
14
+ import { useConfirm } from '../../components/ConfirmDialog';
15
+ import { DataTable, type Column } from '../../components/DataTable';
16
+ import { PageEmpty, PageError, PageHeader } from '../../components/Page';
17
+ import { ImpactConfirmation } from '../../components/SecretModal';
18
+ import { toast } from '../../components/toast';
19
+ import { Badge } from '../../components/ui/badge'
20
+ import { StatusBadge } from '../../components/StatusBadge';
21
+ import { Button } from '../../components/ui/button';
22
+ import { Input } from '../../components/ui/input';
23
+ import {
24
+ DropdownMenu,
25
+ DropdownMenuContent,
26
+ DropdownMenuGroup,
27
+ DropdownMenuItem,
28
+ DropdownMenuLabel,
29
+ DropdownMenuSeparator,
30
+ DropdownMenuTrigger,
31
+ } from '../../components/ui/dropdown-menu';
32
+ import {
33
+ Select,
34
+ SelectContent,
35
+ SelectItem,
36
+ SelectTrigger,
37
+ SelectValue,
38
+ } from '../../components/ui/select';
39
+ import { useApi } from '@ploykit/hooks';
40
+ import { useAuth } from '@ploykit/hooks';
41
+ import { formatDate, formatDateTime } from '../../lib/utils';
42
+ import {
43
+ ADMIN_PAGE_SIZE,
44
+ adminError,
45
+ adminListQuery,
46
+ type AdminListEnvelope,
47
+ } from './shared';
48
+
49
+ type AdminUser = components['schemas']['AdminUser'];
50
+
51
+
52
+ const STATUS_OPTIONS: { value: string; label: string }[] = [
53
+ { value: 'active', label: '生效中' },
54
+ { value: 'disabled', label: '已封禁' },
55
+ ];
56
+
57
+ type RowAction =
58
+ | { kind: 'disable'; user: AdminUser }
59
+ | { kind: 'enable'; user: AdminUser }
60
+ | { kind: 'impersonate'; user: AdminUser };
61
+
62
+ export interface UsersPageProps {
63
+
64
+ impersonatePath?: string;
65
+ }
66
+
67
+ export function UsersPage({ impersonatePath = '/app' }: UsersPageProps = {}) {
68
+ const api = useApi();
69
+ const qc = useQueryClient();
70
+ const confirm = useConfirm();
71
+ const navigate = useNavigate();
72
+ const me = useAuth().user;
73
+
74
+
75
+ const [searchParams, setSearchParams] = useSearchParams();
76
+ const q = searchParams.get('q') ?? '';
77
+ const statusParam = searchParams.get('status') ?? '';
78
+ const status = STATUS_OPTIONS.some((s) => s.value === statusParam)
79
+ ? statusParam
80
+ : '';
81
+ const page = Math.max(
82
+ 1,
83
+ Number.parseInt(searchParams.get('page') ?? '1', 10) || 1,
84
+ );
85
+ const applyFilter = (nextQ: string, nextStatus: string, nextPage: number) => {
86
+ const p = new URLSearchParams(searchParams);
87
+ if (nextQ) p.set('q', nextQ);
88
+ else p.delete('q');
89
+ if (nextStatus) p.set('status', nextStatus);
90
+ else p.delete('status');
91
+ if (nextPage > 1) p.set('page', String(nextPage));
92
+ else p.delete('page');
93
+ setSearchParams(p, { replace: true });
94
+ };
95
+ const [searchInput, setSearchInput] = useState(q);
96
+ const [action, setAction] = useState<RowAction | null>(null);
97
+
98
+
99
+ useEffect(() => {
100
+ const t = setTimeout(() => {
101
+ const next = searchInput.trim();
102
+ if (next !== q) applyFilter(next, status, 1);
103
+ }, 300);
104
+ return () => clearTimeout(t);
105
+ // eslint-disable-next-line react-hooks/exhaustive-deps
106
+ }, [searchInput]);
107
+
108
+ const usersQ = useQuery({
109
+ queryKey: ['admin', 'users', page, q, status],
110
+ queryFn: () =>
111
+ api.get<AdminListEnvelope<AdminUser>>(
112
+ `/api/admin/users${adminListQuery(page, ADMIN_PAGE_SIZE, { q, status })}`,
113
+ ),
114
+ });
115
+
116
+
117
+ const invalidate = () => {
118
+ void qc.invalidateQueries({ queryKey: ['admin', 'users'] });
119
+ void qc.invalidateQueries({ queryKey: ['admin', 'user'] });
120
+ void qc.invalidateQueries({ queryKey: ['admin', 'stats'] });
121
+ };
122
+
123
+ const statusM = useMutation({
124
+ mutationFn: (v: { user: AdminUser; status: 'active' | 'disabled' }) =>
125
+ api.patch(`/api/admin/users/${v.user.id}/status`, { status: v.status }),
126
+ onSuccess: (_d, v) => {
127
+ toast.success(
128
+ `${v.user.email} 已${v.status === 'disabled' ? '封禁' : '解封'}`,
129
+ );
130
+ setAction(null);
131
+ void invalidate();
132
+ },
133
+ onError: (e) => toast.error(adminError(e, '操作失败')),
134
+ });
135
+
136
+ const adminFlagM = useMutation({
137
+ mutationFn: (v: { user: AdminUser; isAdmin: boolean }) =>
138
+ api.patch(`/api/admin/users/${v.user.id}/admin`, { is_admin: v.isAdmin }),
139
+ onSuccess: (_d, v) => {
140
+ toast.success(
141
+ `${v.user.email} ${v.isAdmin ? '已授予' : '已撤销'}平台管理员`,
142
+ );
143
+ void invalidate();
144
+ },
145
+ onError: (e) => toast.error(adminError(e, '操作失败')),
146
+ });
147
+
148
+
149
+ const impersonateM = useMutation({
150
+ mutationFn: (user: AdminUser) =>
151
+ api.post(`/api/admin/users/${user.id}/impersonate`),
152
+ onSuccess: () => {
153
+ window.location.href = impersonatePath;
154
+ },
155
+ onError: (e) => {
156
+ toast.error(adminError(e, '模拟登录失败'));
157
+ setAction(null);
158
+ },
159
+ });
160
+
161
+ const onToggleAdmin = async (user: AdminUser) => {
162
+ const revoke = user.is_platform_admin;
163
+ const ok = await confirm({
164
+ title: revoke ? '撤销平台管理员' : '授予平台管理员',
165
+ description: revoke
166
+ ? `${user.email} 将失去平台管理权限(管理控制台入口随之消失)。`
167
+ : `${user.email} 将获得平台管理权限,可进入管理控制台操作平台全部数据。`,
168
+ confirmText: revoke ? '撤销管理员' : '授予管理员',
169
+ danger: revoke,
170
+ });
171
+ if (ok) adminFlagM.mutate({ user, isAdmin: !revoke });
172
+ };
173
+
174
+ const raw = usersQ.data?.items ?? [];
175
+ const total = usersQ.data?.total ?? 0;
176
+
177
+ const pastEnd = !usersQ.isPending && raw.length === 0 && page > 1;
178
+ const filtered = !!(q || status);
179
+
180
+ const columns: Column<AdminUser>[] = [
181
+ {
182
+ key: 'email',
183
+ header: '用户',
184
+ render: (u) => (
185
+ <div className="min-w-0">
186
+ <p className="truncate font-medium">
187
+ {u.email}
188
+ {u.is_platform_admin && (
189
+ <Badge variant="secondary" className="ml-2">
190
+ 平台管理员
191
+ </Badge>
192
+ )}
193
+ </p>
194
+ <p className="truncate text-xs text-muted-foreground">
195
+ {u.display_name || '—'}
196
+ </p>
197
+ </div>
198
+ ),
199
+ },
200
+ {
201
+ key: 'status',
202
+ header: '状态',
203
+ className: 'w-24',
204
+ render: (u) => <StatusBadge status={u.status} />,
205
+ },
206
+ {
207
+ key: 'email_verified',
208
+ header: '邮箱验证',
209
+ className: 'w-24',
210
+ render: (u) =>
211
+ u.email_verified ? (
212
+ <Badge variant="outline">已验证</Badge>
213
+ ) : (
214
+ <Badge variant="outline" className="text-muted-foreground">
215
+ 未验证
216
+ </Badge>
217
+ ),
218
+ },
219
+ {
220
+ key: 'created_at',
221
+ header: '注册时间',
222
+ className: 'w-28',
223
+ render: (u) => (
224
+ <span className="whitespace-nowrap text-muted-foreground">
225
+ {formatDate(u.created_at)}
226
+ </span>
227
+ ),
228
+ },
229
+ {
230
+ key: 'last_login_at',
231
+ header: '最近登录',
232
+ className: 'w-44',
233
+ render: (u) => (
234
+ <span className="whitespace-nowrap text-muted-foreground">
235
+ {u.last_login_at ? formatDateTime(u.last_login_at) : '从未登录'}
236
+ </span>
237
+ ),
238
+ },
239
+ {
240
+ key: 'actions',
241
+ header: '操作',
242
+ className: 'w-16',
243
+ render: (u) => {
244
+
245
+ if (me?.id === u.id) {
246
+ return (
247
+ <Button
248
+ variant="ghost"
249
+ size="sm"
250
+ onClick={() => navigate(`/admin/users/${u.id}`)}
251
+ >
252
+ <UserRoundSearch /> 详情
253
+ </Button>
254
+ );
255
+ }
256
+ return (
257
+ <DropdownMenu>
258
+ <DropdownMenuTrigger
259
+ className="inline-flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground max-md:size-10"
260
+ aria-label={`操作 ${u.email}`}
261
+ >
262
+ <MoreHorizontal size={16} aria-hidden="true" />
263
+ </DropdownMenuTrigger>
264
+ <DropdownMenuContent align="end" className="w-48">
265
+ {/* GroupLabel 必须包在 Group 内(Base UI Menu.GroupLabel 渲染即读组上下文,
266
+ 裸置于 Content 会 throw #31 整页崩溃——B-users-1 S0 修复) */}
267
+ <DropdownMenuGroup>
268
+ <DropdownMenuLabel className="truncate">
269
+ {u.email}
270
+ </DropdownMenuLabel>
271
+ </DropdownMenuGroup>
272
+ <DropdownMenuSeparator />
273
+ <DropdownMenuItem
274
+ onClick={() => navigate(`/admin/users/${u.id}`)}
275
+ >
276
+ <UserRoundSearch /> 用户详情
277
+ </DropdownMenuItem>
278
+ <DropdownMenuSeparator />
279
+ {u.status === 'active' ? (
280
+ <DropdownMenuItem
281
+ variant="destructive"
282
+ onClick={() => setAction({ kind: 'disable', user: u })}
283
+ >
284
+ <ShieldOff /> 封禁账号
285
+ </DropdownMenuItem>
286
+ ) : (
287
+ <DropdownMenuItem
288
+ onClick={() => setAction({ kind: 'enable', user: u })}
289
+ >
290
+ <ShieldCheck /> 解封账号
291
+ </DropdownMenuItem>
292
+ )}
293
+ <DropdownMenuItem onClick={() => void onToggleAdmin(u)}>
294
+ <UserCog />{' '}
295
+ {u.is_platform_admin ? '撤销平台管理员' : '授予平台管理员'}
296
+ </DropdownMenuItem>
297
+ <DropdownMenuSeparator />
298
+ {/* 管理员互模被服务端禁止(防权限逃逸),行内禁用入口 */}
299
+ <DropdownMenuItem
300
+ disabled={u.is_platform_admin}
301
+ onClick={() => setAction({ kind: 'impersonate', user: u })}
302
+ >
303
+ <LogIn /> 模拟登录
304
+ </DropdownMenuItem>
305
+ </DropdownMenuContent>
306
+ </DropdownMenu>
307
+ );
308
+ },
309
+ },
310
+ ];
311
+
312
+ return (
313
+ <div>
314
+ <PageHeader
315
+ title="用户"
316
+ description="平台全部注册用户;支持邮箱/昵称搜索与状态过滤(服务端检索)"
317
+ />
318
+
319
+ <div className="mb-4 flex flex-wrap items-center gap-2">
320
+ <Input
321
+ className="w-72"
322
+ placeholder="按邮箱前缀 / 昵称搜索…"
323
+ aria-label="搜索用户"
324
+ value={searchInput}
325
+ onChange={(e) => setSearchInput(e.target.value)}
326
+ onKeyDown={(e) => {
327
+ if (e.key === 'Enter') applyFilter(searchInput.trim(), status, 1);
328
+ }}
329
+ />
330
+ <Select
331
+ value={status || 'all'}
332
+ onValueChange={(v) => {
333
+ const next =
334
+ typeof v === 'string' && v !== 'all' ? v : '';
335
+ applyFilter(q, next, 1);
336
+ }}
337
+ >
338
+ <SelectTrigger size="sm" className="w-44" aria-label="按状态过滤">
339
+ <SelectValue>
340
+ {status
341
+ ? (STATUS_OPTIONS.find((s) => s.value === status)?.label ??
342
+ status)
343
+ : '全部状态'}
344
+ </SelectValue>
345
+ </SelectTrigger>
346
+ <SelectContent align="start">
347
+ <SelectItem value="all">全部状态</SelectItem>
348
+ {STATUS_OPTIONS.map((s) => (
349
+ <SelectItem key={s.value} value={s.value}>
350
+ {s.label}
351
+ </SelectItem>
352
+ ))}
353
+ </SelectContent>
354
+ </Select>
355
+ {filtered && (
356
+ <Button
357
+ variant="ghost"
358
+ size="sm"
359
+ className="text-muted-foreground"
360
+ onClick={() => {
361
+ setSearchInput('');
362
+ applyFilter('', '', 1);
363
+ }}
364
+ >
365
+ 清除过滤
366
+ </Button>
367
+ )}
368
+ </div>
369
+
370
+ {usersQ.isError ? (
371
+ <PageError
372
+ message={adminError(usersQ.error, '用户列表加载失败')}
373
+ onRetry={() => void usersQ.refetch()}
374
+ />
375
+ ) : (
376
+ <DataTable
377
+ columns={columns}
378
+ rows={raw}
379
+ rowKey={(u) => u.id}
380
+ loading={usersQ.isPending}
381
+ pagination={{
382
+ page,
383
+ pageSize: ADMIN_PAGE_SIZE,
384
+ total,
385
+ onPageChange: (p) => applyFilter(q, status, p),
386
+ }}
387
+ empty={
388
+ pastEnd ? (
389
+ <div className="flex flex-col items-center gap-2">
390
+ <PageEmpty label="没有更多用户了" hint="当前页数据可能已被删除" />
391
+ <Button
392
+ variant="outline"
393
+ size="sm"
394
+ onClick={() => applyFilter(q, status, 1)}
395
+ >
396
+ 返回第一页
397
+ </Button>
398
+ </div>
399
+ ) : filtered ? (
400
+ <PageEmpty
401
+ label="没有匹配用户"
402
+ hint="换个关键词、放宽状态条件或清除过滤"
403
+ />
404
+ ) : (
405
+ <PageEmpty label="暂无用户" />
406
+ )
407
+ }
408
+ />
409
+ )}
410
+
411
+ {/* 封禁/解封:影响确认(勾选接受后才可执行) */}
412
+ <ImpactConfirmation
413
+ open={action?.kind === 'disable' || action?.kind === 'enable'}
414
+ onOpenChange={(o) => !o && setAction(null)}
415
+ title={
416
+ action?.kind === 'disable'
417
+ ? `封禁 ${action.user.email}`
418
+ : action?.kind === 'enable'
419
+ ? `解封 ${action.user.email}`
420
+ : ''
421
+ }
422
+ danger={action?.kind === 'disable'}
423
+ confirmText={action?.kind === 'disable' ? '封禁' : '解封'}
424
+ impacts={
425
+ action?.kind === 'disable'
426
+ ? [
427
+ '该用户将无法通过邮箱密码与 OAuth 登录',
428
+ '其名下工作区与数据保留,不受影响',
429
+ '操作将记入平台审计日志',
430
+ ]
431
+ : ['该用户恢复登录能力', '操作将记入平台审计日志']
432
+ }
433
+ onConfirm={() => {
434
+ if (action) {
435
+ statusM.mutate({
436
+ user: action.user,
437
+ status: action.kind === 'disable' ? 'disabled' : 'active',
438
+ });
439
+ }
440
+ }}
441
+ />
442
+
443
+ {/* 模拟登录:影响确认;成功后整页跳 /app(Cookie 已被目标会话覆盖) */}
444
+ <ImpactConfirmation
445
+ open={action?.kind === 'impersonate'}
446
+ onOpenChange={(o) => !o && setAction(null)}
447
+ title={
448
+ action?.kind === 'impersonate' ? `模拟登录 ${action.user.email}` : ''
449
+ }
450
+ confirmText={impersonateM.isPending ? '切换中…' : '以该用户进入产品'}
451
+ impacts={[
452
+ '浏览器将以该用户身份进入产品(/app)',
453
+ '当前管理员会话被替换,退出登录后需重新登录管理员账号',
454
+ '审计将记录 admin.impersonate,操作可追溯',
455
+ ]}
456
+ onConfirm={() => {
457
+ if (action?.kind === 'impersonate') impersonateM.mutate(action.user);
458
+ }}
459
+ />
460
+ </div>
461
+ );
462
+ }