import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import { useMutation, useQuery } from "@tanstack/react-query"; import { Building2, UserPlus, Mail, Lock, Sparkles, Check, Wand2, ChevronRight } from "lucide-react"; import { api } from "../../lib/api"; import { Modal } from "../Modal"; import { Spinner } from "../ui"; import { cn } from "../../lib/format"; interface Props { open: boolean; onClose: () => void; onCreated?: () => void; } const PLAN_OPTIONS = [ { value: "trial", label: "Prueba", desc: "14 días" }, { value: "pro", label: "Pro", desc: "Suscripción activa" }, { value: "free", label: "Free", desc: "Plan gratuito" }, ]; export function CreateBusinessModal({ open, onClose, onCreated }: Props) { const navigate = useNavigate(); const { data: tplData } = useQuery({ queryKey: ["admin", "templates"], queryFn: () => api.admin.templates(), enabled: open }); const templates = tplData?.templates ?? []; const [step, setStep] = useState<1 | 2>(1); const [template, setTemplate] = useState("estetica-spa"); const [name, setName] = useState(""); const [industry, setIndustry] = useState(""); const [ownerName, setOwnerName] = useState(""); const [ownerEmail, setOwnerEmail] = useState(""); const [ownerPassword, setOwnerPassword] = useState("demo1234"); const [plan, setPlan] = useState("trial"); const [error, setError] = useState(null); useEffect(() => { if (!open) return; setStep(1); setError(null); setName(""); setIndustry(""); setOwnerName(""); setOwnerEmail(""); setOwnerPassword("demo1234"); setPlan("trial"); setTemplate("estetica-spa"); }, [open]); // Auto-fill name/industry from selected template useEffect(() => { if (!open) return; const t = templates.find((x) => x.key === template); if (t && !name) setName(t.name === "Nuevo Negocio" ? "" : t.name); if (t && !industry) setIndustry(t.industry); }, [template, templates, open]); // eslint-disable-line react-hooks/exhaustive-deps const mut = useMutation({ mutationFn: () => api.admin.createBusiness({ name, industry: industry || undefined, template, ownerName: ownerName || "Dueño", ownerEmail, ownerPassword, plan, }), onSuccess: (data: any) => { onCreated?.(); onClose(); navigate(`/admin/businesses/${data.business.id}`); }, onError: (e: any) => setError(e.message), }); const selected = templates.find((t: any) => t.key === template); const canContinue = !!template; const canCreate = !!name.trim() && !!ownerEmail.trim() && !!ownerPassword.trim(); return (
{step === 1 ? ( La plantilla carga datos demo listos para usar. ) : ( Se creará el negocio y la cuenta del dueño. )}
{step === 2 && ( )} {step === 1 ? ( ) : ( )}
} > {error && (
{error}
)} {step === 1 ? (
{!templates.length ? (
) : (
{templates.map((t: any) => { const on = template === t.key; return ( ); })}
)}

Las plantillas crean empleados, servicios y clientes demo, además de citas pasadas y próximas para que el panel tenga datos desde el minuto uno. Blank crea un negocio vacío para configurar desde cero.

) : (
{selected && (
Plantilla: {selected.name} — {selected.employees} empleados, {selected.services} servicios, {selected.clients} clientes
)}
setName(e.target.value)} placeholder="Ej. Lumière Estética & Spa" />
setIndustry(e.target.value)} placeholder="Estética, Barbería, Dental…" />
{PLAN_OPTIONS.map((p) => ( ))}
Cuenta del dueño
setOwnerName(e.target.value)} placeholder="Dueño" />
setOwnerEmail(e.target.value)} placeholder="dueno@negocio.com" />
setOwnerPassword(e.target.value)} placeholder="demo1234" />
)}
); }