521 lines
18 KiB
HTML
521 lines
18 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
<title>Recordatorios · WK Seguros</title>
|
|
<style>
|
|
:root {
|
|
--bg: #F7F7F5;
|
|
--card: #FFFFFF;
|
|
--ink: #111111;
|
|
--ink-soft: #6E6E73;
|
|
--line: #E8E8E5;
|
|
--accent: #111111;
|
|
--danger: #E53935;
|
|
--shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
|
|
--shadow-md: 0 8px 32px rgba(0,0,0,0.06);
|
|
--shadow-lg: 0 18px 48px rgba(0,0,0,0.10);
|
|
--radius-pill: 999px;
|
|
--radius-card: 28px;
|
|
--radius-soft: 16px;
|
|
}
|
|
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
|
html, body {
|
|
margin: 0; padding: 0;
|
|
background: var(--bg);
|
|
color: var(--ink);
|
|
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Helvetica Neue", Arial, sans-serif;
|
|
font-size: 16px; line-height: 1.5;
|
|
-webkit-font-smoothing: antialiased;
|
|
}
|
|
.wrap {
|
|
max-width: 720px;
|
|
margin: 0 auto;
|
|
padding: 32px 20px 120px;
|
|
}
|
|
header h1 {
|
|
font-size: 28px; font-weight: 600; letter-spacing: -0.02em;
|
|
margin: 0 0 4px;
|
|
}
|
|
header p {
|
|
color: var(--ink-soft); margin: 0 0 28px; font-size: 15px;
|
|
}
|
|
.empty {
|
|
background: var(--card);
|
|
border-radius: var(--radius-card);
|
|
padding: 56px 28px;
|
|
text-align: center;
|
|
box-shadow: var(--shadow-md);
|
|
color: var(--ink-soft);
|
|
}
|
|
.empty svg { width: 48px; height: 48px; opacity: 0.4; margin-bottom: 12px; }
|
|
.card {
|
|
background: var(--card);
|
|
border-radius: var(--radius-card);
|
|
box-shadow: var(--shadow-md);
|
|
padding: 22px 24px;
|
|
margin-bottom: 14px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 18px;
|
|
transition: box-shadow 0.2s ease, transform 0.1s ease;
|
|
}
|
|
.card:hover { box-shadow: var(--shadow-lg); }
|
|
.card-main { flex: 1; min-width: 0; }
|
|
.card-num {
|
|
font-size: 17px; font-weight: 600; letter-spacing: -0.01em;
|
|
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
}
|
|
.card-sub {
|
|
font-size: 13px; color: var(--ink-soft); margin-top: 2px;
|
|
font-variant-numeric: tabular-nums;
|
|
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
}
|
|
.card-meta {
|
|
font-size: 13px; color: var(--ink-soft); margin-top: 4px;
|
|
display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
|
|
}
|
|
.meta-pill {
|
|
background: #F2F2EF;
|
|
border-radius: var(--radius-pill);
|
|
padding: 4px 10px;
|
|
font-variant-numeric: tabular-nums;
|
|
}
|
|
.actions {
|
|
display: flex; align-items: center; gap: 10px;
|
|
}
|
|
/* Píldora de acciones secundarias (editar) */
|
|
.pill-group {
|
|
display: inline-flex; align-items: center; gap: 4px;
|
|
background: var(--card);
|
|
border-radius: var(--radius-pill);
|
|
box-shadow: var(--shadow-sm);
|
|
padding: 6px;
|
|
}
|
|
.icon-btn {
|
|
width: 40px; height: 40px;
|
|
border: 0; background: transparent;
|
|
border-radius: var(--radius-pill);
|
|
display: inline-flex; align-items: center; justify-content: center;
|
|
cursor: pointer; color: var(--ink);
|
|
transition: background 0.15s ease;
|
|
}
|
|
.icon-btn:hover { background: #F2F2EF; }
|
|
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.5; }
|
|
/* Botón destructivo circular aislado */
|
|
.icon-btn.danger {
|
|
background: var(--danger); color: #fff;
|
|
box-shadow: 0 6px 16px rgba(229,57,53,0.32);
|
|
}
|
|
.icon-btn.danger:hover { background: #D32F2F; }
|
|
/* FAB de añadir */
|
|
.fab {
|
|
position: fixed; right: 28px; bottom: 28px;
|
|
width: 60px; height: 60px;
|
|
border-radius: var(--radius-pill);
|
|
background: var(--ink); color: #fff; border: 0;
|
|
box-shadow: var(--shadow-lg);
|
|
display: inline-flex; align-items: center; justify-content: center;
|
|
cursor: pointer; z-index: 10;
|
|
transition: transform 0.15s ease;
|
|
}
|
|
.fab:hover { transform: scale(1.04); }
|
|
.fab:active { transform: scale(0.96); }
|
|
.fab svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 2; }
|
|
/* Modal */
|
|
.modal-bg {
|
|
position: fixed; inset: 0; background: rgba(17,17,17,0.32);
|
|
backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
|
|
display: none; align-items: center; justify-content: center;
|
|
padding: 16px; z-index: 100;
|
|
}
|
|
.modal-bg.open { display: flex; }
|
|
.modal {
|
|
background: var(--card);
|
|
border-radius: var(--radius-card);
|
|
box-shadow: var(--shadow-lg);
|
|
width: 100%; max-width: 480px;
|
|
padding: 28px;
|
|
max-height: 90vh; overflow-y: auto;
|
|
}
|
|
.modal h2 {
|
|
margin: 0 0 6px; font-size: 22px; font-weight: 600; letter-spacing: -0.02em;
|
|
}
|
|
.modal p.hint { color: var(--ink-soft); margin: 0 0 22px; font-size: 14px; }
|
|
.field { margin-bottom: 20px; }
|
|
.field label {
|
|
display: block; font-size: 13px; font-weight: 500;
|
|
color: var(--ink-soft); margin-bottom: 8px; text-transform: uppercase;
|
|
letter-spacing: 0.04em;
|
|
}
|
|
.field input[type="tel"], .field input[type="time"], .field input[type="text"] {
|
|
width: 100%; padding: 12px 16px;
|
|
border: 1px solid var(--line); border-radius: var(--radius-soft);
|
|
background: #FAFAF8; font-size: 16px; font-family: inherit; color: var(--ink);
|
|
transition: border-color 0.15s ease, background 0.15s ease;
|
|
}
|
|
.field input:focus {
|
|
outline: none; border-color: var(--ink); background: #fff;
|
|
}
|
|
.field-hint {
|
|
display: block; margin-top: 6px;
|
|
font-size: 12px; color: var(--ink-soft);
|
|
letter-spacing: 0.01em;
|
|
}
|
|
.days-grid {
|
|
display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
|
|
}
|
|
.day-chip {
|
|
aspect-ratio: 1 / 1; min-width: 0;
|
|
border-radius: var(--radius-pill);
|
|
background: #F2F2EF; border: 0; cursor: pointer;
|
|
font-size: 14px; font-family: inherit; color: var(--ink);
|
|
font-variant-numeric: tabular-nums;
|
|
transition: background 0.12s ease, color 0.12s ease, transform 0.08s ease;
|
|
}
|
|
.day-chip:hover { background: #E8E8E5; }
|
|
.day-chip.selected {
|
|
background: var(--ink); color: #fff;
|
|
}
|
|
.day-chip:active { transform: scale(0.93); }
|
|
.modal-actions {
|
|
display: flex; justify-content: flex-end; gap: 10px; margin-top: 28px;
|
|
}
|
|
.btn {
|
|
padding: 12px 22px;
|
|
border-radius: var(--radius-pill);
|
|
border: 0; cursor: pointer;
|
|
font-size: 15px; font-family: inherit; font-weight: 500;
|
|
transition: background 0.15s ease, transform 0.08s ease;
|
|
}
|
|
.btn:active { transform: scale(0.97); }
|
|
.btn-ghost { background: transparent; color: var(--ink-soft); }
|
|
.btn-ghost:hover { background: #F2F2EF; color: var(--ink); }
|
|
.btn-primary { background: var(--ink); color: #fff; }
|
|
.btn-primary:hover { background: #000; }
|
|
/* Toast */
|
|
#toast {
|
|
position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
|
|
background: var(--ink); color: #fff;
|
|
padding: 12px 20px; border-radius: var(--radius-pill);
|
|
font-size: 14px; box-shadow: var(--shadow-lg);
|
|
opacity: 0; pointer-events: none; transition: all 0.25s ease; z-index: 200;
|
|
}
|
|
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
|
|
#toast.error { background: var(--danger); }
|
|
/* Estado de bloqueo (token inválido) */
|
|
.locked {
|
|
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
|
min-height: 60vh; text-align: center; padding: 0 24px;
|
|
}
|
|
.locked svg { width: 56px; height: 56px; stroke: var(--ink-soft); fill: none; stroke-width: 1.5; margin-bottom: 16px; }
|
|
.locked h2 { font-size: 22px; font-weight: 600; margin: 0 0 6px; }
|
|
.locked p { color: var(--ink-soft); margin: 0; max-width: 320px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="wrap" id="app" style="display:none">
|
|
<header>
|
|
<h1>Recordatorios mensuales</h1>
|
|
<p>Configura quién recibe el resumen del mes siguiente, en qué días y a qué hora.</p>
|
|
</header>
|
|
|
|
<div id="lista"></div>
|
|
</div>
|
|
|
|
<div class="locked" id="bloqueo" style="display:none">
|
|
<svg viewBox="0 0 24 24"><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg>
|
|
<h2>Acceso expirado</h2>
|
|
<p>El link ya no es válido. Vuelve a escribir <strong>recordatorios</strong> al bot de WhatsApp para obtener uno nuevo.</p>
|
|
</div>
|
|
|
|
<button class="fab" id="fab" aria-label="Añadir recordatorio" style="display:none">
|
|
<svg viewBox="0 0 24 24"><path d="M12 5v14M5 12h14"/></svg>
|
|
</button>
|
|
|
|
<!-- Modal -->
|
|
<div class="modal-bg" id="modal-bg">
|
|
<div class="modal" role="dialog" aria-modal="true">
|
|
<h2 id="modal-title">Nuevo recordatorio</h2>
|
|
<p class="hint">El bot enviará el resumen del mes siguiente al destinatario en los días y hora que elijas.</p>
|
|
|
|
<div class="field">
|
|
<label for="f-nombre">Nombre</label>
|
|
<input type="text" id="f-nombre" placeholder="Ej. Paulino Sánchez" maxlength="100" autocomplete="off">
|
|
</div>
|
|
|
|
<div class="field">
|
|
<label for="f-destinatario">Destinatario (WhatsApp)</label>
|
|
<input type="tel" id="f-destinatario" placeholder="222 617 6586" inputmode="numeric" maxlength="10" pattern="[0-9]{10}" autocomplete="off">
|
|
<span class="field-hint">10 dígitos — se enviará a +521XXXXXXXXXX</span>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<label>Días del mes</label>
|
|
<div class="days-grid" id="f-dias"></div>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<label for="f-hora">Hora (CDMX)</label>
|
|
<input type="time" id="f-hora" value="09:00">
|
|
</div>
|
|
|
|
<div class="modal-actions">
|
|
<button class="btn btn-ghost" id="btn-cancelar">Cancelar</button>
|
|
<button class="btn btn-primary" id="btn-guardar">Guardar</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="toast"></div>
|
|
|
|
<script>
|
|
(() => {
|
|
// Obtener token de la query string
|
|
const params = new URLSearchParams(window.location.search);
|
|
const TOKEN = params.get("token") || "";
|
|
// La API vive en el mismo origen, montada bajo /api/v1
|
|
const API = "/seguros/api/v1";
|
|
|
|
const elApp = document.getElementById("app");
|
|
const elBloqueo = document.getElementById("bloqueo");
|
|
const elLista = document.getElementById("lista");
|
|
const elFab = document.getElementById("fab");
|
|
const elModalBg = document.getElementById("modal-bg");
|
|
const elDias = document.getElementById("f-dias");
|
|
const elNombre = document.getElementById("f-nombre");
|
|
const elDestinatario = document.getElementById("f-destinatario");
|
|
const elHora = document.getElementById("f-hora");
|
|
const elBtnGuardar = document.getElementById("btn-guardar");
|
|
const elBtnCancelar = document.getElementById("btn-cancelar");
|
|
const elTitulo = document.getElementById("modal-title");
|
|
const elToast = document.getElementById("toast");
|
|
|
|
let editandoId = null;
|
|
let diasSeleccionados = new Set();
|
|
|
|
// Render chips de días 1-31
|
|
for (let i = 1; i <= 31; i++) {
|
|
const b = document.createElement("button");
|
|
b.className = "day-chip";
|
|
b.type = "button";
|
|
b.textContent = i;
|
|
b.dataset.dia = i;
|
|
b.addEventListener("click", () => {
|
|
if (diasSeleccionados.has(i)) {
|
|
diasSeleccionados.delete(i);
|
|
b.classList.remove("selected");
|
|
} else {
|
|
diasSeleccionados.add(i);
|
|
b.classList.add("selected");
|
|
}
|
|
});
|
|
elDias.appendChild(b);
|
|
}
|
|
|
|
function toast(msg, esError = false) {
|
|
elToast.textContent = msg;
|
|
elToast.classList.toggle("error", esError);
|
|
elToast.classList.add("show");
|
|
setTimeout(() => elToast.classList.remove("show"), 2200);
|
|
}
|
|
|
|
async function apiCall(metodo, ruta, body = null) {
|
|
const url = `${API}${ruta}${ruta.includes("?") ? "&" : "?"}token=${encodeURIComponent(TOKEN)}`;
|
|
const opts = { method: metodo, headers: { "Content-Type": "application/json" } };
|
|
if (body) opts.body = JSON.stringify(body);
|
|
const resp = await fetch(url, opts);
|
|
if (resp.status === 401) {
|
|
mostrarBloqueo();
|
|
throw new Error("Token expirado");
|
|
}
|
|
if (!resp.ok) {
|
|
const txt = await resp.text();
|
|
throw new Error(txt || `HTTP ${resp.status}`);
|
|
}
|
|
return resp.json();
|
|
}
|
|
|
|
function mostrarBloqueo() {
|
|
// Token inválido/expirado: ocultar app + FAB y mostrar SOLO el bloqueo
|
|
elApp.style.display = "none";
|
|
elFab.style.display = "none";
|
|
elBloqueo.style.display = "flex";
|
|
}
|
|
|
|
function mostrarApp() {
|
|
// Token válido: ocultar bloqueo y mostrar app + FAB
|
|
elBloqueo.style.display = "none";
|
|
elApp.style.display = "block";
|
|
elFab.style.display = "inline-flex";
|
|
}
|
|
|
|
function escapeHtml(str) {
|
|
return String(str).replace(/[&<>"']/g, c => ({
|
|
"&": "&", "<": "<", ">": ">", '"': """, "'": "'"
|
|
}[c]));
|
|
}
|
|
|
|
function stripPrefijo521(num) {
|
|
// Compatibilidad: registros viejos guardaron "521" + 10 dígitos.
|
|
// El formato canónico ahora es 10 dígitos.
|
|
if (num && num.length === 13 && num.startsWith("521")) return num.slice(3);
|
|
if (num && num.length === 12 && num.startsWith("52")) return num.slice(2);
|
|
return num || "";
|
|
}
|
|
|
|
function fmtDestinatario(num) {
|
|
const local = stripPrefijo521(num);
|
|
if (!local || local.length !== 10) return num || "";
|
|
// Formato MX: XXX XXX XXXX (con +521 visible para contexto)
|
|
return `+521 ${local.slice(0, 3)} ${local.slice(3, 6)} ${local.slice(6)}`;
|
|
}
|
|
|
|
function fmtDias(dias) {
|
|
if (!dias || dias.length === 0) return "—";
|
|
return dias.join(", ");
|
|
}
|
|
|
|
function renderLista(items) {
|
|
if (!items || items.length === 0) {
|
|
elLista.innerHTML = `
|
|
<div class="empty">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
|
<rect x="3" y="5" width="18" height="16" rx="3"/>
|
|
<path d="M16 3v4M8 3v4M3 11h18"/>
|
|
</svg>
|
|
<p>Aún no hay recordatorios. Toca el botón <strong>+</strong> para crear el primero.</p>
|
|
</div>`;
|
|
return;
|
|
}
|
|
elLista.innerHTML = "";
|
|
for (const r of items) {
|
|
const card = document.createElement("div");
|
|
card.className = "card";
|
|
const nombreEscaped = escapeHtml(r.nombre || "Sin nombre");
|
|
card.innerHTML = `
|
|
<div class="card-main">
|
|
<div class="card-num">${nombreEscaped}</div>
|
|
<div class="card-sub">${fmtDestinatario(r.destinatario)}</div>
|
|
<div class="card-meta">
|
|
<span class="meta-pill">${fmtDias(r.dias)}</span>
|
|
<span class="meta-pill">${r.hora}</span>
|
|
</div>
|
|
</div>
|
|
<div class="actions">
|
|
<div class="pill-group">
|
|
<button class="icon-btn" data-accion="editar" aria-label="Editar">
|
|
<svg viewBox="0 0 24 24"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 1 1 3 3L7 19l-4 1 1-4Z"/></svg>
|
|
</button>
|
|
</div>
|
|
<button class="icon-btn danger" data-accion="eliminar" aria-label="Eliminar">
|
|
<svg viewBox="0 0 24 24"><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><path d="M19 6 18 20a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/></svg>
|
|
</button>
|
|
</div>
|
|
`;
|
|
card.querySelector('[data-accion="editar"]').addEventListener("click", () => abrirModal(r));
|
|
card.querySelector('[data-accion="eliminar"]').addEventListener("click", () => eliminar(r));
|
|
elLista.appendChild(card);
|
|
}
|
|
}
|
|
|
|
async function cargar() {
|
|
try {
|
|
const data = await apiCall("GET", "/reminders");
|
|
renderLista(data.recordatorios || []);
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
function abrirModal(item = null) {
|
|
editandoId = item ? item.id : null;
|
|
elTitulo.textContent = item ? "Editar recordatorio" : "Nuevo recordatorio";
|
|
elNombre.value = item ? (item.nombre || "") : "";
|
|
// Pre-fill solo con los 10 dígitos (sin prefijo 521) por compat con registros viejos
|
|
elDestinatario.value = item ? stripPrefijo521(item.destinatario) : "";
|
|
elHora.value = item ? item.hora : "09:00";
|
|
diasSeleccionados = new Set(item ? item.dias : []);
|
|
for (const chip of elDias.querySelectorAll(".day-chip")) {
|
|
const d = parseInt(chip.dataset.dia, 10);
|
|
chip.classList.toggle("selected", diasSeleccionados.has(d));
|
|
}
|
|
elModalBg.classList.add("open");
|
|
setTimeout(() => elNombre.focus(), 50);
|
|
}
|
|
|
|
function cerrarModal() {
|
|
elModalBg.classList.remove("open");
|
|
editandoId = null;
|
|
}
|
|
|
|
async function guardar() {
|
|
const nombre = elNombre.value.trim();
|
|
const destinatario = elDestinatario.value.trim().replace(/\D/g, "");
|
|
const dias = Array.from(diasSeleccionados).sort((a, b) => a - b);
|
|
const hora = elHora.value;
|
|
|
|
if (!nombre || nombre.length > 100) {
|
|
toast("Nombre requerido (1-100 caracteres)", true); return;
|
|
}
|
|
if (!/^\d{10}$/.test(destinatario)) {
|
|
toast("Ingresa exactamente 10 dígitos (sin prefijo)", true); return;
|
|
}
|
|
if (dias.length === 0) {
|
|
toast("Selecciona al menos un día", true); return;
|
|
}
|
|
if (!/^\d{2}:\d{2}$/.test(hora)) {
|
|
toast("Hora inválida", true); return;
|
|
}
|
|
|
|
const payload = { nombre, destinatario, dias, hora };
|
|
try {
|
|
if (editandoId) {
|
|
await apiCall("PUT", `/reminders/${editandoId}`, payload);
|
|
toast("Recordatorio actualizado");
|
|
} else {
|
|
await apiCall("POST", "/reminders", payload);
|
|
toast("Recordatorio creado");
|
|
}
|
|
cerrarModal();
|
|
cargar();
|
|
} catch (e) {
|
|
toast(e.message || "Error al guardar", true);
|
|
}
|
|
}
|
|
|
|
async function eliminar(item) {
|
|
const etiqueta = item.nombre ? item.nombre : fmtDestinatario(item.destinatario);
|
|
if (!confirm(`¿Eliminar el recordatorio de ${etiqueta}?`)) return;
|
|
try {
|
|
await apiCall("DELETE", `/reminders/${item.id}`);
|
|
toast("Recordatorio eliminado");
|
|
cargar();
|
|
} catch (e) {
|
|
toast(e.message || "Error al eliminar", true);
|
|
}
|
|
}
|
|
|
|
elFab.addEventListener("click", () => abrirModal());
|
|
elBtnCancelar.addEventListener("click", cerrarModal);
|
|
elBtnGuardar.addEventListener("click", guardar);
|
|
elModalBg.addEventListener("click", (e) => { if (e.target === elModalBg) cerrarModal(); });
|
|
document.addEventListener("keydown", (e) => { if (e.key === "Escape") cerrarModal(); });
|
|
|
|
// Boot: validar token y cargar
|
|
(async () => {
|
|
if (!TOKEN) { mostrarBloqueo(); return; }
|
|
try {
|
|
await apiCall("GET", "/reminders/validate");
|
|
mostrarApp();
|
|
cargar();
|
|
} catch (e) {
|
|
mostrarBloqueo();
|
|
}
|
|
})();
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|