"use client"; import React, { useState } from 'react'; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { CheckCircle, Mail, Calendar, User, Phone, Building, MessageSquare } from "lucide-react"; import { colors } from '@/lib/colors'; import AppointmentCalendar from './AppointmentCalendar'; interface AppointmentFormData { name: string; telefon: string; firma: string; email: string; beschreibung: string; } interface AppointmentFormProps { onSubmit: (data: AppointmentFormData & { termin_datum?: Date; termin_time?: string }) => void; loading?: boolean; } export default function AppointmentForm({ onSubmit, loading = false }: AppointmentFormProps) { const [formData, setFormData] = useState({ name: '', telefon: '', firma: '', email: '', beschreibung: '' }); const [selectedSlot, setSelectedSlot] = useState<{ date: Date; time: string } | null>(null); const [errors, setErrors] = useState>({}); const handleInputChange = (field: keyof AppointmentFormData, value: string) => { setFormData(prev => ({ ...prev, [field]: value })); // Clear error when user starts typing if (errors[field]) { setErrors(prev => { const newErrors = { ...prev }; delete newErrors[field]; return newErrors; }); } }; const handleSlotSelect = (date: Date, time: string) => { console.log('=== SLOT SELECTION DEBUG ==='); console.log('Selected date:', date); console.log('Selected time:', time); console.log('Date type:', typeof date); console.log('Date instanceof Date:', date instanceof Date); console.log('Date.toISOString():', date.toISOString()); if (time === '') { setSelectedSlot(null); console.log('Slot deselected'); } else { setSelectedSlot({ date, time }); console.log('Slot selected:', { date, time }); } }; const validateForm = (): boolean => { const newErrors: Record = {}; if (!formData.name.trim()) { newErrors.name = 'Name ist erforderlich'; } if (!formData.telefon.trim()) { newErrors.telefon = 'Telefonnummer ist erforderlich'; } if (!formData.firma.trim()) { newErrors.firma = 'Unternehmen ist erforderlich'; } if (!formData.email.trim()) { newErrors.email = 'E-Mail ist erforderlich'; } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) { newErrors.email = 'Bitte geben Sie eine gültige E-Mail-Adresse ein'; } if (!formData.beschreibung.trim()) { newErrors.beschreibung = 'Projektbeschreibung ist erforderlich'; } if (!selectedSlot) { newErrors.termin_datum = 'Bitte wählen Sie einen Termin aus'; } setErrors(newErrors); return Object.keys(newErrors).length === 0; }; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (validateForm()) { console.log('=== FORM SUBMIT DEBUG ==='); console.log('Form data:', formData); console.log('Selected slot:', selectedSlot); console.log('Selected slot date:', selectedSlot?.date); console.log('Selected slot time:', selectedSlot?.time); const submitData = { ...formData, termin_datum: selectedSlot?.date, termin_time: selectedSlot?.time }; console.log('Submit data:', submitData); console.log('Submit termin_datum:', submitData.termin_datum); console.log('Submit termin_time:', submitData.termin_time); onSubmit(submitData); } }; return (
{/* Appointment Form */}

Termin anfragen

handleInputChange('name', e.target.value)} className={`w-full p-3 rounded-xl border-2 focus:outline-none focus:ring-2 ${ errors.name ? 'border-red-500' : '' }`} style={{ borderColor: errors.name ? '#ef4444' : colors.tertiary, backgroundColor: colors.background, color: colors.primary }} placeholder="Dein vollständiger Name" /> {errors.name && (

{errors.name}

)}
handleInputChange('telefon', e.target.value)} className={`w-full p-3 rounded-xl border-2 focus:outline-none focus:ring-2 ${ errors.telefon ? 'border-red-500' : '' }`} style={{ borderColor: errors.telefon ? '#ef4444' : colors.tertiary, backgroundColor: colors.background, color: colors.primary }} placeholder="+49 123 456789" /> {errors.telefon && (

{errors.telefon}

)}
handleInputChange('firma', e.target.value)} className={`w-full p-3 rounded-xl border-2 focus:outline-none focus:ring-2 ${ errors.firma ? 'border-red-500' : '' }`} style={{ borderColor: errors.firma ? '#ef4444' : colors.tertiary, backgroundColor: colors.background, color: colors.primary }} placeholder="Name deines Unternehmens" /> {errors.firma && (

{errors.firma}

)}
handleInputChange('email', e.target.value)} className={`w-full p-3 rounded-xl border-2 focus:outline-none focus:ring-2 ${ errors.email ? 'border-red-500' : '' }`} style={{ borderColor: errors.email ? '#ef4444' : colors.tertiary, backgroundColor: colors.background, color: colors.primary }} placeholder="deine@email.de" /> {errors.email && (

{errors.email}

)}