"use client"; import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import { formatDate } from "@/lib/date-utils"; import DashboardSidebar from "@/components/DashboardSidebar"; import { useSession } from "next-auth/react"; export default function PhotoboxDetailPage({ params, }: { params: { id: string }; }) { const router = useRouter(); const { data: session } = useSession(); const [photobox, setPhotobox] = useState(null); const [loading, setLoading] = useState(true); const [editing, setEditing] = useState(false); const [formData, setFormData] = useState({ status: "", description: "", }); useEffect(() => { fetchPhotobox(); }, [params.id]); const fetchPhotobox = async () => { try { const res = await fetch(`/api/photoboxes/${params.id}`); const data = await res.json(); setPhotobox(data.photobox); setFormData({ status: data.photobox.status, description: data.photobox.description || "", }); } catch (error) { console.error("Fetch error:", error); } finally { setLoading(false); } }; const handleUpdate = async (e: React.FormEvent) => { e.preventDefault(); try { const res = await fetch(`/api/photoboxes/${params.id}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify(formData), }); if (res.ok) { setEditing(false); fetchPhotobox(); } else { alert("Fehler beim Aktualisieren"); } } catch (error) { console.error("Update error:", error); alert("Fehler beim Aktualisieren"); } }; const handleDelete = async () => { if (!confirm("Möchten Sie diese Fotobox wirklich löschen?")) return; try { const res = await fetch(`/api/photoboxes/${params.id}`, { method: "DELETE", }); if (res.ok) { router.push("/dashboard/photoboxes"); } else { alert("Fehler beim Löschen"); } } catch (error) { console.error("Delete error:", error); alert("Fehler beim Löschen"); } }; if (loading) { return (

Lädt...

); } if (!photobox) { return (

Fotobox nicht gefunden

); } const getModelLabel = (model: string) => { const labels: Record = { VINTAGE_SMILE: "Vintage Smile", VINTAGE_PHOTOS: "Vintage Photos", NOSTALGIE: "Nostalgie", MAGIC_MIRROR: "Magic Mirror", }; return labels[model] || model; }; return (

{getModelLabel(photobox.model)}

SN: {photobox.serialNumber}

{editing ? (