import { LogoutButton } from "@/components/ui/LogoutButton"; import { auth } from "@/lib/auth"; import { deleteTutorial, getAllTutorials } from "@/lib/tutorials"; import { CalendarDaysOutlined, PenToSquareOutlined, PlusOutlined, Trash3Outlined, } from "@lineiconshq/free-icons"; import { Lineicons } from "@lineiconshq/react-lineicons"; import { revalidatePath } from "next/cache"; import Link from "next/link"; import { redirect } from "next/navigation"; export const dynamic = "force-dynamic"; async function handleDelete(formData: FormData) { "use server"; const session = await auth(); if (!session) { throw new Error("Non autorisé"); } const id = formData.get("id")?.toString(); if (!id) throw new Error("ID manquant"); await deleteTutorial(id); revalidatePath("/dashboard"); revalidatePath("/"); } export default async function DashboardPage() { const session = await auth(); if (!session) { redirect("/login"); } const tutorials = await getAllTutorials(); return (
{/* Header */}

Tutoriels

{tutorials.length} tutoriel {tutorials.length > 1 ? "s" : ""}

Nouveau tutoriel
{/* Liste */} {tutorials.length === 0 ? (

Aucun tutoriel pour l'instant

) : (
{/* Table header */}
Titre
Catégorie
Difficulté
Date
Actions
{/* Table body */}
{tutorials.map((tuto) => (
{tuto.title}

/{tuto.slug}

{tuto.category.name}
{new Date(tuto.date).toLocaleDateString( "fr-FR", { day: "2-digit", month: "2-digit", } )}
Éditer
))}
)}
); } function DifficultyBadge({ level }: { level: string }) { const colors: Record = { Débutant: "bg-emerald-500/20 text-emerald-400 border-emerald-500/30", Intermédiaire: "bg-amber-500/20 text-amber-400 border-amber-500/30", Avancé: "bg-rose-500/20 text-rose-400 border-rose-500/30", }; return ( {level} ); }