'use client' import { useState } from 'react' import { useRouter, useSearchParams } from 'next/navigation' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { User, Mail, Phone, Calendar, Briefcase } from 'lucide-react' const OCCUPATIONS = [ 'Estudiante', 'Profesional', 'Empresario/a', 'Ama de casa', 'Artista', 'Comerciante', 'Profesor/a', 'Ingeniero/a', 'Médico/a', 'Abogado/a', 'Otro' ] export default function RegisterPage() { const router = useRouter() const searchParams = useSearchParams() const redirect = searchParams.get('redirect') || '/booking/cita' const emailParam = searchParams.get('email') || '' const phoneParam = searchParams.get('phone') || '' const [formData, setFormData] = useState({ email: emailParam, phone: phoneParam, first_name: '', last_name: '', birthday: '', occupation: '' }) const [loading, setLoading] = useState(false) const [errors, setErrors] = useState>({}) const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target setFormData(prev => ({ ...prev, [name]: value })) setErrors({ ...errors, [name]: '' }) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setErrors({}) setLoading(true) const validationErrors: Record = {} if (!formData.email.trim() || !formData.email.includes('@')) { validationErrors.email = 'Email inválido' } if (!formData.phone.trim()) { validationErrors.phone = 'Teléfono requerido' } if (!formData.first_name.trim()) { validationErrors.first_name = 'Nombre requerido' } if (!formData.last_name.trim()) { validationErrors.last_name = 'Apellido requerido' } if (!formData.birthday) { validationErrors.birthday = 'Fecha de nacimiento requerida' } if (!formData.occupation) { validationErrors.occupation = 'Ocupación requerida' } if (Object.keys(validationErrors).length > 0) { setErrors(validationErrors) setLoading(false) return } try { const response = await fetch('/api/customers', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) }) const data = await response.json() if (response.ok && data.success) { const params = new URLSearchParams({ customer_id: data.customer.id, ...Object.fromEntries(searchParams.entries()) }) router.push(`${redirect}?${params.toString()}`) } else { if (data.message === 'El cliente ya existe') { const params = new URLSearchParams({ customer_id: data.customer.id, ...Object.fromEntries(searchParams.entries()) }) router.push(`${redirect}?${params.toString()}`) } else { setErrors({ submit: data.error || 'Error al registrar cliente' }) setLoading(false) } } } catch (error) { console.error('Error registrando cliente:', error) setErrors({ submit: 'Error al registrar cliente' }) setLoading(false) } } return (

Anchor:23

Completa tu registro

Registro de Cliente Ingresa tus datos personales para completar tu reserva
{errors.email &&

{errors.email}

}
{errors.phone &&

{errors.phone}

}
{errors.first_name &&

{errors.first_name}

}
{errors.last_name &&

{errors.last_name}

}
{errors.birthday &&

{errors.birthday}

}
{errors.occupation &&

{errors.occupation}

}
{errors.submit && (
{errors.submit}
)}
* Al registrarte, aceptas nuestros términos y condiciones.
) }