@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.
- package/dist/AppProviders.js +2 -2
- package/dist/components/ConfirmDialog.js +1 -1
- package/dist/components/CronInput.js +3 -3
- package/dist/components/DataTable.js +4 -4
- package/dist/components/FormField.js +1 -1
- package/dist/components/ImpersonationBanner.js +1 -1
- package/dist/components/NotificationBell.js +1 -1
- package/dist/components/OnboardingChecklist.js +3 -3
- package/dist/components/Page.js +2 -2
- package/dist/components/ReauthDialog.js +4 -4
- package/dist/components/SecretModal.js +2 -2
- package/dist/components/SettingsCard.js +2 -2
- package/dist/components/SiteBanner.js +1 -1
- package/dist/components/SiteBannerLayer.js +1 -1
- package/dist/components/StatusBadge.js +1 -1
- package/dist/components/UserMenu.js +3 -3
- package/dist/components/WorkspaceSwitcher.js +7 -7
- package/dist/components/ui/alert-dialog.js +2 -2
- package/dist/components/ui/avatar.js +1 -1
- package/dist/components/ui/badge.js +1 -1
- package/dist/components/ui/breadcrumb.js +1 -1
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/card.js +1 -1
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/dialog.js +2 -2
- package/dist/components/ui/dropdown-menu.js +1 -1
- package/dist/components/ui/empty.js +1 -1
- package/dist/components/ui/field.js +3 -3
- package/dist/components/ui/input.js +1 -1
- package/dist/components/ui/label.js +1 -1
- package/dist/components/ui/popover.js +1 -1
- package/dist/components/ui/progress.js +1 -1
- package/dist/components/ui/select.js +1 -1
- package/dist/components/ui/separator.js +1 -1
- package/dist/components/ui/sheet.js +2 -2
- package/dist/components/ui/sidebar.js +8 -8
- package/dist/components/ui/skeleton.js +1 -1
- package/dist/components/ui/switch.js +1 -1
- package/dist/components/ui/tabs.js +1 -1
- package/dist/components/ui/textarea.js +1 -1
- package/dist/components/ui/tooltip.js +1 -1
- package/dist/index.js +78 -78
- package/dist/layouts/AppShell.js +4 -4
- package/dist/layouts/SettingsShell.js +4 -4
- package/dist/pages/LoginPage.js +5 -5
- package/dist/pages/account/NotificationPreferencesPage.js +3 -3
- package/dist/pages/account/ProfileSettingsPage.js +9 -9
- package/dist/pages/account/SecuritySettingsPage.js +13 -13
- package/dist/pages/account/TokensPage.js +12 -12
- package/dist/pages/admin/AdminSettingsPage.js +11 -11
- package/dist/pages/admin/AdminShell.js +3 -3
- package/dist/pages/admin/AuditPage.js +8 -8
- package/dist/pages/admin/OrdersPage.js +12 -12
- package/dist/pages/admin/OverviewPage.js +13 -13
- package/dist/pages/admin/SSOPage.js +6 -6
- package/dist/pages/admin/UserDetailPage.js +13 -13
- package/dist/pages/admin/UsersPage.js +13 -13
- package/dist/pages/admin/WebhookDeliveriesPage.js +9 -9
- package/dist/pages/admin/WorkspaceDetailPage.js +14 -14
- package/dist/pages/admin/WorkspacesPage.js +9 -9
- package/dist/pages/admin/shared.js +1 -1
- package/dist/pages/auth/ForgotPasswordPage.js +4 -4
- package/dist/pages/auth/InviteAcceptPage.js +6 -6
- package/dist/pages/auth/RegisterPage.js +7 -7
- package/dist/pages/auth/ResetPasswordPage.js +5 -5
- package/dist/pages/auth/VerifyEmailPage.js +3 -3
- package/dist/pages/workspace/BillingPage.js +11 -11
- package/dist/pages/workspace/BillingSuccessPage.js +2 -2
- package/dist/pages/workspace/MembersPage.js +15 -15
- package/dist/pages/workspace/RolePermissionsPage.js +9 -9
- package/dist/pages/workspace/SchedulesPage.js +12 -12
- package/dist/pages/workspace/UsagePage.js +6 -6
- package/dist/pages/workspace/WebhooksPage.js +16 -16
- package/dist/pages/workspace/WorkspaceAuditPage.js +7 -7
- package/dist/pages/workspace/WorkspaceGeneralPage.js +9 -9
- package/package.json +6 -5
- package/src/AppProviders.tsx +29 -0
- package/src/components/ConfirmDialog.tsx +77 -0
- package/src/components/CronInput.tsx +195 -0
- package/src/components/DataTable.tsx +152 -0
- package/src/components/ErrorBoundary.tsx +46 -0
- package/src/components/FormField.tsx +56 -0
- package/src/components/ImpersonationBanner.tsx +23 -0
- package/src/components/NotificationBell.tsx +135 -0
- package/src/components/OnboardingChecklist.tsx +114 -0
- package/src/components/Page.tsx +67 -0
- package/src/components/ReauthDialog.tsx +94 -0
- package/src/components/SecretModal.tsx +147 -0
- package/src/components/SettingsCard.tsx +39 -0
- package/src/components/SiteBanner.tsx +32 -0
- package/src/components/SiteBannerLayer.tsx +29 -0
- package/src/components/StatusBadge.tsx +12 -0
- package/src/components/UserMenu.tsx +103 -0
- package/src/components/WorkspaceSwitcher.tsx +159 -0
- package/src/components/__tests__/AppProviders.test.tsx +111 -0
- package/src/components/__tests__/CronInput.test.tsx +180 -0
- package/src/components/__tests__/DataTable.test.tsx +208 -0
- package/src/components/__tests__/ErrorBoundary.test.tsx +61 -0
- package/src/components/__tests__/ImpersonationBanner.test.tsx +59 -0
- package/src/components/__tests__/NotificationBell.test.tsx +207 -0
- package/src/components/__tests__/OnboardingChecklist.test.tsx +97 -0
- package/src/components/__tests__/SecretModal.test.tsx +112 -0
- package/src/components/__tests__/SiteBannerLayer.test.tsx +44 -0
- package/src/components/__tests__/UserMenu.test.tsx +98 -0
- package/src/components/__tests__/WorkspaceSwitcher.test.tsx +162 -0
- package/src/components/__tests__/form.test.tsx +133 -0
- package/src/components/__tests__/semantic-tokens.test.ts +41 -0
- package/src/components/__tests__/smoke.test.tsx +11 -0
- package/src/components/__tests__/toast.test.tsx +27 -0
- package/src/components/toast.tsx +23 -0
- package/src/components/ui/__tests__/alert-dialog.test.tsx +66 -0
- package/src/components/ui/__tests__/avatar.test.tsx +30 -0
- package/src/components/ui/__tests__/checkbox.test.tsx +18 -0
- package/src/components/ui/__tests__/dropdown-menu.test.tsx +33 -0
- package/src/components/ui/__tests__/field.test.tsx +43 -0
- package/src/components/ui/__tests__/overlay-size.test.tsx +84 -0
- package/src/components/ui/__tests__/popover.test.tsx +32 -0
- package/src/components/ui/__tests__/progress.test.tsx +24 -0
- package/src/components/ui/__tests__/select-callback.test.tsx +72 -0
- package/src/components/ui/__tests__/select.test.tsx +48 -0
- package/src/components/ui/__tests__/sidebar.test.tsx +121 -0
- package/src/components/ui/__tests__/stock-mirror.test.ts +39 -0
- package/src/components/ui/__tests__/subpath.test.tsx +38 -0
- package/src/components/ui/__tests__/switch.test.tsx +24 -0
- package/src/components/ui/__tests__/tabs.test.tsx +24 -0
- package/src/components/ui/__tests__/textarea.test.tsx +41 -0
- package/src/components/ui/alert-dialog.tsx +187 -0
- package/src/components/ui/avatar.tsx +108 -0
- package/src/components/ui/badge.tsx +51 -0
- package/src/components/ui/breadcrumb.tsx +124 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/card.tsx +102 -0
- package/src/components/ui/checkbox.tsx +28 -0
- package/src/components/ui/dialog.tsx +166 -0
- package/src/components/ui/dropdown-menu.tsx +265 -0
- package/src/components/ui/empty.tsx +103 -0
- package/src/components/ui/field.tsx +238 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/label.tsx +17 -0
- package/src/components/ui/popover.tsx +89 -0
- package/src/components/ui/progress.tsx +82 -0
- package/src/components/ui/select.tsx +235 -0
- package/src/components/ui/separator.tsx +24 -0
- package/src/components/ui/sheet.tsx +146 -0
- package/src/components/ui/sidebar.tsx +723 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/tabs.tsx +79 -0
- package/src/components/ui/textarea.tsx +26 -0
- package/src/components/ui/tooltip.tsx +63 -0
- package/src/dev.css +1 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/index.ts +150 -0
- package/src/layouts/AppShell.tsx +163 -0
- package/src/layouts/AuthShell.tsx +24 -0
- package/src/layouts/SettingsShell.tsx +129 -0
- package/src/layouts/__tests__/AppShell.test.tsx +163 -0
- package/src/layouts/__tests__/SettingsShell.test.tsx +146 -0
- package/src/lib/__tests__/api-error.test.ts +163 -0
- package/src/lib/__tests__/utils.test.ts +21 -0
- package/src/lib/api-error.ts +98 -0
- package/src/lib/utils.ts +109 -0
- package/src/pages/LandingPage.tsx +88 -0
- package/src/pages/LoginPage.tsx +291 -0
- package/src/pages/__tests__/LandingPage.test.tsx +58 -0
- package/src/pages/__tests__/LoginPage.test.tsx +229 -0
- package/src/pages/__tests__/RegisterPage.test.tsx +138 -0
- package/src/pages/__tests__/ssr-smoke.test.tsx +99 -0
- package/src/pages/account/NotificationPreferencesPage.tsx +138 -0
- package/src/pages/account/ProfileSettingsPage.tsx +189 -0
- package/src/pages/account/SecuritySettingsPage.tsx +214 -0
- package/src/pages/account/TokensPage.tsx +211 -0
- package/src/pages/account/__tests__/NotificationPreferencesPage.test.tsx +150 -0
- package/src/pages/account/__tests__/ProfileSettingsPage.test.tsx +173 -0
- package/src/pages/account/__tests__/SecuritySettingsPage.test.tsx +212 -0
- package/src/pages/account/__tests__/TokensPage.test.tsx +180 -0
- package/src/pages/admin/AdminSettingsPage.tsx +564 -0
- package/src/pages/admin/AdminShell.tsx +199 -0
- package/src/pages/admin/AuditPage.tsx +338 -0
- package/src/pages/admin/OrdersPage.tsx +642 -0
- package/src/pages/admin/OverviewPage.tsx +559 -0
- package/src/pages/admin/SSOPage.tsx +166 -0
- package/src/pages/admin/UserDetailPage.tsx +641 -0
- package/src/pages/admin/UsersPage.tsx +462 -0
- package/src/pages/admin/WebhookDeliveriesPage.tsx +318 -0
- package/src/pages/admin/WorkspaceDetailPage.tsx +551 -0
- package/src/pages/admin/WorkspacesPage.tsx +299 -0
- package/src/pages/admin/__tests__/AdminSettingsPage.test.tsx +260 -0
- package/src/pages/admin/__tests__/OrdersPageMarkPaid.test.tsx +207 -0
- package/src/pages/admin/__tests__/OverviewPageActivity.test.tsx +213 -0
- package/src/pages/admin/__tests__/SSOPage.test.tsx +128 -0
- package/src/pages/admin/__tests__/UsersPageActions.test.tsx +188 -0
- package/src/pages/admin/__tests__/WorkspaceDetailPageTransfer.test.tsx +170 -0
- package/src/pages/admin/__tests__/WorkspacesPagePlans.test.tsx +138 -0
- package/src/pages/admin/shared.ts +42 -0
- package/src/pages/auth/ForgotPasswordPage.tsx +83 -0
- package/src/pages/auth/InviteAcceptPage.tsx +105 -0
- package/src/pages/auth/RegisterPage.tsx +204 -0
- package/src/pages/auth/ResetPasswordPage.tsx +150 -0
- package/src/pages/auth/VerifyEmailPage.tsx +76 -0
- package/src/pages/auth/__tests__/ForgotPasswordPage.test.tsx +67 -0
- package/src/pages/auth/__tests__/InviteAcceptPage.test.tsx +86 -0
- package/src/pages/auth/__tests__/ResetPasswordPage.test.tsx +115 -0
- package/src/pages/auth/__tests__/VerifyEmailPage.test.tsx +74 -0
- package/src/pages/workspace/BillingPage.tsx +361 -0
- package/src/pages/workspace/BillingSuccessPage.tsx +115 -0
- package/src/pages/workspace/MembersPage.tsx +568 -0
- package/src/pages/workspace/RolePermissionsPage.tsx +202 -0
- package/src/pages/workspace/SchedulesPage.tsx +387 -0
- package/src/pages/workspace/UsagePage.tsx +207 -0
- package/src/pages/workspace/WebhooksPage.tsx +506 -0
- package/src/pages/workspace/WorkspaceAuditPage.tsx +229 -0
- package/src/pages/workspace/WorkspaceGeneralPage.tsx +184 -0
- package/src/pages/workspace/__tests__/BillingPage.test.tsx +302 -0
- package/src/pages/workspace/__tests__/BillingSuccessPage.test.tsx +134 -0
- package/src/pages/workspace/__tests__/MembersPage.test.tsx +347 -0
- package/src/pages/workspace/__tests__/RolePermissionsPage.test.tsx +138 -0
- package/src/pages/workspace/__tests__/SchedulesPage.test.tsx +239 -0
- package/src/pages/workspace/__tests__/UsagePage.test.tsx +223 -0
- package/src/pages/workspace/__tests__/WebhooksPage.test.tsx +309 -0
- package/src/pages/workspace/__tests__/WorkspaceAuditPage.test.tsx +112 -0
- 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
|
+
}
|