"use client"; import { useState } 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 [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), }); 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 (
Manuelle Buchung anlegen