'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { Button, Input, Label, Card, CardContent, CardHeader, CardTitle } from '@horux/shared-ui'; import { useAuthStore } from '@/stores/auth-store'; import { apiClient } from '@/lib/api/client'; import { CheckCircle2, ArrowLeft } from 'lucide-react'; type VerticalProfile = 'CONTABLE' | 'JURIDICO' | 'ARQUITECTURA'; export default function RegisterDespachoPage() { const router = useRouter(); const { setUser, setTokens } = useAuthStore(); const [step, setStep] = useState(1); const [verticalProfile, setVerticalProfile] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [form, setForm] = useState({ despachoNombre: '', ownerNombre: '', ownerEmail: '', ownerPassword: '', acceptedTerms: false, }); const handleChange = (field: string) => (e: React.ChangeEvent) => { setForm((prev) => ({ ...prev, [field]: e.target.value })); setError(''); }; const handleSubmit = async () => { if (!form.acceptedTerms) { setError('Debes aceptar los términos y condiciones'); return; } if (!verticalProfile) { setError('Selecciona un tipo de despacho'); return; } setLoading(true); setError(''); try { const { data } = await apiClient.post('/despachos/signup', { despacho: { nombre: form.despachoNombre, verticalProfile, }, owner: { nombre: form.ownerNombre, email: form.ownerEmail, password: form.ownerPassword, }, }); setTokens(data.accessToken, data.refreshToken); setUser(data.user); router.push('/onboarding'); } catch (err: any) { setError(err.response?.data?.message || 'Error al registrar el despacho'); setStep(1); } finally { setLoading(false); } }; // =================== STEP 1: Registration Form =================== if (step === 1) { const canProceed = form.despachoNombre && form.ownerNombre && form.ownerEmail && form.ownerPassword.length >= 10 && form.acceptedTerms; return (
1 2
Crea tu cuenta

Plataforma para despachos profesionales

setForm((p) => ({ ...p, acceptedTerms: e.target.checked }))} className="mt-1" />
{error &&

{error}

}

¿Ya tienes cuenta? Inicia sesión

); } // =================== STEP 2: Vertical Selection =================== return (
2

¿Qué tipo de despacho eres?

Selecciona tu área profesional

⚖️

Jurídico

Próximamente

🏗️

Arquitectura

Próximamente

{error &&

{error}

}
); }