feat: detectar tel duplicado en crear cuenta y ofrecer reutilizar cuenta existente

This commit is contained in:
Jorem Juárez committed 2026-04-22 14:11:46 -06:00
1 parent 487d338923
commit 861852e8dd
1 file changed
+59 -1
+59 -1
View File
@@ -242,6 +242,8 @@ function WonderlooCheckin() {
const [submitLoading, setSubmitLoading] = useState(false);
const [editingChildId, setEditingChildId] = useState(null);
const [editChildForm, setEditChildForm] = useState({ nombre: "", cumple: "", alergias: "", relacion: "" });
const [duplicateTutor, setDuplicateTutor] = useState(null);
const [checkingDuplicate, setCheckingDuplicate] = useState(false);
const [currentTime] = useState(new Date().toLocaleTimeString("es-MX", { hour: "2-digit", minute: "2-digit" }));
const [currentDate] = useState(new Date().toLocaleDateString("es-MX", { weekday: "long", year: "numeric", month: "long", day: "numeric" }));
@@ -426,6 +428,45 @@ function WonderlooCheckin() {
}
};
// Antes de avanzar del step "tutor", verifica si el teléfono ya existe.
// Si existe, abre el modal con opción de cambiar a flujo "Ya tengo cuenta".
const advanceFromTutor = async () => {
if (checkingDuplicate) return;
setCheckingDuplicate(true);
try {
const apiTutor = await apiFetch("/tutores/lookup", {
method: "POST",
body: JSON.stringify({ telefono: tutorData.telefono }),
});
setDuplicateTutor(normalizeTutor(apiTutor));
} catch (err) {
if (err.status === 404) {
goNext();
} else if (err instanceof TypeError) {
setToast({ message: "Error de conexión. Intenta de nuevo.", type: "error" });
} else {
setToast({ message: err.message || "Error inesperado", type: "error" });
}
} finally {
setCheckingDuplicate(false);
}
};
const handleDuplicateUseIt = () => {
if (!duplicateTutor) return;
setMode("returning");
setFoundUser(duplicateTutor);
setSelectedChildren(duplicateTutor.children.map((_, i) => i));
setTutorData({ nombre: "", telefono: "", correo: "" });
setChildren([{ nombre: "", cumple: "", alergias: "", relacion: "" }]);
setStep(0);
setDuplicateTutor(null);
};
const handleDuplicateDismiss = () => {
setDuplicateTutor(null);
};
const handleSubmit = async () => {
setSubmitLoading(true);
try {
@@ -977,12 +1018,29 @@ function WonderlooCheckin() {
<div style={{ maxWidth: "420px", margin: "0 auto", padding: "20px 20px 100px" }}>{renderStep()}</div>
<div style={{ position: "fixed", bottom: 0, left: 0, right: 0, padding: "16px 20px", background: `linear-gradient(0deg, ${COLORS.warmBg} 80%, ${COLORS.warmBg}00 100%)` }}>
<div style={{ maxWidth: "420px", margin: "0 auto" }}>
<Btn onClick={isLastStep ? handleSubmit : goNext} disabled={submitLoading || !canProceed()} variant={isLastStep ? "success" : "primary"}>{submitLoading ? "Registrando..." : (isLastStep ? "Firmar y registrar ✓" : "Continuar →")}</Btn>
<Btn onClick={isLastStep ? handleSubmit : (currentStepName === "tutor" ? advanceFromTutor : goNext)} disabled={submitLoading || checkingDuplicate || !canProceed()} variant={isLastStep ? "success" : "primary"}>{submitLoading ? "Registrando..." : (checkingDuplicate ? "Verificando..." : (isLastStep ? "Firmar y registrar ✓" : "Continuar →"))}</Btn>
</div>
</div>
<style>{`@keyframes fadeUp { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } } @keyframes popIn { from { transform:scale(0); } to { transform:scale(1); } } * { -webkit-tap-highlight-color: transparent; } input, select { font-size: 17px !important; }`}</style>
</div>
{toast && <ToastBanner toast={toast} />}
{duplicateTutor && (
<div style={{ position: "fixed", inset: 0, background: "rgba(0,0,0,0.55)", zIndex: 300, display: "flex", alignItems: "center", justifyContent: "center", padding: "20px", fontFamily: "'Nunito', sans-serif" }}>
<Card style={{ maxWidth: "420px", width: "100%", padding: "28px 24px" }}>
<div style={{ textAlign: "center", marginBottom: "20px" }}>
<div style={{ fontSize: "48px", marginBottom: "10px" }}>📱</div>
<h3 style={{ margin: "0 0 8px 0", fontFamily: "'Fredoka', sans-serif", fontSize: "22px", color: COLORS.text }}>Ya tenemos este número</h3>
<p style={{ margin: 0, fontSize: "15px", color: COLORS.textLight, lineHeight: 1.5 }}>
El teléfono <strong>{duplicateTutor.telefono}</strong> ya está registrado a nombre de <strong>{duplicateTutor.nombre.split(" ")[0]}</strong>.
</p>
</div>
<div style={{ display: "flex", flexDirection: "column", gap: "10px" }}>
<Btn onClick={handleDuplicateUseIt} variant="success">Sí, usar esta cuenta →</Btn>
<Btn onClick={handleDuplicateDismiss} variant="outline">No, cambiar número</Btn>
</div>
</Card>
</div>
)}
</React.Fragment>
);
}