From 0bfed1adf29663585c2aef0e321b0986f85edef2 Mon Sep 17 00:00:00 2001 From: R0m1k3 Date: Fri, 10 Apr 2026 11:45:57 +0200 Subject: [PATCH] feat: implement admin dashboard with authentication and title management capabilities --- app/actions/admin.ts | 19 ++++++++ app/admin/page.tsx | 7 +++ app/page.tsx | 5 ++- components/EditTitleForm.tsx | 85 ++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 components/EditTitleForm.tsx diff --git a/app/actions/admin.ts b/app/actions/admin.ts index 1441b2e..d8e0c74 100644 --- a/app/actions/admin.ts +++ b/app/actions/admin.ts @@ -105,3 +105,22 @@ export async function deleteButton(id: number) { revalidatePath('/admin'); revalidatePath('/'); } + +/** + * Update global app title. + */ +export async function updateAppTitle(formData: FormData) { + if (!(await isAuthenticated())) throw new Error('Non autorisé'); + + const title = formData.get('title') as string; + if (!title) throw new Error('Titre requis.'); + + await prisma.config.upsert({ + where: { id: 'app_title' }, + update: { value: title }, + create: { id: 'app_title', value: title }, + }); + + revalidatePath('/admin'); + revalidatePath('/'); +} diff --git a/app/admin/page.tsx b/app/admin/page.tsx index e05994c..24e1a1f 100644 --- a/app/admin/page.tsx +++ b/app/admin/page.tsx @@ -6,6 +6,7 @@ import { LogOut, ArrowLeft, Trash2 } from 'lucide-react'; import Link from 'next/link'; import { AddButtonForm } from '@/components/AddButtonForm'; import { AdminButtonRow } from '@/components/AdminButtonRow'; +import { EditTitleForm } from '@/components/EditTitleForm'; export const dynamic = 'force-dynamic'; @@ -17,6 +18,9 @@ export default async function AdminPage() { orderBy: { order: 'asc' }, }); + const titleConfig = await prisma.config.findUnique({ where: { id: 'app_title' } }); + const appTitle = titleConfig?.value || 'Menu Application'; + return (
@@ -70,6 +74,9 @@ export default async function AdminPage() {
+ {/* Edit Title Form */} + + {/* Add form */} diff --git a/app/page.tsx b/app/page.tsx index 5a15048..3d40a6d 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -16,6 +16,9 @@ export default async function Home() { orderBy: { order: 'asc' }, }); + const titleConfig = await prisma.config.findUnique({ where: { id: 'app_title' } }); + const appTitle = titleConfig?.value || 'Menu Application'; + return (
@@ -66,7 +69,7 @@ export default async function Home() { letterSpacing: '-0.04em', color: 'var(--fg)', }}> - Menu Application + {appTitle} {buttons.length > 0 && (

diff --git a/components/EditTitleForm.tsx b/components/EditTitleForm.tsx new file mode 100644 index 0000000..77d6c4f --- /dev/null +++ b/components/EditTitleForm.tsx @@ -0,0 +1,85 @@ +'use client'; + +import React, { useState } from 'react'; +import { updateAppTitle } from '@/app/actions/admin'; +import { Type } from 'lucide-react'; + +interface EditTitleFormProps { + currentTitle: string; +} + +export function EditTitleForm({ currentTitle }: EditTitleFormProps) { + const [loading, setLoading] = useState(false); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setLoading(true); + const formData = new FormData(e.currentTarget); + try { + await updateAppTitle(formData); + } finally { + setLoading(false); + } + }; + + return ( +

+

+ TITRE DE L'APPLICATION +

+ +
+
+ + +
+ + + +
+
+ ); +}