mirror of
https://github.com/R0m1k3/Menu.git
synced 2026-10-11 17:28:28 +02:00
feat: implement admin dashboard with authentication and title management capabilities
This commit is contained in:
1 parent
d253eff0fa
commit
0bfed1adf2
4 files changed
+115
-1
No files matched your search
@@ -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('/');
|
||||
}
|
||||
@@ -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 (
|
||||
<div style={{ minHeight: '100vh', padding: '1.5rem 2rem', maxWidth: '860px', margin: '0 auto' }}>
|
||||
|
||||
@@ -70,6 +74,9 @@ export default async function AdminPage() {
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Edit Title Form */}
|
||||
<EditTitleForm currentTitle={appTitle} />
|
||||
|
||||
{/* Add form */}
|
||||
<AddButtonForm />
|
||||
|
||||
|
||||
+4
-1
@@ -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 (
|
||||
<div style={{ minHeight: '100vh', display: 'flex', flexDirection: 'column' }}>
|
||||
|
||||
@@ -66,7 +69,7 @@ export default async function Home() {
|
||||
letterSpacing: '-0.04em',
|
||||
color: 'var(--fg)',
|
||||
}}>
|
||||
Menu Application
|
||||
{appTitle}
|
||||
</h1>
|
||||
{buttons.length > 0 && (
|
||||
<p style={{ color: 'var(--fg-muted)', fontSize: '0.9rem', marginTop: '0.4rem', fontWeight: 500 }}>
|
||||
|
||||
@@ -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<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const formData = new FormData(e.currentTarget);
|
||||
try {
|
||||
await updateAppTitle(formData);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
position: 'relative',
|
||||
zIndex: 45,
|
||||
background: 'var(--card-bg)',
|
||||
backdropFilter: 'blur(24px)',
|
||||
WebkitBackdropFilter: 'blur(24px)',
|
||||
border: '1px solid var(--card-border)',
|
||||
borderRadius: '20px',
|
||||
padding: '1.75rem',
|
||||
marginBottom: '2rem',
|
||||
}}>
|
||||
<h2 style={{
|
||||
fontSize: '0.78rem',
|
||||
fontWeight: 700,
|
||||
color: 'var(--fg-muted)',
|
||||
marginBottom: '1.25rem',
|
||||
letterSpacing: '0.08em',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: '0.5rem',
|
||||
}}>
|
||||
<Type size={14} /> TITRE DE L'APPLICATION
|
||||
</h2>
|
||||
|
||||
<form onSubmit={handleSubmit} style={{ display: 'flex', gap: '0.75rem', flexWrap: 'wrap', alignItems: 'flex-end' }}>
|
||||
<div style={{ flex: '1 1 200px' }}>
|
||||
<label style={{ display: 'block', fontSize: '0.72rem', fontWeight: 700, color: 'var(--fg-muted)', marginBottom: '0.45rem', letterSpacing: '0.06em' }}>
|
||||
TITRE AFFICHÉ
|
||||
</label>
|
||||
<input name="title" type="text" defaultValue={currentTitle} required />
|
||||
</div>
|
||||
|
||||
<button
|
||||
className="save-title-btn"
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
style={{
|
||||
background: 'var(--accent-btn-hover)',
|
||||
border: '1px solid var(--card-border)',
|
||||
color: 'var(--fg)',
|
||||
padding: '0.78rem 1.25rem',
|
||||
borderRadius: '12px',
|
||||
fontWeight: 600,
|
||||
fontSize: '0.88rem',
|
||||
cursor: 'pointer',
|
||||
whiteSpace: 'nowrap',
|
||||
flexShrink: 0,
|
||||
transition: 'all 200ms ease',
|
||||
opacity: loading ? 0.6 : 1,
|
||||
}}
|
||||
>
|
||||
{loading ? '…' : 'Enregistrer'}
|
||||
</button>
|
||||
<style>{`
|
||||
.save-title-btn:hover { background: var(--success) !important; border-color: transparent !important; color: #fff !important; }
|
||||
`}</style>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user