fix: improve error handling in admin pages to show user-friendly error messages
- Add error display to help questions new/edit pages - Improve error visibility in admin-badges, admin-applications, admin-logs, admin-users pages - Update createHelpQuestion action to properly handle and display unique name collisions and database errors - Add user-friendly error messages to admin error handling - Enhances admin page error reporting for better user experience
This commit is contained in:
1 parent
d775e893f4
commit
0323c3fcaa
13 files changed
+222
-221
No files matched your search
@@ -51,7 +51,6 @@ export default async function AdminStaffActivities({
|
||||
select: {
|
||||
id: true,
|
||||
userId: true,
|
||||
username: true,
|
||||
action: true,
|
||||
description: true,
|
||||
targetType: true,
|
||||
@@ -65,7 +64,17 @@ export default async function AdminStaffActivities({
|
||||
})
|
||||
.catch(() => []);
|
||||
|
||||
const staffIds = Array.from(new Set(activities.map((a) => Number(a.userId)))).filter((n) => n > 0);
|
||||
let nameById = new Map<number, string>();
|
||||
if (staffIds.length) {
|
||||
const users = await prisma.user
|
||||
.findMany({ where: { id: { in: staffIds } }, select: { id: true, username: true } })
|
||||
.catch(() => []);
|
||||
nameById = new Map(users.map((x) => [x.id, x.username]));
|
||||
}
|
||||
|
||||
const total = await prisma.staffActivities.count({ where: whereClause }).catch(() => 0);
|
||||
|
||||
const pages = Math.max(1, Math.ceil(total / PER_PAGE));
|
||||
|
||||
const onlineCount = activities.filter((a) => a.createdAt && new Date(a.createdAt).getTime() > Date.now() - 60000).length;
|
||||
@@ -104,12 +113,13 @@ export default async function AdminStaffActivities({
|
||||
placeholder="Staff ID"
|
||||
style={{ width: 120 }}
|
||||
/>
|
||||
<input
|
||||
name="action"
|
||||
defaultValue={action}
|
||||
placeholder="Action type (e.g., rank_change)"
|
||||
style={{ width: 160 }}
|
||||
/>
|
||||
<input
|
||||
name="action"
|
||||
defaultValue={action ?? ""}
|
||||
placeholder="Action type (e.g., rank_change)"
|
||||
style={{ width: 160 }}
|
||||
/>
|
||||
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Filter
|
||||
</button>
|
||||
@@ -141,7 +151,7 @@ export default async function AdminStaffActivities({
|
||||
{activities.map((a) => (
|
||||
<tr key={String(a.id)}>
|
||||
<td className="muted" style={{ whiteSpace: "nowrap" }}>{fromDate(a.createdAt)}</td>
|
||||
<td className="muted">#{a.userId} ({a.username ?? "unknown"})</td>
|
||||
<td className="muted">#{Number(a.userId)} ({nameById.get(Number(a.userId)) ?? "unknown"})</td>
|
||||
<td>
|
||||
<span className="admin-badge">{a.action}</span>
|
||||
</td>
|
||||
|
||||
Reference in new issue
Block a user