@umituz/web-dashboard 11.13.0 → 11.14.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/package.json +5 -1
- package/src/domains/admin/admin.css +187 -0
- package/src/domains/admin/components/AdminGate.test.tsx +44 -0
- package/src/domains/admin/components/AdminGate.tsx +41 -0
- package/src/domains/admin/components/AdminHealthCard.test.tsx +42 -0
- package/src/domains/admin/components/AdminHealthCard.tsx +108 -0
- package/src/domains/admin/components/AdminOverview.test.tsx +44 -0
- package/src/domains/admin/components/AdminOverview.tsx +133 -0
- package/src/domains/admin/components/AdminShell.test.tsx +59 -0
- package/src/domains/admin/components/AdminShell.tsx +80 -0
- package/src/domains/admin/components/AdminUsersTable.test.tsx +79 -0
- package/src/domains/admin/components/AdminUsersTable.tsx +239 -0
- package/src/domains/admin/components/index.ts +5 -0
- package/src/domains/admin/index.ts +2 -0
- package/src/domains/admin/types.ts +66 -0
- package/src/domains/stepper/components/Stepper.tsx +7 -2
- package/src/domains/stepper/types.ts +3 -1
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-dashboard",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.14.0",
|
|
4
4
|
"description": "Installable app skeleton for the fleet — layouts, analytics (dependency-free SVG charts), calendar, onboarding flow permissions/module registry; udb-* stylesheet on design-system tokens",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
"./activity/activity.css": "./src/domains/activity/activity.css",
|
|
15
15
|
"./activity/components": "./src/domains/activity/components/index.ts",
|
|
16
16
|
"./activity/types": "./src/domains/activity/types.ts",
|
|
17
|
+
"./admin": "./src/domains/admin/index.ts",
|
|
18
|
+
"./admin/admin.css": "./src/domains/admin/admin.css",
|
|
19
|
+
"./admin/components": "./src/domains/admin/components/index.ts",
|
|
20
|
+
"./admin/types": "./src/domains/admin/types.ts",
|
|
17
21
|
"./analytics": "./src/domains/analytics/index.ts",
|
|
18
22
|
"./analytics/components": "./src/domains/analytics/components/index.ts",
|
|
19
23
|
"./analytics/hooks": "./src/domains/analytics/hooks/index.ts",
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
.udb-admin-shell {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: 1.25rem;
|
|
5
|
+
width: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.udb-admin-subnav {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: 0.25rem;
|
|
12
|
+
border-bottom: 1px solid var(--line-200, rgba(0, 0, 0, 0.08));
|
|
13
|
+
overflow-x: auto;
|
|
14
|
+
scrollbar-width: none;
|
|
15
|
+
-webkit-overflow-scrolling: touch;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.udb-admin-subnav::-webkit-scrollbar {
|
|
19
|
+
display: none;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.udb-admin-subnav-item {
|
|
23
|
+
display: inline-flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
gap: 0.5rem;
|
|
26
|
+
padding: 0.625rem 0.875rem;
|
|
27
|
+
font-size: 0.875rem;
|
|
28
|
+
font-weight: 500;
|
|
29
|
+
white-space: nowrap;
|
|
30
|
+
color: var(--fg-500, #6b7280);
|
|
31
|
+
border-bottom: 2px solid transparent;
|
|
32
|
+
text-decoration: none;
|
|
33
|
+
transition: color 150ms ease, border-color 150ms ease;
|
|
34
|
+
background: transparent;
|
|
35
|
+
border-top: none;
|
|
36
|
+
border-left: none;
|
|
37
|
+
border-right: none;
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.udb-admin-subnav-item:hover {
|
|
42
|
+
color: var(--fg-900, #111827);
|
|
43
|
+
border-bottom-color: var(--line-300, rgba(0, 0, 0, 0.15));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.udb-admin-subnav-item.is-active {
|
|
47
|
+
color: var(--color-primary, #2563eb);
|
|
48
|
+
border-bottom-color: var(--color-primary, #2563eb);
|
|
49
|
+
font-weight: 600;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.udb-admin-overview {
|
|
53
|
+
display: flex;
|
|
54
|
+
flex-direction: column;
|
|
55
|
+
gap: 1.5rem;
|
|
56
|
+
width: 100%;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.udb-admin-kpi-grid {
|
|
60
|
+
display: grid;
|
|
61
|
+
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
|
62
|
+
gap: 1rem;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.udb-admin-layout-split {
|
|
66
|
+
display: grid;
|
|
67
|
+
grid-template-columns: 1fr;
|
|
68
|
+
gap: 1.5rem;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@media (min-width: 1024px) {
|
|
72
|
+
.udb-admin-layout-split {
|
|
73
|
+
grid-template-columns: 1fr 340px;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.udb-admin-health-card {
|
|
78
|
+
display: flex;
|
|
79
|
+
flex-direction: column;
|
|
80
|
+
gap: 1rem;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.udb-admin-health-header {
|
|
84
|
+
display: flex;
|
|
85
|
+
align-items: center;
|
|
86
|
+
justify-content: space-between;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.udb-admin-health-status-row {
|
|
90
|
+
display: flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
gap: 0.625rem;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.udb-admin-pulse-lamp {
|
|
96
|
+
position: relative;
|
|
97
|
+
width: 0.625rem;
|
|
98
|
+
height: 0.625rem;
|
|
99
|
+
border-radius: 9999px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.udb-admin-pulse-lamp::after {
|
|
103
|
+
content: '';
|
|
104
|
+
position: absolute;
|
|
105
|
+
inset: -3px;
|
|
106
|
+
border-radius: 9999px;
|
|
107
|
+
opacity: 0.4;
|
|
108
|
+
animation: udb-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.udb-admin-pulse-lamp--healthy {
|
|
112
|
+
background-color: #10b981;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.udb-admin-pulse-lamp--healthy::after {
|
|
116
|
+
background-color: #10b981;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.udb-admin-pulse-lamp--degraded {
|
|
120
|
+
background-color: #f59e0b;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.udb-admin-pulse-lamp--degraded::after {
|
|
124
|
+
background-color: #f59e0b;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.udb-admin-pulse-lamp--down {
|
|
128
|
+
background-color: #ef4444;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.udb-admin-pulse-lamp--down::after {
|
|
132
|
+
background-color: #ef4444;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@keyframes udb-pulse {
|
|
136
|
+
0%, 100% {
|
|
137
|
+
transform: scale(1);
|
|
138
|
+
opacity: 0.4;
|
|
139
|
+
}
|
|
140
|
+
50% {
|
|
141
|
+
transform: scale(1.6);
|
|
142
|
+
opacity: 0;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.udb-admin-checks-list {
|
|
147
|
+
display: flex;
|
|
148
|
+
flex-direction: column;
|
|
149
|
+
gap: 0.5rem;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.udb-admin-check-item {
|
|
153
|
+
display: flex;
|
|
154
|
+
align-items: center;
|
|
155
|
+
justify-content: space-between;
|
|
156
|
+
padding: 0.5rem 0.75rem;
|
|
157
|
+
border-radius: 0.5rem;
|
|
158
|
+
background: var(--surface-100, rgba(0, 0, 0, 0.02));
|
|
159
|
+
font-size: 0.8125rem;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.udb-admin-quick-actions {
|
|
163
|
+
display: flex;
|
|
164
|
+
flex-direction: column;
|
|
165
|
+
gap: 0.5rem;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.udb-admin-quick-action-btn {
|
|
169
|
+
display: flex;
|
|
170
|
+
align-items: center;
|
|
171
|
+
gap: 0.75rem;
|
|
172
|
+
padding: 0.75rem;
|
|
173
|
+
border-radius: 0.5rem;
|
|
174
|
+
border: 1px solid var(--line-200, rgba(0, 0, 0, 0.08));
|
|
175
|
+
background: var(--surface-card, #ffffff);
|
|
176
|
+
text-decoration: none;
|
|
177
|
+
color: var(--fg-900, #111827);
|
|
178
|
+
transition: all 150ms ease;
|
|
179
|
+
cursor: pointer;
|
|
180
|
+
width: 100%;
|
|
181
|
+
text-align: left;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.udb-admin-quick-action-btn:hover {
|
|
185
|
+
background: var(--surface-hover, rgba(0, 0, 0, 0.03));
|
|
186
|
+
border-color: var(--line-300, rgba(0, 0, 0, 0.15));
|
|
187
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { AdminGate } from './AdminGate';
|
|
4
|
+
|
|
5
|
+
describe('AdminGate', () => {
|
|
6
|
+
it('renders children when isAdmin is true', () => {
|
|
7
|
+
render(
|
|
8
|
+
<AdminGate isAdmin={true}>
|
|
9
|
+
<div>Privileged admin content</div>
|
|
10
|
+
</AdminGate>,
|
|
11
|
+
);
|
|
12
|
+
expect(screen.getByText('Privileged admin content')).toBeTruthy();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('renders loading state when isLoading is true', () => {
|
|
16
|
+
render(
|
|
17
|
+
<AdminGate isAdmin={false} isLoading={true}>
|
|
18
|
+
<div>Hidden content</div>
|
|
19
|
+
</AdminGate>,
|
|
20
|
+
);
|
|
21
|
+
expect(screen.getByRole('status')).toBeTruthy();
|
|
22
|
+
expect(screen.queryByText('Hidden content')).toBeNull();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('renders default AccessDenied when isAdmin is false', () => {
|
|
26
|
+
render(
|
|
27
|
+
<AdminGate isAdmin={false}>
|
|
28
|
+
<div>Hidden content</div>
|
|
29
|
+
</AdminGate>,
|
|
30
|
+
);
|
|
31
|
+
expect(screen.getByText('Admin Access Required')).toBeTruthy();
|
|
32
|
+
expect(screen.queryByText('Hidden content')).toBeNull();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('renders custom fallback when provided and isAdmin is false', () => {
|
|
36
|
+
render(
|
|
37
|
+
<AdminGate isAdmin={false} fallback={<div>Custom unauthorized message</div>}>
|
|
38
|
+
<div>Hidden content</div>
|
|
39
|
+
</AdminGate>,
|
|
40
|
+
);
|
|
41
|
+
expect(screen.getByText('Custom unauthorized message')).toBeTruthy();
|
|
42
|
+
expect(screen.queryByText('Hidden content')).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { AccessDenied } from '../../permissions/AccessDenied';
|
|
3
|
+
|
|
4
|
+
export interface AdminGateProps {
|
|
5
|
+
readonly isAdmin: boolean;
|
|
6
|
+
readonly isLoading?: boolean;
|
|
7
|
+
readonly fallback?: ReactNode;
|
|
8
|
+
readonly children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function AdminGate({
|
|
12
|
+
isAdmin,
|
|
13
|
+
isLoading = false,
|
|
14
|
+
fallback,
|
|
15
|
+
children,
|
|
16
|
+
}: AdminGateProps) {
|
|
17
|
+
if (isLoading) {
|
|
18
|
+
return (
|
|
19
|
+
<div
|
|
20
|
+
role="status"
|
|
21
|
+
aria-label="Checking access"
|
|
22
|
+
className="flex min-h-[240px] w-full items-center justify-center p-8 text-sm text-ink-3"
|
|
23
|
+
>
|
|
24
|
+
<span className="animate-pulse">Checking administrator permissions…</span>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!isAdmin) {
|
|
30
|
+
return (
|
|
31
|
+
fallback ?? (
|
|
32
|
+
<AccessDenied
|
|
33
|
+
title="Admin Access Required"
|
|
34
|
+
description="You do not have administrative privileges to view this section."
|
|
35
|
+
/>
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return <>{children}</>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { AdminHealthCard } from './AdminHealthCard';
|
|
4
|
+
import type { AdminSystemHealth } from '../types';
|
|
5
|
+
|
|
6
|
+
const sampleHealth: AdminSystemHealth = {
|
|
7
|
+
status: 'healthy',
|
|
8
|
+
latencyMs: 42,
|
|
9
|
+
uptime: '99.99%',
|
|
10
|
+
version: 'v2.4.0',
|
|
11
|
+
checks: [
|
|
12
|
+
{ name: 'Database connection', status: 'ok', latencyMs: 12 },
|
|
13
|
+
{ name: 'Edge Worker', status: 'ok', latencyMs: 8 },
|
|
14
|
+
{ name: 'Redis Cache', status: 'warn', latencyMs: 95, message: 'High load' },
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe('AdminHealthCard', () => {
|
|
19
|
+
it('renders title, status label, and metrics', () => {
|
|
20
|
+
render(<AdminHealthCard health={sampleHealth} />);
|
|
21
|
+
expect(screen.getByText('System Telemetry')).toBeTruthy();
|
|
22
|
+
expect(screen.getByText('Operational')).toBeTruthy();
|
|
23
|
+
expect(screen.getByText('42ms')).toBeTruthy();
|
|
24
|
+
expect(screen.getByText('99.99%')).toBeTruthy();
|
|
25
|
+
expect(screen.getByText('v2.4.0')).toBeTruthy();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('renders service checks list', () => {
|
|
29
|
+
render(<AdminHealthCard health={sampleHealth} />);
|
|
30
|
+
expect(screen.getByText('Database connection')).toBeTruthy();
|
|
31
|
+
expect(screen.getByText('Edge Worker')).toBeTruthy();
|
|
32
|
+
expect(screen.getByText('Redis Cache')).toBeTruthy();
|
|
33
|
+
expect(screen.getByText('High load')).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('calls onRefresh when refresh button is clicked', () => {
|
|
37
|
+
const handleRefresh = vi.fn();
|
|
38
|
+
render(<AdminHealthCard health={sampleHealth} onRefresh={handleRefresh} />);
|
|
39
|
+
fireEvent.click(screen.getByLabelText('Refresh telemetry'));
|
|
40
|
+
expect(handleRefresh).toHaveBeenCalled();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Activity, AlertTriangle, CheckCircle2, RefreshCw, XCircle } from 'lucide-react';
|
|
2
|
+
import { Badge, Button } from '@umituz/web-design-system/atoms';
|
|
3
|
+
import { Card } from '@umituz/web-design-system/organisms';
|
|
4
|
+
import { cn } from '@umituz/web-design-system/utils';
|
|
5
|
+
import type { AdminSystemHealth } from '../types';
|
|
6
|
+
|
|
7
|
+
export interface AdminHealthCardProps {
|
|
8
|
+
readonly health: AdminSystemHealth;
|
|
9
|
+
readonly title?: string;
|
|
10
|
+
readonly subtitle?: string;
|
|
11
|
+
readonly onRefresh?: () => void;
|
|
12
|
+
readonly isRefreshing?: boolean;
|
|
13
|
+
readonly className?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function AdminHealthCard({
|
|
17
|
+
health,
|
|
18
|
+
title = 'System Telemetry',
|
|
19
|
+
subtitle = 'Live infrastructure and service checks',
|
|
20
|
+
onRefresh,
|
|
21
|
+
isRefreshing = false,
|
|
22
|
+
className,
|
|
23
|
+
}: AdminHealthCardProps) {
|
|
24
|
+
const tone = health.status === 'healthy' ? 'success' : health.status === 'degraded' ? 'warning' : 'danger';
|
|
25
|
+
const label = health.status === 'healthy' ? 'Operational' : health.status === 'degraded' ? 'Degraded' : 'Outage';
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Card className={cn('p-5', className)}>
|
|
29
|
+
<div className="udb-admin-health-header mb-4">
|
|
30
|
+
<div className="flex items-center gap-2.5">
|
|
31
|
+
<Activity size={18} className="text-ink-2" />
|
|
32
|
+
<div>
|
|
33
|
+
<h3 className="font-display text-base font-semibold text-ink leading-tight">{title}</h3>
|
|
34
|
+
{subtitle && <p className="text-xs text-ink-3">{subtitle}</p>}
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div className="flex items-center gap-2">
|
|
39
|
+
<div className="udb-admin-health-status-row">
|
|
40
|
+
<span
|
|
41
|
+
className={cn(
|
|
42
|
+
'udb-admin-pulse-lamp',
|
|
43
|
+
health.status === 'healthy' && 'udb-admin-pulse-lamp--healthy',
|
|
44
|
+
health.status === 'degraded' && 'udb-admin-pulse-lamp--degraded',
|
|
45
|
+
health.status === 'down' && 'udb-admin-pulse-lamp--down',
|
|
46
|
+
)}
|
|
47
|
+
/>
|
|
48
|
+
<Badge variant={tone}>{label}</Badge>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
{onRefresh && (
|
|
52
|
+
<Button
|
|
53
|
+
variant="outline"
|
|
54
|
+
size="sm"
|
|
55
|
+
onClick={onRefresh}
|
|
56
|
+
disabled={isRefreshing}
|
|
57
|
+
aria-label="Refresh telemetry"
|
|
58
|
+
className="h-8 w-8 p-0"
|
|
59
|
+
>
|
|
60
|
+
<RefreshCw size={13} className={cn(isRefreshing && 'animate-spin')} />
|
|
61
|
+
</Button>
|
|
62
|
+
)}
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<div className="grid grid-cols-3 gap-2 border-y border-line py-3 text-center">
|
|
67
|
+
<div>
|
|
68
|
+
<span className="block text-2xs font-semibold uppercase tracking-wider text-ink-3">Latency</span>
|
|
69
|
+
<span className="font-mono text-sm font-semibold text-ink">
|
|
70
|
+
{typeof health.latencyMs === 'number' ? `${health.latencyMs}ms` : '—'}
|
|
71
|
+
</span>
|
|
72
|
+
</div>
|
|
73
|
+
<div>
|
|
74
|
+
<span className="block text-2xs font-semibold uppercase tracking-wider text-ink-3">Uptime</span>
|
|
75
|
+
<span className="font-mono text-sm font-semibold text-ink">{health.uptime ?? '99.98%'}</span>
|
|
76
|
+
</div>
|
|
77
|
+
<div>
|
|
78
|
+
<span className="block text-2xs font-semibold uppercase tracking-wider text-ink-3">Version</span>
|
|
79
|
+
<span className="font-mono text-sm font-semibold text-ink">{health.version ?? '—'}</span>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
{health.checks && health.checks.length > 0 && (
|
|
84
|
+
<div className="udb-admin-checks-list mt-3.5">
|
|
85
|
+
{health.checks.map((check) => {
|
|
86
|
+
const checkTone = check.status === 'ok' ? 'text-emerald-600' : check.status === 'warn' ? 'text-amber-600' : 'text-rose-600';
|
|
87
|
+
const CheckIcon = check.status === 'ok' ? CheckCircle2 : check.status === 'warn' ? AlertTriangle : XCircle;
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<div key={check.name} className="udb-admin-check-item">
|
|
91
|
+
<div className="flex items-center gap-2">
|
|
92
|
+
<CheckIcon size={14} className={checkTone} />
|
|
93
|
+
<span className="font-medium text-ink">{check.name}</span>
|
|
94
|
+
</div>
|
|
95
|
+
<div className="flex items-center gap-2">
|
|
96
|
+
{check.message && <span className="text-2xs text-ink-3">{check.message}</span>}
|
|
97
|
+
{typeof check.latencyMs === 'number' && (
|
|
98
|
+
<span className="font-mono text-xs text-ink-2">{check.latencyMs}ms</span>
|
|
99
|
+
)}
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
})}
|
|
104
|
+
</div>
|
|
105
|
+
)}
|
|
106
|
+
</Card>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { AdminOverview } from './AdminOverview';
|
|
4
|
+
import type { AdminKpiItem, AdminSystemHealth } from '../types';
|
|
5
|
+
|
|
6
|
+
const kpis: AdminKpiItem[] = [
|
|
7
|
+
{ id: 'tenants', label: 'Total Tenants', value: 142, sub: '128 active' },
|
|
8
|
+
{ id: 'mrr', label: 'Monthly Recurring Revenue', value: '$24,500', change: { value: '+12%', trend: 'up' } },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const health: AdminSystemHealth = {
|
|
12
|
+
status: 'healthy',
|
|
13
|
+
latencyMs: 35,
|
|
14
|
+
uptime: '99.95%',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('AdminOverview', () => {
|
|
18
|
+
it('renders KPI items with values and trends', () => {
|
|
19
|
+
render(<AdminOverview kpis={kpis}><div>Main overview content</div></AdminOverview>);
|
|
20
|
+
expect(screen.getByText('Total Tenants')).toBeTruthy();
|
|
21
|
+
expect(screen.getByText('142')).toBeTruthy();
|
|
22
|
+
expect(screen.getByText('Monthly Recurring Revenue')).toBeTruthy();
|
|
23
|
+
expect(screen.getByText('$24,500')).toBeTruthy();
|
|
24
|
+
expect(screen.getByText('+12%')).toBeTruthy();
|
|
25
|
+
expect(screen.getByText('Main overview content')).toBeTruthy();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('renders quick action buttons and handles clicks', () => {
|
|
29
|
+
const handleClick = vi.fn();
|
|
30
|
+
render(
|
|
31
|
+
<AdminOverview
|
|
32
|
+
health={health}
|
|
33
|
+
quickActions={[
|
|
34
|
+
{ title: 'Create Tenant', description: 'Add a new organization', onClick: handleClick },
|
|
35
|
+
]}
|
|
36
|
+
/>,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(screen.getByText('Create Tenant')).toBeTruthy();
|
|
40
|
+
expect(screen.getByText('Add a new organization')).toBeTruthy();
|
|
41
|
+
fireEvent.click(screen.getByText('Create Tenant'));
|
|
42
|
+
expect(handleClick).toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { ChevronRight, TrendingDown, TrendingUp } from 'lucide-react';
|
|
3
|
+
import { Card } from '@umituz/web-design-system/organisms';
|
|
4
|
+
import { cn } from '@umituz/web-design-system/utils';
|
|
5
|
+
import type { AdminKpiItem, AdminSystemHealth } from '../types';
|
|
6
|
+
import { AdminHealthCard } from './AdminHealthCard';
|
|
7
|
+
|
|
8
|
+
export interface AdminQuickAction {
|
|
9
|
+
readonly title: string;
|
|
10
|
+
readonly description?: string;
|
|
11
|
+
readonly icon?: ReactNode;
|
|
12
|
+
readonly href?: string;
|
|
13
|
+
readonly onClick?: () => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface AdminOverviewProps {
|
|
17
|
+
readonly kpis?: readonly AdminKpiItem[];
|
|
18
|
+
readonly health?: AdminSystemHealth;
|
|
19
|
+
readonly onRefreshHealth?: () => void;
|
|
20
|
+
readonly isRefreshingHealth?: boolean;
|
|
21
|
+
readonly healthTitle?: string;
|
|
22
|
+
readonly quickActions?: readonly AdminQuickAction[];
|
|
23
|
+
readonly children?: ReactNode;
|
|
24
|
+
readonly className?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function AdminOverview({
|
|
28
|
+
kpis,
|
|
29
|
+
health,
|
|
30
|
+
onRefreshHealth,
|
|
31
|
+
isRefreshingHealth,
|
|
32
|
+
healthTitle,
|
|
33
|
+
quickActions,
|
|
34
|
+
children,
|
|
35
|
+
className,
|
|
36
|
+
}: AdminOverviewProps) {
|
|
37
|
+
return (
|
|
38
|
+
<div className={cn('udb-admin-overview', className)}>
|
|
39
|
+
{kpis && kpis.length > 0 && (
|
|
40
|
+
<div className="udb-admin-kpi-grid">
|
|
41
|
+
{kpis.map((kpi) => (
|
|
42
|
+
<Card key={kpi.id} className="p-4">
|
|
43
|
+
<div className="flex items-center justify-between">
|
|
44
|
+
<span className="text-xs font-semibold uppercase tracking-wider text-ink-3">{kpi.label}</span>
|
|
45
|
+
{kpi.icon && <span className="text-ink-3">{kpi.icon}</span>}
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<div className="mt-2 flex items-baseline justify-between gap-2">
|
|
49
|
+
<span className="font-display text-2xl font-bold tracking-tight text-ink">{kpi.value}</span>
|
|
50
|
+
{kpi.change && (
|
|
51
|
+
<span
|
|
52
|
+
className={cn(
|
|
53
|
+
'inline-flex items-center gap-0.5 text-xs font-medium',
|
|
54
|
+
kpi.change.trend === 'up' && 'text-emerald-600',
|
|
55
|
+
kpi.change.trend === 'down' && 'text-rose-600',
|
|
56
|
+
kpi.change.trend === 'neutral' && 'text-ink-3',
|
|
57
|
+
)}
|
|
58
|
+
>
|
|
59
|
+
{kpi.change.trend === 'up' && <TrendingUp size={12} />}
|
|
60
|
+
{kpi.change.trend === 'down' && <TrendingDown size={12} />}
|
|
61
|
+
{kpi.change.value}
|
|
62
|
+
</span>
|
|
63
|
+
)}
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
{kpi.sub && <p className="mt-1 text-2xs text-ink-3">{kpi.sub}</p>}
|
|
67
|
+
</Card>
|
|
68
|
+
))}
|
|
69
|
+
</div>
|
|
70
|
+
)}
|
|
71
|
+
|
|
72
|
+
<div className={cn(Boolean(health || quickActions) && 'udb-admin-layout-split')}>
|
|
73
|
+
<div className="min-w-0 flex-1">{children}</div>
|
|
74
|
+
|
|
75
|
+
{(health || (quickActions && quickActions.length > 0)) && (
|
|
76
|
+
<aside className="flex flex-col gap-4">
|
|
77
|
+
{health && (
|
|
78
|
+
<AdminHealthCard
|
|
79
|
+
health={health}
|
|
80
|
+
title={healthTitle}
|
|
81
|
+
onRefresh={onRefreshHealth}
|
|
82
|
+
isRefreshing={isRefreshingHealth}
|
|
83
|
+
/>
|
|
84
|
+
)}
|
|
85
|
+
|
|
86
|
+
{quickActions && quickActions.length > 0 && (
|
|
87
|
+
<Card className="p-4">
|
|
88
|
+
<h3 className="font-display text-sm font-semibold uppercase tracking-wider text-ink-3 mb-3">
|
|
89
|
+
Shortcuts & Actions
|
|
90
|
+
</h3>
|
|
91
|
+
<div className="udb-admin-quick-actions">
|
|
92
|
+
{quickActions.map((action) => {
|
|
93
|
+
const content = (
|
|
94
|
+
<>
|
|
95
|
+
{action.icon && <span className="text-ink-2">{action.icon}</span>}
|
|
96
|
+
<div className="min-w-0 flex-1">
|
|
97
|
+
<span className="block text-sm font-semibold text-ink leading-tight">{action.title}</span>
|
|
98
|
+
{action.description && (
|
|
99
|
+
<span className="block text-2xs text-ink-3">{action.description}</span>
|
|
100
|
+
)}
|
|
101
|
+
</div>
|
|
102
|
+
<ChevronRight size={14} className="text-ink-4 shrink-0" />
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
if (action.href) {
|
|
107
|
+
return (
|
|
108
|
+
<a key={action.title} href={action.href} className="udb-admin-quick-action-btn">
|
|
109
|
+
{content}
|
|
110
|
+
</a>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<button
|
|
116
|
+
key={action.title}
|
|
117
|
+
type="button"
|
|
118
|
+
onClick={action.onClick}
|
|
119
|
+
className="udb-admin-quick-action-btn"
|
|
120
|
+
>
|
|
121
|
+
{content}
|
|
122
|
+
</button>
|
|
123
|
+
);
|
|
124
|
+
})}
|
|
125
|
+
</div>
|
|
126
|
+
</Card>
|
|
127
|
+
)}
|
|
128
|
+
</aside>
|
|
129
|
+
)}
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { MemoryRouter } from 'react-router';
|
|
4
|
+
import { AdminShell } from './AdminShell';
|
|
5
|
+
import type { AdminNavItem } from '../types';
|
|
6
|
+
|
|
7
|
+
const navItems: AdminNavItem[] = [
|
|
8
|
+
{ id: 'overview', label: 'Overview', href: '/admin', exact: true },
|
|
9
|
+
{ id: 'users', label: 'Users', href: '/admin/users' },
|
|
10
|
+
{ id: 'health', label: 'Health', href: '/admin/health' },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
describe('AdminShell', () => {
|
|
14
|
+
it('renders title, description and children', () => {
|
|
15
|
+
render(
|
|
16
|
+
<AdminShell title="Platform Console" description="Manage all system tenants">
|
|
17
|
+
<div>Admin content area</div>
|
|
18
|
+
</AdminShell>,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
expect(screen.getByText('Platform Console')).toBeTruthy();
|
|
22
|
+
expect(screen.getByText('Manage all system tenants')).toBeTruthy();
|
|
23
|
+
expect(screen.getByText('Admin content area')).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('renders interactive subnav buttons when onNavChange is provided', () => {
|
|
27
|
+
const handleNavChange = vi.fn();
|
|
28
|
+
render(
|
|
29
|
+
<AdminShell
|
|
30
|
+
title="Admin"
|
|
31
|
+
navItems={navItems}
|
|
32
|
+
activeNavId="users"
|
|
33
|
+
onNavChange={handleNavChange}
|
|
34
|
+
>
|
|
35
|
+
<div>Content</div>
|
|
36
|
+
</AdminShell>,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(screen.getByText('Overview')).toBeTruthy();
|
|
40
|
+
expect(screen.getByText('Users')).toBeTruthy();
|
|
41
|
+
expect(screen.getByText('Health')).toBeTruthy();
|
|
42
|
+
|
|
43
|
+
fireEvent.click(screen.getByText('Health'));
|
|
44
|
+
expect(handleNavChange).toHaveBeenCalledWith(navItems[2]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('renders NavLinks when rendered inside a Router without onNavChange', () => {
|
|
48
|
+
render(
|
|
49
|
+
<MemoryRouter initialEntries={['/admin']}>
|
|
50
|
+
<AdminShell title="Admin" navItems={navItems}>
|
|
51
|
+
<div>Content</div>
|
|
52
|
+
</AdminShell>
|
|
53
|
+
</MemoryRouter>,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
expect(screen.getByText('Overview')).toBeTruthy();
|
|
57
|
+
expect(screen.getByText('Users')).toBeTruthy();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { NavLink } from 'react-router';
|
|
3
|
+
import { cn } from '@umituz/web-design-system/utils';
|
|
4
|
+
import type { AdminNavItem } from '../types';
|
|
5
|
+
|
|
6
|
+
export interface AdminShellProps {
|
|
7
|
+
readonly title: string;
|
|
8
|
+
readonly description?: string;
|
|
9
|
+
readonly badge?: ReactNode;
|
|
10
|
+
readonly actions?: ReactNode;
|
|
11
|
+
readonly navItems?: readonly AdminNavItem[];
|
|
12
|
+
readonly activeNavId?: string;
|
|
13
|
+
readonly onNavChange?: (item: AdminNavItem) => void;
|
|
14
|
+
readonly children: ReactNode;
|
|
15
|
+
readonly className?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function AdminShell({
|
|
19
|
+
title,
|
|
20
|
+
description,
|
|
21
|
+
badge,
|
|
22
|
+
actions,
|
|
23
|
+
navItems,
|
|
24
|
+
activeNavId,
|
|
25
|
+
onNavChange,
|
|
26
|
+
children,
|
|
27
|
+
className,
|
|
28
|
+
}: AdminShellProps) {
|
|
29
|
+
return (
|
|
30
|
+
<div className={cn('udb-admin-shell', className)}>
|
|
31
|
+
<div className="flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
|
|
32
|
+
<div>
|
|
33
|
+
<div className="flex items-center gap-2.5">
|
|
34
|
+
<h1 className="font-display text-2xl font-bold tracking-tight text-ink">{title}</h1>
|
|
35
|
+
{badge}
|
|
36
|
+
</div>
|
|
37
|
+
{description && <p className="mt-1 text-sm text-ink-2 leading-relaxed">{description}</p>}
|
|
38
|
+
</div>
|
|
39
|
+
{actions && <div className="mt-3 flex items-center gap-2 sm:mt-0">{actions}</div>}
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
{navItems && navItems.length > 0 && (
|
|
43
|
+
<nav aria-label="Admin sections" className="udb-admin-subnav">
|
|
44
|
+
{navItems.map((item) => {
|
|
45
|
+
if (onNavChange) {
|
|
46
|
+
const isActive = activeNavId === item.id;
|
|
47
|
+
return (
|
|
48
|
+
<button
|
|
49
|
+
key={item.id}
|
|
50
|
+
type="button"
|
|
51
|
+
onClick={() => onNavChange(item)}
|
|
52
|
+
className={cn('udb-admin-subnav-item', isActive && 'is-active')}
|
|
53
|
+
>
|
|
54
|
+
{item.icon}
|
|
55
|
+
<span>{item.label}</span>
|
|
56
|
+
{item.badge}
|
|
57
|
+
</button>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<NavLink
|
|
63
|
+
key={item.id}
|
|
64
|
+
to={item.href}
|
|
65
|
+
end={item.exact}
|
|
66
|
+
className={({ isActive }) => cn('udb-admin-subnav-item', isActive && 'is-active')}
|
|
67
|
+
>
|
|
68
|
+
{item.icon}
|
|
69
|
+
<span>{item.label}</span>
|
|
70
|
+
{item.badge}
|
|
71
|
+
</NavLink>
|
|
72
|
+
);
|
|
73
|
+
})}
|
|
74
|
+
</nav>
|
|
75
|
+
)}
|
|
76
|
+
|
|
77
|
+
<div className="min-w-0 flex-1">{children}</div>
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { AdminUsersTable } from './AdminUsersTable';
|
|
4
|
+
import type { AdminUser } from '../types';
|
|
5
|
+
|
|
6
|
+
const users: AdminUser[] = [
|
|
7
|
+
{
|
|
8
|
+
id: 'u-1',
|
|
9
|
+
name: 'Alice Johnson',
|
|
10
|
+
email: 'alice@example.com',
|
|
11
|
+
roles: ['admin', 'owner'],
|
|
12
|
+
status: 'active',
|
|
13
|
+
createdAt: '2026-01-15T12:00:00Z',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: 'u-2',
|
|
17
|
+
name: 'Bob Smith',
|
|
18
|
+
email: 'bob@example.com',
|
|
19
|
+
roles: ['member'],
|
|
20
|
+
status: 'suspended',
|
|
21
|
+
createdAt: '2026-02-20T12:00:00Z',
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
describe('AdminUsersTable', () => {
|
|
26
|
+
it('renders user rows with names, emails, roles and statuses', () => {
|
|
27
|
+
render(<AdminUsersTable users={users} />);
|
|
28
|
+
expect(screen.getByText('Alice Johnson')).toBeTruthy();
|
|
29
|
+
expect(screen.getByText('alice@example.com')).toBeTruthy();
|
|
30
|
+
expect(screen.getByText('admin')).toBeTruthy();
|
|
31
|
+
expect(screen.getByText('owner')).toBeTruthy();
|
|
32
|
+
expect(screen.getByText('active')).toBeTruthy();
|
|
33
|
+
|
|
34
|
+
expect(screen.getByText('Bob Smith')).toBeTruthy();
|
|
35
|
+
expect(screen.getByText('bob@example.com')).toBeTruthy();
|
|
36
|
+
expect(screen.getByText('suspended')).toBeTruthy();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('filters users using internal search input', () => {
|
|
40
|
+
render(<AdminUsersTable users={users} />);
|
|
41
|
+
const searchInput = screen.getByPlaceholderText('Search users by name or email…');
|
|
42
|
+
fireEvent.change(searchInput, { target: { value: 'alice' } });
|
|
43
|
+
|
|
44
|
+
expect(screen.getByText('Alice Johnson')).toBeTruthy();
|
|
45
|
+
expect(screen.queryByText('Bob Smith')).toBeNull();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('handles action buttons: edit roles, moderate, and view details', () => {
|
|
49
|
+
const handleEditRoles = vi.fn();
|
|
50
|
+
const handleModerate = vi.fn();
|
|
51
|
+
const handleViewDetails = vi.fn();
|
|
52
|
+
|
|
53
|
+
render(
|
|
54
|
+
<AdminUsersTable
|
|
55
|
+
users={users}
|
|
56
|
+
onEditRoles={handleEditRoles}
|
|
57
|
+
onModerate={handleModerate}
|
|
58
|
+
onViewDetails={handleViewDetails}
|
|
59
|
+
/>,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
fireEvent.click(screen.getAllByLabelText('View user details')[0]!);
|
|
63
|
+
expect(handleViewDetails).toHaveBeenCalledWith(users[0]);
|
|
64
|
+
|
|
65
|
+
fireEvent.click(screen.getAllByLabelText('Edit roles')[0]!);
|
|
66
|
+
expect(handleEditRoles).toHaveBeenCalledWith(users[0]);
|
|
67
|
+
|
|
68
|
+
fireEvent.click(screen.getByLabelText('Suspend user'));
|
|
69
|
+
expect(handleModerate).toHaveBeenCalledWith(users[0], 'suspend');
|
|
70
|
+
|
|
71
|
+
fireEvent.click(screen.getByLabelText('Activate user'));
|
|
72
|
+
expect(handleModerate).toHaveBeenCalledWith(users[1], 'activate');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('renders empty state when users array is empty', () => {
|
|
76
|
+
render(<AdminUsersTable users={[]} emptyTitle="No registered users" />);
|
|
77
|
+
expect(screen.getByText('No registered users')).toBeTruthy();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { useMemo, useState, type ReactNode } from 'react';
|
|
2
|
+
import { Ban, Edit2, Eye, Trash2, UserCheck } from 'lucide-react';
|
|
3
|
+
import { Badge, Button, Input, NativeSelect } from '@umituz/web-design-system/atoms';
|
|
4
|
+
import { Avatar } from '@umituz/web-design-system/molecules';
|
|
5
|
+
import { Card, EmptyState } from '@umituz/web-design-system/organisms';
|
|
6
|
+
import { cn } from '@umituz/web-design-system/utils';
|
|
7
|
+
import type { AdminUser, AdminUserStatus, AdminUserStatusFilter } from '../types';
|
|
8
|
+
|
|
9
|
+
export interface AdminUsersTableProps {
|
|
10
|
+
readonly users: readonly AdminUser[];
|
|
11
|
+
readonly loading?: boolean;
|
|
12
|
+
readonly searchPlaceholder?: string;
|
|
13
|
+
readonly statusFilter?: AdminUserStatusFilter;
|
|
14
|
+
readonly onStatusFilterChange?: (filter: AdminUserStatusFilter) => void;
|
|
15
|
+
readonly onSearch?: (query: string) => void;
|
|
16
|
+
readonly onEditRoles?: (user: AdminUser) => void;
|
|
17
|
+
readonly onModerate?: (user: AdminUser, action: 'ban' | 'suspend' | 'activate') => void;
|
|
18
|
+
readonly onViewDetails?: (user: AdminUser) => void;
|
|
19
|
+
readonly onDelete?: (user: AdminUser) => void;
|
|
20
|
+
readonly actions?: (user: AdminUser) => ReactNode;
|
|
21
|
+
readonly emptyTitle?: string;
|
|
22
|
+
readonly emptyDescription?: string;
|
|
23
|
+
readonly className?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const STATUS_VARIANTS: Record<AdminUserStatus, 'success' | 'warning' | 'danger' | 'neutral'> = {
|
|
27
|
+
active: 'success',
|
|
28
|
+
suspended: 'warning',
|
|
29
|
+
banned: 'danger',
|
|
30
|
+
pending: 'neutral',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function AdminUsersTable({
|
|
34
|
+
users,
|
|
35
|
+
loading = false,
|
|
36
|
+
searchPlaceholder = 'Search users by name or email…',
|
|
37
|
+
statusFilter = 'all',
|
|
38
|
+
onStatusFilterChange,
|
|
39
|
+
onSearch,
|
|
40
|
+
onEditRoles,
|
|
41
|
+
onModerate,
|
|
42
|
+
onViewDetails,
|
|
43
|
+
onDelete,
|
|
44
|
+
actions,
|
|
45
|
+
emptyTitle = 'No users found',
|
|
46
|
+
emptyDescription = 'There are no users matching your filter or query.',
|
|
47
|
+
className,
|
|
48
|
+
}: AdminUsersTableProps) {
|
|
49
|
+
const [internalQuery, setInternalQuery] = useState('');
|
|
50
|
+
const [internalStatus, setInternalStatus] = useState<AdminUserStatusFilter>(statusFilter);
|
|
51
|
+
|
|
52
|
+
const activeStatus = onStatusFilterChange ? statusFilter : internalStatus;
|
|
53
|
+
|
|
54
|
+
const handleQueryChange = (q: string) => {
|
|
55
|
+
setInternalQuery(q);
|
|
56
|
+
onSearch?.(q);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const handleStatusChange = (s: AdminUserStatusFilter) => {
|
|
60
|
+
if (onStatusFilterChange) {
|
|
61
|
+
onStatusFilterChange(s);
|
|
62
|
+
} else {
|
|
63
|
+
setInternalStatus(s);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const filteredUsers = useMemo(() => {
|
|
68
|
+
if (onSearch || onStatusFilterChange) return users;
|
|
69
|
+
const q = internalQuery.trim().toLowerCase();
|
|
70
|
+
return users.filter((u) => {
|
|
71
|
+
if (activeStatus !== 'all' && u.status !== activeStatus) return false;
|
|
72
|
+
if (!q) return true;
|
|
73
|
+
return u.name.toLowerCase().includes(q) || u.email.toLowerCase().includes(q);
|
|
74
|
+
});
|
|
75
|
+
}, [users, internalQuery, activeStatus, onSearch, onStatusFilterChange]);
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Card className={cn('overflow-hidden', className)}>
|
|
79
|
+
<div className="flex flex-col gap-3 border-b border-line p-4 sm:flex-row sm:items-center sm:justify-between">
|
|
80
|
+
<div className="relative min-w-0 flex-1 max-w-sm">
|
|
81
|
+
<Input
|
|
82
|
+
value={internalQuery}
|
|
83
|
+
onChange={(e) => handleQueryChange(e.target.value)}
|
|
84
|
+
placeholder={searchPlaceholder}
|
|
85
|
+
className="w-full text-sm"
|
|
86
|
+
/>
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
<div className="flex items-center gap-2">
|
|
90
|
+
<NativeSelect
|
|
91
|
+
value={activeStatus}
|
|
92
|
+
onChange={(e) => handleStatusChange(e.target.value as AdminUserStatusFilter)}
|
|
93
|
+
aria-label="Filter users by status"
|
|
94
|
+
className="w-36 text-xs"
|
|
95
|
+
>
|
|
96
|
+
<option value="all">All statuses</option>
|
|
97
|
+
<option value="active">Active</option>
|
|
98
|
+
<option value="suspended">Suspended</option>
|
|
99
|
+
<option value="banned">Banned</option>
|
|
100
|
+
<option value="pending">Pending</option>
|
|
101
|
+
</NativeSelect>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
{loading ? (
|
|
106
|
+
<div className="flex min-h-[220px] items-center justify-center p-8 text-sm text-ink-3">
|
|
107
|
+
<span className="animate-pulse">Loading users…</span>
|
|
108
|
+
</div>
|
|
109
|
+
) : filteredUsers.length === 0 ? (
|
|
110
|
+
<div className="p-8">
|
|
111
|
+
<EmptyState title={emptyTitle} description={emptyDescription} />
|
|
112
|
+
</div>
|
|
113
|
+
) : (
|
|
114
|
+
<div className="overflow-x-auto">
|
|
115
|
+
<table className="w-full text-left border-collapse">
|
|
116
|
+
<thead>
|
|
117
|
+
<tr className="border-b border-line bg-surface-100 text-2xs font-semibold uppercase tracking-wider text-ink-3">
|
|
118
|
+
<th className="py-2.5 px-4">User</th>
|
|
119
|
+
<th className="py-2.5 px-4">Roles</th>
|
|
120
|
+
<th className="py-2.5 px-4">Status</th>
|
|
121
|
+
<th className="py-2.5 px-4">Created</th>
|
|
122
|
+
<th className="py-2.5 px-4 text-right">Actions</th>
|
|
123
|
+
</tr>
|
|
124
|
+
</thead>
|
|
125
|
+
<tbody className="divide-y divide-line text-sm">
|
|
126
|
+
{filteredUsers.map((user) => {
|
|
127
|
+
const dateStr = user.createdAt
|
|
128
|
+
? typeof user.createdAt === 'string'
|
|
129
|
+
? user.createdAt.slice(0, 10)
|
|
130
|
+
: new Date(user.createdAt).toISOString().slice(0, 10)
|
|
131
|
+
: '—';
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<tr key={user.id} className="transition-colors hover:bg-surface-50">
|
|
135
|
+
<td className="py-3 px-4">
|
|
136
|
+
<div className="flex items-center gap-3">
|
|
137
|
+
<Avatar name={user.name} size="sm" />
|
|
138
|
+
<div className="min-w-0">
|
|
139
|
+
<span className="block font-semibold text-ink leading-tight">{user.name}</span>
|
|
140
|
+
<span className="block text-xs text-ink-3 truncate">{user.email}</span>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
</td>
|
|
144
|
+
|
|
145
|
+
<td className="py-3 px-4">
|
|
146
|
+
<div className="flex flex-wrap gap-1">
|
|
147
|
+
{user.roles.map((r) => (
|
|
148
|
+
<Badge key={r} variant="outline" className="text-2xs capitalize">
|
|
149
|
+
{r}
|
|
150
|
+
</Badge>
|
|
151
|
+
))}
|
|
152
|
+
</div>
|
|
153
|
+
</td>
|
|
154
|
+
|
|
155
|
+
<td className="py-3 px-4">
|
|
156
|
+
<Badge variant={STATUS_VARIANTS[user.status]} className="capitalize text-2xs">
|
|
157
|
+
{user.status}
|
|
158
|
+
</Badge>
|
|
159
|
+
</td>
|
|
160
|
+
|
|
161
|
+
<td className="py-3 px-4 font-mono text-xs text-ink-3">{dateStr}</td>
|
|
162
|
+
|
|
163
|
+
<td className="py-3 px-4 text-right">
|
|
164
|
+
{actions ? (
|
|
165
|
+
actions(user)
|
|
166
|
+
) : (
|
|
167
|
+
<div className="flex items-center justify-end gap-1">
|
|
168
|
+
{onViewDetails && (
|
|
169
|
+
<Button
|
|
170
|
+
variant="ghost"
|
|
171
|
+
size="sm"
|
|
172
|
+
onClick={() => onViewDetails(user)}
|
|
173
|
+
aria-label="View user details"
|
|
174
|
+
className="h-8 w-8 p-0"
|
|
175
|
+
>
|
|
176
|
+
<Eye size={14} />
|
|
177
|
+
</Button>
|
|
178
|
+
)}
|
|
179
|
+
|
|
180
|
+
{onEditRoles && (
|
|
181
|
+
<Button
|
|
182
|
+
variant="ghost"
|
|
183
|
+
size="sm"
|
|
184
|
+
onClick={() => onEditRoles(user)}
|
|
185
|
+
aria-label="Edit roles"
|
|
186
|
+
className="h-8 w-8 p-0"
|
|
187
|
+
>
|
|
188
|
+
<Edit2 size={13} />
|
|
189
|
+
</Button>
|
|
190
|
+
)}
|
|
191
|
+
|
|
192
|
+
{onModerate && user.status === 'active' && (
|
|
193
|
+
<Button
|
|
194
|
+
variant="ghost"
|
|
195
|
+
size="sm"
|
|
196
|
+
onClick={() => onModerate(user, 'suspend')}
|
|
197
|
+
aria-label="Suspend user"
|
|
198
|
+
className="h-8 w-8 p-0 text-amber-600 hover:text-amber-700"
|
|
199
|
+
>
|
|
200
|
+
<Ban size={13} />
|
|
201
|
+
</Button>
|
|
202
|
+
)}
|
|
203
|
+
|
|
204
|
+
{onModerate && user.status !== 'active' && (
|
|
205
|
+
<Button
|
|
206
|
+
variant="ghost"
|
|
207
|
+
size="sm"
|
|
208
|
+
onClick={() => onModerate(user, 'activate')}
|
|
209
|
+
aria-label="Activate user"
|
|
210
|
+
className="h-8 w-8 p-0 text-emerald-600 hover:text-emerald-700"
|
|
211
|
+
>
|
|
212
|
+
<UserCheck size={14} />
|
|
213
|
+
</Button>
|
|
214
|
+
)}
|
|
215
|
+
|
|
216
|
+
{onDelete && (
|
|
217
|
+
<Button
|
|
218
|
+
variant="ghost"
|
|
219
|
+
size="sm"
|
|
220
|
+
onClick={() => onDelete(user)}
|
|
221
|
+
aria-label="Delete user"
|
|
222
|
+
className="h-8 w-8 p-0 text-rose-600 hover:text-rose-700"
|
|
223
|
+
>
|
|
224
|
+
<Trash2 size={13} />
|
|
225
|
+
</Button>
|
|
226
|
+
)}
|
|
227
|
+
</div>
|
|
228
|
+
)}
|
|
229
|
+
</td>
|
|
230
|
+
</tr>
|
|
231
|
+
);
|
|
232
|
+
})}
|
|
233
|
+
</tbody>
|
|
234
|
+
</table>
|
|
235
|
+
</div>
|
|
236
|
+
)}
|
|
237
|
+
</Card>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface AdminNavItem {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly label: string;
|
|
6
|
+
readonly href: string;
|
|
7
|
+
readonly icon?: ReactNode;
|
|
8
|
+
readonly badge?: ReactNode;
|
|
9
|
+
readonly exact?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type AdminUserStatus = 'active' | 'suspended' | 'banned' | 'pending';
|
|
13
|
+
|
|
14
|
+
export interface AdminUser<TMeta = Record<string, unknown>> {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly email: string;
|
|
18
|
+
readonly avatarUrl?: string;
|
|
19
|
+
readonly roles: readonly string[];
|
|
20
|
+
readonly status: AdminUserStatus;
|
|
21
|
+
readonly createdAt?: string | number | Date;
|
|
22
|
+
readonly lastActiveAt?: string | number | Date;
|
|
23
|
+
readonly metadata?: TMeta;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type AdminUserStatusFilter = 'all' | AdminUserStatus;
|
|
27
|
+
|
|
28
|
+
export interface AdminKpiItem {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly label: string;
|
|
31
|
+
readonly value: string | number;
|
|
32
|
+
readonly sub?: string;
|
|
33
|
+
readonly tone?: 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'neutral' | 'violet';
|
|
34
|
+
readonly icon?: ReactNode;
|
|
35
|
+
readonly change?: {
|
|
36
|
+
readonly value: number | string;
|
|
37
|
+
readonly trend: 'up' | 'down' | 'neutral';
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface AdminServiceCheck {
|
|
42
|
+
readonly name: string;
|
|
43
|
+
readonly status: 'ok' | 'warn' | 'fail';
|
|
44
|
+
readonly latencyMs?: number;
|
|
45
|
+
readonly message?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface AdminSystemHealth {
|
|
49
|
+
readonly status: 'healthy' | 'degraded' | 'down';
|
|
50
|
+
readonly latencyMs?: number;
|
|
51
|
+
readonly version?: string;
|
|
52
|
+
readonly uptime?: string;
|
|
53
|
+
readonly lastCheckedAt?: string | number | Date;
|
|
54
|
+
readonly checks?: readonly AdminServiceCheck[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface AdminTenantSummary {
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly name: string;
|
|
60
|
+
readonly slug?: string;
|
|
61
|
+
readonly plan: string;
|
|
62
|
+
readonly status: 'active' | 'suspended' | 'trial';
|
|
63
|
+
readonly usersCount?: number;
|
|
64
|
+
readonly mrr?: string | number;
|
|
65
|
+
readonly createdAt?: string | number | Date;
|
|
66
|
+
}
|
|
@@ -12,12 +12,17 @@ function normalizeStep(step: StepItem | string, index: number): StepItem {
|
|
|
12
12
|
export function Stepper({
|
|
13
13
|
steps,
|
|
14
14
|
currentStep,
|
|
15
|
+
currentIndex,
|
|
15
16
|
failStep,
|
|
17
|
+
failIndex,
|
|
16
18
|
orientation = 'horizontal',
|
|
17
19
|
clickable = false,
|
|
18
20
|
onStepClick,
|
|
19
21
|
className,
|
|
20
22
|
}: StepperProps) {
|
|
23
|
+
const activeIndex = currentStep ?? currentIndex ?? 0;
|
|
24
|
+
const failureIndex = failStep ?? failIndex;
|
|
25
|
+
|
|
21
26
|
return (
|
|
22
27
|
<div
|
|
23
28
|
className={cn(
|
|
@@ -31,8 +36,8 @@ export function Stepper({
|
|
|
31
36
|
{steps.map((rawStep, i) => {
|
|
32
37
|
const step = normalizeStep(rawStep, i);
|
|
33
38
|
const state =
|
|
34
|
-
|
|
35
|
-
const isClickable = clickable && !step.disabled && i <=
|
|
39
|
+
failureIndex === i ? 'fail' : i < activeIndex ? 'done' : i === activeIndex ? 'current' : 'pending';
|
|
40
|
+
const isClickable = clickable && !step.disabled && i <= activeIndex;
|
|
36
41
|
|
|
37
42
|
return (
|
|
38
43
|
<div
|
|
@@ -11,8 +11,10 @@ export interface StepItem {
|
|
|
11
11
|
|
|
12
12
|
export interface StepperProps {
|
|
13
13
|
readonly steps: readonly StepItem[] | readonly string[];
|
|
14
|
-
readonly currentStep
|
|
14
|
+
readonly currentStep?: number;
|
|
15
|
+
readonly currentIndex?: number;
|
|
15
16
|
readonly failStep?: number;
|
|
17
|
+
readonly failIndex?: number;
|
|
16
18
|
readonly orientation?: 'horizontal' | 'vertical';
|
|
17
19
|
readonly clickable?: boolean;
|
|
18
20
|
readonly onStepClick?: (stepIndex: number) => void;
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './domains/settings';
|
|
|
4
4
|
export * from './domains/calendar';
|
|
5
5
|
export * from './domains/kanban';
|
|
6
6
|
export * from './domains/activity';
|
|
7
|
+
export * from './domains/admin';
|
|
7
8
|
export * from './domains/filters';
|
|
8
9
|
export * from './domains/stepper';
|
|
9
10
|
export * from './domains/permissions';
|