// Yomee — Personal Info Screen // First post-auth onboarding step. Captures name, age, gender. // Uses OnboardingHeader + TextField + SegmentedSelect from OnboardingShared.jsx // Uses PrimaryButton from Shared.jsx /* global React, OnboardingHeader, TextField, SegmentedSelect, PrimaryButton */ const { useState: useStatePI, useEffect: useEffectPI } = React; function PersonalInfoScreen({ onBack, onContinue }) { // Read every persona-driven field reactively from the global persona // context. Switching the active persona via the Demo pill must update the // form fields instantly without a remount. const yomeeUser = (window.useYomeeUser && window.useYomeeUser()) || {}; const personaGenderToken = yomeeUser.gender === "female" ? "f" : yomeeUser.gender === "male" ? "m" : ""; const name = yomeeUser.name || ""; const age = yomeeUser.age != null ? String(yomeeUser.age) : ""; const gender = personaGenderToken; const [errors, setErrors] = useStatePI({}); const [touched, setTouched] = useStatePI({}); const validate = () => { const e = {}; if (!name.trim()) e.name = "Ingresa tu nombre para continuar."; else if (name.trim().length < 2) e.name = "El nombre debe tener al menos 2 letras."; else if (!/^[\p{L} '\-]+$/u.test(name.trim())) e.name = "Usa solo letras, espacios o guiones."; if (!age) e.age = "Ingresa tu edad."; else { const n = parseInt(age, 10); if (Number.isNaN(n)) e.age = "La edad debe ser un número."; else if (n < 18) e.age = "Debes ser mayor de 18 años para usar Yomee."; else if (n > 120) e.age = "Verifica tu edad."; } if (!gender) e.gender = "Selecciona una opción."; return e; }; // Reset transient touched/errors state when the active persona changes // so the form doesn't carry over a previous user's validation flags. useEffectPI(() => { setTouched({}); setErrors({}); // eslint-disable-next-line react-hooks/exhaustive-deps }, [yomeeUser.personaKey]); useEffectPI(() => { if (!touched.name && !touched.age && !touched.gender) return; const e = validate(); const filtered = {}; Object.keys(e).forEach((k) => { if (touched[k]) filtered[k] = e[k]; }); setErrors(filtered); // eslint-disable-next-line react-hooks/exhaustive-deps }, [name, age, gender, touched]); const submit = () => { setTouched({ name: true, age: true, gender: true }); const e = validate(); setErrors(e); if (Object.keys(e).length === 0) onContinue(); }; const allValid = name.trim() && age && gender && Object.keys(validate()).length === 0; return (

Antes de empezar,
confírmanos tus datos.

Así podremos personalizar tu experiencia.

{/* All three fields read directly from the active persona via the global context above — onChange is a no-op so values always reflect activePersona.{name,age,gender}. */} {}} placeholder="Abramo Escobar" error={errors.name} /> {}} placeholder="32" placeholderColor="rgba(20,32,28,0.32)" inputMode="numeric" maxLength={3} error={errors.age} /> {}} options={[ { value: "f", label: "Femenino" }, { value: "m", label: "Masculino" }, { value: "x", label: "Otro" }, ]} error={errors.gender} />
Continuar
); } window.PersonalInfoScreen = PersonalInfoScreen;