-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpage.tsx
More file actions
224 lines (213 loc) · 6.78 KB
/
page.tsx
File metadata and controls
224 lines (213 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
"use client";
import { Card } from "@repo/ui";
import { useTRPC } from "~/server/client";
import { useQuery } from "@tanstack/react-query";
import type { AppRouter } from "~/server/routers";
// Define type for the stats object returned by the API
type SystemStatsQueryProcedure = AppRouter["admin"]["system"]["getStats"];
type SystemStats = Awaited<ReturnType<SystemStatsQueryProcedure>>;
// Define type for the static part, adding a key to link to API data
interface StaticStatData {
title: string;
icon: React.ReactNode;
key: keyof SystemStats; // Key to match the field in SystemStats
}
// TODO: Make stats clickable and redirect to the respective page
// Define static parts outside the component with explicit type and key
const staticStatsData: StaticStatData[] = [
{
title: "Total Pages",
key: "pageCount",
icon: (
<svg
xmlns="http://www.w3.org/2000/svg"
className="text-primary-400 h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
/>
</svg>
),
},
{
title: "Total Tags",
key: "tagCount",
icon: (
<svg
xmlns="http://www.w3.org/2000/svg"
className="text-secondary-400 h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M12.586 2.586a2 2 0 00-2.828 0L7 5.172V4a1 1 0 10-2 0v4.5a.5.5 0 00.146.354l6.5 6.5a2 2 0 002.828 0l4.5-4.5a2 2 0 000-2.828l-6.914-6.914zM6 8.5a1.5 1.5 0 11-3 0 1.5 1.5 0 013 0z"
/>
</svg>
),
},
{
title: "Total Assets",
key: "assetCount",
icon: (
<svg
xmlns="http://www.w3.org/2000/svg"
className="text-accent-400 h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
/>
</svg>
),
},
{
title: "Total Users",
key: "userCount",
icon: (
<svg
xmlns="http://www.w3.org/2000/svg"
className="text-secondary-400 h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"
/>
</svg>
),
},
{
title: "User Groups",
key: "groupCount",
icon: (
<svg
xmlns="http://www.w3.org/2000/svg"
className="text-complementary-400 h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"
/>
</svg>
),
},
];
export default function AdminDashboardPage() {
// Fetch system stats using tRPC and TanStack Query
const trpc = useTRPC();
const {
data: statsData,
isLoading,
error,
} = useQuery(trpc.admin.system.getStats.queryOptions());
// Handle error state
if (error) {
return (
<div>Error loading system stats: {error.message}. Check permissions.</div>
);
}
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-bold">Admin Dashboard</h1>
<p className="text-text-secondary">Overview of your NextWiki system</p>
</div>
<div className="grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-5">
{staticStatsData.map((statDef) => (
<Card key={statDef.key} className="p-6">
<div className="flex items-center">
<div className="bg-background-level1 rounded-full p-3">
{statDef.icon}
</div>
<div className="ml-4">
<p className="text-text-secondary text-sm font-medium">
{statDef.title}
</p>
<p className="text-2xl font-semibold">
{isLoading || !statsData ? (
<span className="bg-background-level1 inline-block h-8 w-16 animate-pulse rounded"></span>
) : (
statsData[statDef.key]
)}
</p>
</div>
</div>
</Card>
))}
</div>
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
<Card className="p-6">
<h2 className="mb-4 text-lg font-medium">Recent Pages</h2>
{isLoading ? (
<div className="space-y-4">
{[...Array(3)].map((_, i) => (
<div
key={i}
className="bg-background-level1 h-12 animate-pulse rounded"
></div>
))}
</div>
) : (
<div className="space-y-4">
<p className="text-text-secondary">
Recent page activity will be shown here
</p>
</div>
)}
</Card>
<Card className="p-6">
<h2 className="mb-4 text-lg font-medium">System Health</h2>
{isLoading ? (
<div className="space-y-4">
{[...Array(3)].map((_, i) => (
<div
key={i}
className="bg-background-level1 h-12 animate-pulse rounded"
></div>
))}
</div>
) : (
<div className="space-y-4">
<div className="flex items-center justify-between">
<span>Database</span>
<span className="text-success-500">Healthy</span>
</div>
<div className="flex items-center justify-between">
<span>Storage</span>
<span className="text-success-500">Healthy</span>
</div>
<div className="flex items-center justify-between">
<span>Cache</span>
<span className="text-success-500">Healthy</span>
</div>
</div>
)}
</Card>
</div>
</div>
);
}