"use client"; import { useState, useEffect } from "react"; import { FiCalendar, FiMapPin } from "react-icons/fi"; import Link from "next/link"; import { useRouter } from "next/navigation"; interface NewBookingFormProps { locations: any[]; user: any; } export default function NewBookingForm({ locations, user, }: NewBookingFormProps) { const router = useRouter(); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [equipmentList, setEquipmentList] = useState([]); const [selectedEquipment, setSelectedEquipment] = useState([]); useEffect(() => { fetch("/api/equipment") .then((res) => res.json()) .then((data) => setEquipmentList(data.equipment || [])) .catch(() => {}); }, []); const toggleEquipment = (id: string) => { setSelectedEquipment((prev) => prev.includes(id) ? prev.filter((e) => e !== id) : [...prev, id] ); }; const [formData, setFormData] = useState({ locationId: "", model: "VINTAGE_SMILE", customerName: "", customerEmail: "", customerPhone: "", customerAddress: "", customerCity: "", customerZip: "", invoiceType: "PRIVATE", companyName: "", eventDate: "", eventAddress: "", eventCity: "", eventZip: "", eventLocation: "", setupTimeStart: "", setupTimeLatest: "", dismantleTimeEarliest: "", dismantleTimeLatest: "", calculatedPrice: 0, notes: "", }); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(""); try { const res = await fetch("/api/bookings/create", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ...formData, equipmentIds: selectedEquipment }), }); const data = await res.json(); if (!res.ok) { throw new Error(data.error || "Fehler beim Erstellen"); } alert("Buchung erfolgreich erstellt!"); router.push(`/dashboard/bookings/${data.booking.id}`); } catch (err: any) { setError(err.message); setLoading(false); } }; return (
← Zurück zu Buchungen

Neue Buchung erstellen

Manuelle Buchung anlegen

Standort & Fotobox

{equipmentList.length > 0 && (
{equipmentList.map((eq) => ( ))}
)}

Kundendaten

{formData.invoiceType === "BUSINESS" && (
setFormData({ ...formData, companyName: 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 focus:border-transparent" />
)}
setFormData({ ...formData, customerName: e.target.value }) } required 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 focus:border-transparent" />
setFormData({ ...formData, customerEmail: e.target.value }) } required 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 focus:border-transparent" />
setFormData({ ...formData, customerPhone: e.target.value }) } required 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 focus:border-transparent" />
setFormData({ ...formData, customerAddress: e.target.value }) } placeholder="Straße und Hausnummer" 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 focus:border-transparent placeholder-gray-500" />
setFormData({ ...formData, customerZip: 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 focus:border-transparent" />
setFormData({ ...formData, customerCity: 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 focus:border-transparent" />

Event-Details

setFormData({ ...formData, eventDate: e.target.value }) } required min={new Date().toISOString().split("T")[0]} 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 focus:border-transparent" />
setFormData({ ...formData, calculatedPrice: parseFloat(e.target.value), }) } required 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 focus:border-transparent" />
setFormData({ ...formData, eventAddress: e.target.value }) } required placeholder="Straße und Hausnummer" 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 focus:border-transparent placeholder-gray-500" />
setFormData({ ...formData, eventZip: e.target.value }) } required 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 focus:border-transparent" />
setFormData({ ...formData, eventCity: e.target.value }) } required 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 focus:border-transparent" />
setFormData({ ...formData, eventLocation: e.target.value }) } placeholder="z.B. Hotel Maritim" 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 focus:border-transparent placeholder-gray-500" />
setFormData({ ...formData, setupTimeStart: e.target.value }) } required 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 focus:border-transparent" />
setFormData({ ...formData, setupTimeLatest: e.target.value }) } required 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 focus:border-transparent" />
setFormData({ ...formData, dismantleTimeEarliest: 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 focus:border-transparent" />
setFormData({ ...formData, dismantleTimeLatest: 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 focus:border-transparent" />