// 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íaen el salón. >}
{content.intro && (
{content.intro}
)}
{(content.nextStart || content.location) && (
{content.nextStart && (
Próximo grupo
{content.nextStart}
)}
{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.topics.map((t, i) => (
✦
{t}
))}
)}
{course.price > 0 ? (
{formatPrice(course.price, course.note)}
) : (
Precio a consultar
)}
{course.seats > 0 && (
{course.seats} cupo{course.seats !== 1 ? "s" : ""}
)}
onEnroll(course.id)} style={{
border: "1px solid var(--noir)", background: "transparent", color: "var(--noir)",
padding: "13px 24px", cursor: "pointer", fontFamily: "var(--sans)",
fontSize: 11, letterSpacing: "0.18em", textTransform: "uppercase",
transition: "background 0.25s, color 0.25s",
}}
onMouseEnter={e => { e.currentTarget.style.background = "var(--noir)"; e.currentTarget.style.color = "var(--ivory)"; }}
onMouseLeave={e => { e.currentTarget.style.background = "transparent"; e.currentTarget.style.color = "var(--noir)"; }}
>Inscribirme
);
};
const AcCourses = ({ courses, onEnroll }) => {
if (!courses?.length) return null;
return (
Los cursos
Elige por dónde empezar.
);
};
// ——————————————————————————————————————————————
// FORMULARIO DE INSCRIPCIÓN
// ——————————————————————————————————————————————
const AcField = ({ label, children }) => (
{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 datosy 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 →
) : (
)}
);
});
// ------------------------------------------------
// MODELOS: franja para quien llegó sin intención de estudiar
// ------------------------------------------------
const AcModelsBand = () => (
);
// ——————————————————————————————————————————————
// PREGUNTAS FRECUENTES
// ——————————————————————————————————————————————
const AcFaqItem = ({ item, open, onToggle }) => (
{item.q}
+
{open && (
{item.a}
)}
);
const AcFaq = ({ items }) => {
const [open, setOpen] = useState(null);
if (!items?.length) return null;
return (
Preguntas frecuentes
{items.map((item, i) => (
setOpen(open === i ? null : i)} />
))}
);
};
// ——————————————————————————————————————————————
// ESTADOS SIN CONTENIDO
// ——————————————————————————————————————————————
const AcMessage = ({ title, body }) => (
);
// ——————————————————————————————————————————————
// PORTAL
// ——————————————————————————————————————————————
function AcademiaPortal() {
const academy = useAcademy();
const [scrolled, setScrolled] = useState(false);
const [courseId, setCourseId] = useState("");
const formRef = React.useRef(null);
useEffect(() => {
const onScroll = () => setScrolled(window.scrollY > 40);
window.addEventListener("scroll", onScroll);
return () => window.removeEventListener("scroll", onScroll);
}, []);
const goToEnroll = (id) => {
if (id) setCourseId(id);
formRef.current?.scrollIntoView({ behavior: "smooth", block: "start" });
};
if (academy === null) {
return ;
}
if (!academy.enabled || !academy.content) {
return (
);
}
const content = academy.content;
return (
{ window.location.href = "/booking"; }}
scrolled={scrolled} hasAcademy hrefPrefix="/" />
goToEnroll("")} />
{academy.models && }
);
}
ReactDOM.createRoot(document.getElementById("root")).render( );