'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import DashboardSidebar from '@/components/DashboardSidebar'; import { useSession } from 'next-auth/react'; export default function PhotoboxesPage() { const router = useRouter(); const { data: session } = useSession(); const [photoboxes, setPhotoboxes] = useState([]); const [loading, setLoading] = useState(true); const [showForm, setShowForm] = useState(false); const [locations, setLocations] = useState([]); const [formData, setFormData] = useState({ locationId: '', model: 'VINTAGE_SMILE', serialNumber: '', description: '', }); useEffect(() => { fetchPhotoboxes(); fetchLocations(); }, []); const fetchPhotoboxes = async () => { try { const res = await fetch('/api/photoboxes'); const data = await res.json(); setPhotoboxes(data.photoboxes || []); } catch (error) { console.error('Fetch error:', error); } finally { setLoading(false); } }; const fetchLocations = async () => { try { const res = await fetch('/api/locations'); const data = await res.json(); setLocations(data.locations || []); } catch (error) { console.error('Locations fetch error:', error); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { const res = await fetch('/api/photoboxes', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData), }); if (res.ok) { setShowForm(false); setFormData({ locationId: '', model: 'VINTAGE_SMILE', serialNumber: '', description: '', }); fetchPhotoboxes(); } else { alert('Fehler beim Erstellen'); } } catch (error) { console.error('Create error:', error); alert('Fehler beim Erstellen'); } }; const getStatusBadge = (status: string) => { const styles: Record = { AVAILABLE: 'bg-green-500/20 text-green-400 border border-green-500/50', IN_USE: 'bg-blue-500/20 text-blue-400 border border-blue-500/50', MAINTENANCE: 'bg-yellow-500/20 text-yellow-400 border border-yellow-500/50', DAMAGED: 'bg-red-500/20 text-red-400 border border-red-500/50', }; return styles[status] || 'bg-gray-500/20 text-gray-400 border border-gray-500/50'; }; const getStatusLabel = (status: string) => { const labels: Record = { AVAILABLE: 'Verfügbar', IN_USE: 'Im Einsatz', MAINTENANCE: 'Wartung', DAMAGED: 'Defekt', }; return labels[status] || status; }; 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; }; if (loading) { return (

Lädt...

); } return (

Fotoboxen

Verwalten Sie alle Fotoboxen

{showForm && (

Neue Fotobox erstellen

setFormData({ ...formData, serialNumber: e.target.value })} className="w-full px-4 py-2 bg-gray-700 border border-gray-600 text-white rounded-lg focus:ring-2 focus:ring-red-500" required />