"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; const SPORT_LABEL: Record = { "muay-thai": { icon: "🥊", name: "Muay Thai" }, yoga: { icon: "🧘", name: "Yoga" }, }; export default function AdminClasses({ slots }: { slots: any[] }) { const router = useRouter(); return (

📅 Cours & places disponibles

Renseigne le nombre de places pour chaque cours. Quand les places sont épuisées, le cours s'affiche « COMPLET » sur le site.

{slots.map((slot) => ( router.refresh()} /> ))}
); } function SlotCard({ slot, onUpdate }: { slot: any; onUpdate: () => void }) { const sport = SPORT_LABEL[slot.sport] || { icon: "🏅", name: slot.sport }; const [capacity, setCapacity] = useState(String(slot.capacity)); const [booked, setBooked] = useState(String(slot.booked)); const [isFull, setIsFull] = useState(slot.isFull); const [saving, setSaving] = useState(false); const capacityNum = Math.max(0, parseInt(capacity) || 0); const bookedNum = Math.max(0, parseInt(booked) || 0); const remaining = Math.max(0, capacityNum - bookedNum); const full = isFull || remaining === 0; async function save() { setSaving(true); const res = await fetch("/api/admin/classes", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id: slot.id, capacity, booked, isFull }), }); setSaving(false); if (res.ok) onUpdate(); } return (
{sport.icon}

{sport.name} — {slot.label}

{slot.time}

{full ? "❌ COMPLET" : `${remaining} places libres`}
setCapacity(e.target.value)} />
setBooked(e.target.value)} />
); }