From 0323c3fcaa7edebd31088773237a6c2c322a52dd Mon Sep 17 00:00:00 2001 From: remco Date: Wed, 1 Jul 2026 21:25:30 +0200 Subject: [PATCH] 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 --- prod.log | 8 + src/actions/admin-help.ts | 7 +- src/app/admin/help-questions/[id]/page.tsx | 8 + src/app/admin/help-questions/new/page.tsx | 13 +- src/app/admin/logs/page.tsx | 26 ++- src/app/admin/users/page.tsx | 192 ++++++++------------- src/app/api/admin/users/actions/route.ts | 12 +- src/app/globals.css | 10 +- src/components/admin/dashboard.tsx | 2 + src/components/language-switcher.tsx | 11 +- src/components/navbar-color-picker.tsx | 13 +- src/components/navigation.tsx | 6 +- src/components/top-header.tsx | 135 ++++++++------- 13 files changed, 222 insertions(+), 221 deletions(-) create mode 100644 prod.log diff --git a/prod.log b/prod.log new file mode 100644 index 00000000..d592674e --- /dev/null +++ b/prod.log @@ -0,0 +1,8 @@ + +> start +> next start + +▲ Next.js 16.2.9 +- Local: http://localhost:3000 +- Network: http://5.252.100.130:3000 +✓ Ready in 93ms diff --git a/src/actions/admin-help.ts b/src/actions/admin-help.ts index d5ed50b2..89254c06 100644 --- a/src/actions/admin-help.ts +++ b/src/actions/admin-help.ts @@ -48,11 +48,12 @@ export async function createHelpQuestion(formData: FormData): Promise { targetType: "help_center_category", targetId: Number(entry.id), }); - } catch { - // Unique name collision or DB error — re-render unchanged. + } catch (error) { + // Unique name collision or DB error — re-render unchanged with error. revalidatePath("/admin/help-questions"); - return; + redirect("/admin/help-questions/new?error=Unique name collision or database error. Please try again."); } + revalidatePath("/admin/help-questions"); redirect("/admin/help-questions"); } diff --git a/src/app/admin/help-questions/[id]/page.tsx b/src/app/admin/help-questions/[id]/page.tsx index e94ed7cd..571c477d 100644 --- a/src/app/admin/help-questions/[id]/page.tsx +++ b/src/app/admin/help-questions/[id]/page.tsx @@ -7,10 +7,13 @@ export const dynamic = "force-dynamic"; export default async function EditHelpQuestion({ params, + searchParams, }: { params: Promise<{ id: string }>; + searchParams: Promise<{ error?: string }>; }) { const { id } = await params; + const { error } = await searchParams; let entry: Awaited< ReturnType > = null; @@ -29,6 +32,11 @@ export default async function EditHelpQuestion({ ← Help Center

Edit help-center entry

+ {error ? ( +

+ Error: {error} +

+ ) : null}
diff --git a/src/app/admin/help-questions/new/page.tsx b/src/app/admin/help-questions/new/page.tsx index 9422beb3..11798b83 100644 --- a/src/app/admin/help-questions/new/page.tsx +++ b/src/app/admin/help-questions/new/page.tsx @@ -1,13 +1,24 @@ import Link from "next/link"; import { createHelpQuestion } from "@/actions/admin-help"; -export default function NewHelpQuestion() { +export default async function NewHelpQuestion({ + searchParams, +}: { + searchParams: Promise<{ error?: string }>; +}) { + const { error } = await searchParams; + return (

← Help Center

New help-center entry

+ {error ? ( +

+ Error: {error} +

+ ) : null}