// JOXE ACADEMIA — Página pública de las clases de barbería // El contenido lo edita el salón desde el panel (Admin → Academia). Aquí no // hay textos de negocio quemados: si no hay nada publicado, la página lo dice. const { useState, useEffect } = React; const AC_STATUS = { idle: "idle", sending: "sending", sent: "sent" }; // Espejo de cleanName en lib/db.js: en un nombre solo entran letras (con // tildes y ñ), espacios, apóstrofo y guion. El backend vuelve a validar. const NAME_STRIP_RE = /[^\p{L}\p{M}'’ -]/gu; const NAME_HAS_FORBIDDEN_RE = /[^\p{L}\p{M}'’ -]/u; const cleanName = (v, max = 80) => String(v ?? "") .replace(NAME_STRIP_RE, "").replace(/['’-]{2,}/g, m => m[0]) .replace(/\s+/g, " ").trimStart().slice(0, max); // —————————————————————————————————————————————— // HERO // —————————————————————————————————————————————— const AcHero = ({ content, onEnroll }) => (
{content.kicker || "Academia JOXE"}

{content.headline || <>Clases de barbería
en el salón.}

{content.intro && (

{content.intro}

)}
Ver el salón
{(content.nextStart || content.location) && (
{content.nextStart && (
Próximo grupo
{content.nextStart}
)} {content.location && (
Dónde
{content.location}
)}
)}
); // —————————————————————————————————————————————— // QUÉ INCLUYE // —————————————————————————————————————————————— const AcIncludes = ({ items }) => { if (!items?.length) return null; return (
Qué incluye
{items.map((item, i) => (
{String(i + 1).padStart(2, "0")}

{item}

))}
); }; // —————————————————————————————————————————————— // CURSOS // —————————————————————————————————————————————— const AcCourse = ({ course, onEnroll }) => { const meta = [course.level, course.duration, course.schedule].filter(Boolean); return (

{course.name}

{meta.length > 0 && ( {meta.join(" · ")} )} {course.summary && (

{course.summary}

)} {course.topics?.length > 0 && ( )}
{course.price > 0 ? (
{formatPrice(course.price, course.note)}
) : (
Precio a consultar
)} {course.seats > 0 && ( {course.seats} cupo{course.seats !== 1 ? "s" : ""} )}
); }; const AcCourses = ({ courses, onEnroll }) => { if (!courses?.length) return null; return (
Los cursos

Elige por dónde empezar.

{courses.map(c => )}
); }; // —————————————————————————————————————————————— // FORMULARIO DE INSCRIPCIÓN // —————————————————————————————————————————————— const AcField = ({ label, children }) => ( ); const acInputStyle = { background: "transparent", border: "1px solid rgba(245,241,234,0.22)", color: "var(--ivory)", padding: "14px 16px", width: "100%", fontFamily: "var(--sans)", fontSize: 15, }; const AcEnroll = React.forwardRef(({ content, courseId, onCourseChange }, ref) => { const [form, setForm] = useState({ name: "", phone: "", email: "", message: "" }); const [status, setStatus] = useState(AC_STATUS.idle); const [error, setError] = useState(""); const set = (k) => (e) => setForm(f => ({ ...f, [k]: e.target.value })); // El nombre se filtra al escribir, igual que en reservas. El aviso se // sostiene unos segundos para que no se apague con la siguiente tecla válida. const [nameBlocked, setNameBlocked] = useState(false); const nameBlockedTimer = React.useRef(null); const setName = (e) => { const raw = e.target.value; if (NAME_HAS_FORBIDDEN_RE.test(raw)) { setNameBlocked(true); clearTimeout(nameBlockedTimer.current); nameBlockedTimer.current = setTimeout(() => setNameBlocked(false), 4000); } setForm(f => ({ ...f, name: cleanName(raw, 80) })); }; useEffect(() => () => clearTimeout(nameBlockedTimer.current), []); const courses = content.courses || []; const wa = getWAConfig(); const waMsg = content.whatsappMsg || `Hola, quiero información sobre las clases${courseId ? " de " + (courses.find(c => c.id === courseId)?.name || "") : ""}.`; const waUrl = `https://wa.me/${wa.number}?text=${encodeURIComponent(waMsg)}`; const submit = async (e) => { e.preventDefault(); if (status === AC_STATUS.sending) return; const phoneErr = phoneError(form.phone); if (phoneErr) { setError(phoneErr); return; } setStatus(AC_STATUS.sending); setError(""); try { const res = await fetch("/api/academy", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ...form, courseId }), }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.error || "No se pudo enviar la solicitud"); setStatus(AC_STATUS.sent); } catch (err) { setError(err.message); setStatus(AC_STATUS.idle); } }; return (
Inscripción

Déjanos tus datos
y te contamos.

Te escribimos por WhatsApp para resolver dudas, confirmar el cupo y coordinar el pago. Sin compromiso.

Prefiero WhatsApp
{status === AC_STATUS.sent ? (
Solicitud recibida

Gracias, {form.name.split(" ")[0]}. Te contactamos al {fmtPhone(form.phone)} para darte los detalles del curso.

Escribir ahora por WhatsApp →
) : (
{nameBlocked && ( )} { setForm(f => ({ ...f, phone })); setError(""); }} fieldStyle={acInputStyle} focusColor="var(--bronze)" /> {courses.length > 0 && ( )}