import { prisma } from '@/lib/db'; import { isAuthenticated, logoutAdmin, deleteButton } from '@/app/actions/admin'; import { redirect } from 'next/navigation'; import { ThemeToggle } from '@/components/ThemeToggle'; import { LogOut, ArrowLeft, Trash2, Globe } from 'lucide-react'; import Image from 'next/image'; import Link from 'next/link'; import { AddButtonForm } from '@/components/AddButtonForm'; export const dynamic = 'force-dynamic'; function getDomain(url: string): string { try { return new URL(url).hostname; } catch { return url; } } export default async function AdminPage() { const auth = await isAuthenticated(); if (!auth) redirect('/admin/login'); const buttons = await prisma.button.findMany({ orderBy: { order: 'asc' }, }); return (
{/* Header */}

Administration

{buttons.length} application{buttons.length !== 1 ? 's' : ''} configurée{buttons.length !== 1 ? 's' : ''}

{/* Add form */} {/* Button list */} {buttons.length === 0 ? (
Aucun bouton configuré.
) : (
{(buttons as any[]).map((btn) => { const domain = getDomain(btn.url); const faviconUrl = `https://www.google.com/s2/favicons?domain=${domain}&sz=32`; return (
{/* Icon: emoji or favicon */}
{btn.icon ? btn.icon : ( {btn.name} )}
{btn.name}
{btn.url}
{ 'use server'; await deleteButton(btn.id); }}>
); })}
)}
); }