-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
208 lines (190 loc) · 9.3 KB
/
Copy pathadmin.html
File metadata and controls
208 lines (190 loc) · 9.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Acad3micFlow - Admin Panel</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
body {
font-family: 'Inter', sans-serif;
}
.glass {
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(10px);
}
</style>
</head>
<body class="bg-[#0c0c0c] text-gray-200 min-h-screen flex">
<!-- Sidebar -->
<aside class="w-64 bg-[#090909] border-r border-white/10 hidden md:flex flex-col">
<div class="p-6">
<h1 class="text-xl font-bold bg-gradient-to-r from-indigo-400 to-purple-400 bg-clip-text text-transparent">
Acad3mic Admin</h1>
</div>
<nav class="flex-1 p-4 space-y-2">
<button class="w-full text-left p-3 rounded-xl bg-white/5 border border-white/10 flex items-center gap-3">
<i class="fa-solid fa-chart-line opacity-60"></i> Dashboard
</button>
<button
class="w-full text-left p-3 rounded-xl hover:bg-white/5 transition-all flex items-center gap-3 text-gray-400">
<i class="fa-solid fa-users opacity-60"></i> Users
</button>
<button
class="w-full text-left p-3 rounded-xl hover:bg-white/5 transition-all flex items-center gap-3 text-gray-400">
<i class="fa-solid fa-credit-card opacity-60"></i> Transactions
</button>
</nav>
<div class="p-4 border-t border-white/10">
<a href="index.html"
class="flex items-center gap-3 p-3 rounded-xl hover:bg-white/5 transition-all text-sm text-gray-400">
<i class="fa-solid fa-arrow-left"></i> Back to Chat
</a>
</div>
</aside>
<!-- Main Content -->
<main class="flex-1 overflow-y-auto p-6 md:p-10 space-y-8">
<div class="flex justify-between items-center">
<h2 class="text-2xl font-bold">System Overview</h2>
<div id="last-updated" class="text-xs text-gray-500 italic">Last updated: Just now</div>
</div>
<!-- Stats Grid -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="glass border border-white/10 p-6 rounded-3xl space-y-2">
<p class="text-sm text-gray-400">Total Users</p>
<h3 id="stat-users" class="text-3xl font-bold">--</h3>
<div class="text-[10px] text-green-400 flex items-center gap-1">
<i class="fa-solid fa-arrow-up"></i> 12% from last week
</div>
</div>
<div class="glass border border-white/10 p-6 rounded-3xl space-y-2">
<p class="text-sm text-gray-400">Conversations</p>
<h3 id="stat-chats" class="text-3xl font-bold">--</h3>
<div class="text-[10px] text-indigo-400 flex items-center gap-1">
<i class="fa-solid fa-message"></i> Active system load
</div>
</div>
<div class="glass border border-white/10 p-6 rounded-3xl space-y-2">
<p class="text-sm text-gray-400">Circulating Credits</p>
<h3 id="stat-credits" class="text-3xl font-bold">--</h3>
<div class="text-[10px] text-gray-500">System economy value</div>
</div>
</div>
<!-- Users Table -->
<div class="space-y-4">
<h3 class="text-xl font-semibold">Registered Users</h3>
<div class="glass border border-white/10 rounded-3xl overflow-hidden">
<table class="w-full text-left text-sm">
<thead class="bg-white/5 border-b border-white/10">
<tr>
<th class="p-4 font-medium">User</th>
<th class="p-4 font-medium">Credits</th>
<th class="p-4 font-medium">Status</th>
<th class="p-4 font-medium">Actions</th>
</tr>
</thead>
<tbody id="user-table-body">
<!-- Users populated here -->
</tbody>
</table>
</div>
</div>
</main>
<!-- Credit Modal (Hidden) -->
<div id="modal" class="fixed inset-0 bg-black/80 backdrop-blur-sm hidden flex items-center justify-center p-4 z-50">
<div class="glass border border-white/10 w-full max-w-md rounded-3xl p-8 space-y-6">
<h3 class="text-xl font-bold">Adjust Credits</h3>
<p id="modal-user-email" class="text-sm text-gray-400"></p>
<input id="credit-amount" type="number" placeholder="Amount to add/remove"
class="w-full bg-white/5 border border-white/10 p-4 rounded-xl outline-none focus:border-indigo-500 transition-all">
<div class="flex gap-3">
<button onclick="closeModal()"
class="flex-1 p-3 rounded-xl border border-white/10 hover:bg-white/5">Cancel</button>
<button onclick="confirmAddCredits()"
class="flex-1 p-3 rounded-xl bg-indigo-600 hover:bg-indigo-700">Confirm</button>
</div>
</div>
</div>
<script>
const API_BASE = ""; // Same origin
let selectedUserId = null;
async function init() {
await fetchStats();
await fetchUsers();
}
async function fetchStats() {
try {
const res = await fetch(`${API_BASE}/admin/stats`, {
headers: { 'Authorization': 'Bearer ' + localStorage.getItem('token') }
});
const data = await res.json();
document.getElementById('stat-users').innerText = data.total_users;
document.getElementById('stat-chats').innerText = data.total_conversations;
document.getElementById('stat-credits').innerText = data.total_credits_in_circulation.toFixed(1);
} catch (err) {
console.error("Stats fail", err);
}
}
async function fetchUsers() {
try {
const res = await fetch(`${API_BASE}/admin/users`, {
headers: { 'Authorization': 'Bearer ' + localStorage.getItem('token') }
});
const users = await res.json();
const container = document.getElementById('user-table-body');
container.innerHTML = users.map(user => `
<tr class="border-b border-white/5 hover:bg-white/5 transition-all">
<td class="p-4">
<div class="flex items-center gap-3">
<div class="w-8 h-8 rounded-lg bg-indigo-600/20 text-indigo-400 flex items-center justify-center font-bold text-xs">
${user.email[0].toUpperCase()}
</div>
<div>
<p class="font-medium">${user.display_name || 'No Name'}</p>
<p class="text-[10px] text-gray-500">${user.email}</p>
</div>
</div>
</td>
<td class="p-4 font-mono text-indigo-400">${user.credits.toFixed(1)}</td>
<td class="p-4">
<span class="px-2 py-0.5 rounded-full bg-green-500/10 text-green-400 text-[10px] border border-green-500/20">Active</span>
</td>
<td class="p-4">
<button onclick="openModal(${user.id}, '${user.email}')" class="text-xs text-gray-400 hover:text-white transition-all underline decoration-white/20">Manage Credits</button>
</td>
</tr>
`).join('');
} catch (err) {
console.error("Users fail", err);
}
}
function openModal(id, email) {
selectedUserId = id;
document.getElementById('modal-user-email').innerText = `Adding credits to: ${email}`;
document.getElementById('modal').classList.remove('hidden');
}
function closeModal() {
document.getElementById('modal').classList.add('hidden');
}
async function confirmAddCredits() {
const amount = parseFloat(document.getElementById('credit-amount').value);
if (!amount) return;
try {
const res = await fetch(`${API_BASE}/admin/users/${selectedUserId}/add-credits?amount=${amount}`, {
method: 'POST',
headers: { 'Authorization': 'Bearer ' + localStorage.getItem('token') }
});
if (res.ok) {
closeModal();
init();
}
} catch (err) {
alert("Action failed");
}
}
init();
</script>
</body>
</html>