Actualizar index.html

This commit is contained in:
2026-02-21 18:51:40 +00:00
parent e271a3b182
commit 87972f4be1

View File

@@ -7,116 +7,145 @@
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/lucide@latest"></script> <script src="https://unpkg.com/lucide@latest"></script>
<style> <style>
body { background-color: #f8fafc; } body {
.fade-in { animation: fadeIn 0.4s ease-out forwards; } background-color: #f4f7f9;
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } } /* Patrón de fondo muy sutil */
.glass-panel { background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(10px); } background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
background-size: 24px 24px;
}
.fade-in { animation: fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.blob {
position: absolute;
filter: blur(60px);
z-index: -1;
opacity: 0.4;
}
</style> </style>
</head> </head>
<body class="text-slate-800 font-sans antialiased min-h-screen flex flex-col items-center"> <body class="text-slate-800 font-sans antialiased min-h-screen flex flex-col items-center relative overflow-x-hidden">
<div id="loader" class="fixed inset-0 bg-slate-50 z-50 flex flex-col items-center justify-center transition-opacity duration-300"> <div class="blob bg-blue-300 w-64 h-64 rounded-full top-[-50px] left-[-50px]"></div>
<div class="w-12 h-12 border-4 border-blue-200 border-t-blue-600 rounded-full animate-spin mb-4"></div> <div class="blob bg-emerald-200 w-64 h-64 rounded-full top-[20%] right-[-100px]"></div>
<p class="text-sm font-bold text-slate-500 animate-pulse">Cargando tu expediente...</p>
</div>
<div id="errorScreen" class="hidden w-full max-w-md mx-auto p-6 flex flex-col items-center justify-center min-h-screen text-center fade-in"> <div id="loader" class="fixed inset-0 bg-slate-50/90 backdrop-blur-md z-50 flex flex-col items-center justify-center transition-opacity duration-300">
<div class="w-20 h-20 bg-red-100 text-red-500 rounded-full flex items-center justify-center mb-6 shadow-inner"> <div class="relative w-16 h-16 flex items-center justify-center mb-4">
<i data-lucide="shield-alert" class="w-10 h-10"></i> <div class="absolute inset-0 border-4 border-blue-100 border-t-blue-600 rounded-full animate-spin"></div>
<i data-lucide="wrench" class="w-6 h-6 text-blue-600 animate-pulse"></i>
</div> </div>
<h2 class="text-2xl font-black text-slate-800 mb-2">Enlace no válido</h2> <p class="text-sm font-black tracking-widest uppercase text-slate-500 animate-pulse">Conectando...</p>
<p class="text-slate-500 font-medium">Parece que este enlace ha caducado o no es correcto. Por favor, solicita un nuevo acceso a tu empresa de reparaciones.</p>
</div> </div>
<main id="mainContent" class="hidden w-full max-w-md mx-auto min-h-screen flex flex-col relative pb-24"> <div id="errorScreen" class="hidden w-full max-w-md mx-auto p-6 flex flex-col items-center justify-center min-h-screen text-center fade-in z-10 relative">
<div class="w-24 h-24 bg-red-50 text-red-500 rounded-full flex items-center justify-center mb-6 shadow-xl shadow-red-500/20 border border-red-100">
<i data-lucide="shield-alert" class="w-12 h-12"></i>
</div>
<h2 class="text-3xl font-black text-slate-800 mb-3 tracking-tight">Enlace no válido</h2>
<p class="text-slate-500 font-medium leading-relaxed">Parece que este enlace ha caducado o no es correcto. Por favor, solicita un nuevo acceso a tu empresa reparadora.</p>
</div>
<main id="mainContent" class="hidden w-full max-w-md mx-auto min-h-screen flex flex-col relative pb-10 z-10">
<header class="bg-slate-900 text-white p-6 pt-10 rounded-b-[2.5rem] shadow-lg relative z-10 shrink-0"> <div class="pt-10 pb-6 px-6 flex flex-col items-center text-center fade-in" style="animation-delay: 0.1s;">
<div class="flex items-center justify-between"> <div id="companyLogoContainer" class="hidden relative mb-5">
<div class="flex items-center gap-3"> <div class="absolute inset-0 bg-blue-500 rounded-3xl blur-xl opacity-20"></div>
<div id="companyLogoContainer" class="hidden w-12 h-12 bg-white rounded-xl p-1 shadow-sm shrink-0"> <div class="relative w-28 h-28 bg-white rounded-3xl shadow-lg border border-slate-100 flex items-center justify-center overflow-hidden p-3">
<img id="companyLogo" src="" class="w-full h-full object-contain rounded-lg"> <img id="companyLogo" src="" class="w-full h-full object-contain">
</div>
<div>
<p class="text-[10px] font-black text-blue-400 uppercase tracking-widest mb-1">Gestión de Siniestro</p>
<h1 id="companyName" class="text-xl font-black tracking-tight leading-none uppercase line-clamp-2">Empresa Reparadora</h1>
</div>
</div> </div>
</div> </div>
</header>
<div class="px-5 -mt-6 relative z-20 flex-1 flex flex-col gap-5 fade-in">
<div class="bg-white p-6 rounded-[2rem] shadow-xl shadow-slate-200/50 border border-slate-100"> <p class="text-[10px] font-black text-blue-600 uppercase tracking-widest mb-1.5 opacity-80">Gestión de Siniestro</p>
<h2 class="text-2xl font-black text-slate-800 mb-1">Hola, <span id="clientName" class="text-blue-600">Cliente</span></h2> <h1 id="companyName" class="text-2xl font-black tracking-tight text-slate-900 uppercase leading-none">Empresa Reparadora</h1>
<p class="text-sm text-slate-500 font-medium mb-5">Aquí tienes los detalles de tu reparación.</p> </div>
<div class="px-5 flex-1 flex flex-col gap-6 fade-in" style="animation-delay: 0.2s;">
<div class="bg-white/80 backdrop-blur-xl p-7 rounded-[2.5rem] shadow-xl shadow-slate-200/40 border border-white">
<h2 class="text-3xl font-black text-slate-800 mb-1 tracking-tight">Hola, <span id="clientName" class="text-blue-600">Cliente</span></h2>
<p class="text-sm text-slate-500 font-medium mb-6">Detalles de tu expediente <span id="serviceRef" class="font-bold text-slate-700 bg-slate-100 px-2 py-0.5 rounded text-xs ml-1">#0000</span></p>
<div id="dateContainer"> <div id="dateContainer">
</div> </div>
</div> </div>
<div id="workerCard" class="bg-gradient-to-br from-blue-50 to-indigo-50 p-6 rounded-[2rem] border border-blue-100 shadow-sm hidden"> <div id="workerCard" class="bg-white/80 backdrop-blur-xl p-7 rounded-[2.5rem] border border-white shadow-xl shadow-slate-200/40 hidden fade-in" style="animation-delay: 0.3s;">
<p class="text-[10px] font-black text-blue-500 uppercase tracking-widest mb-4">Técnico Asignado</p> <div class="flex justify-between items-center mb-5">
<div class="flex items-center gap-4 mb-5"> <p class="text-[10px] font-black text-indigo-500 uppercase tracking-widest">Técnico Asignado</p>
<div class="w-14 h-14 bg-white rounded-full flex items-center justify-center shadow-md text-blue-600 shrink-0"> <span class="relative flex h-3 w-3">
<i data-lucide="user-check" class="w-7 h-7"></i> <span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75"></span>
<span class="relative inline-flex rounded-full h-3 w-3 bg-emerald-500"></span>
</span>
</div>
<div class="flex items-center gap-5 mb-6">
<div class="w-16 h-16 bg-gradient-to-br from-indigo-50 to-blue-50 border border-blue-100 rounded-full flex items-center justify-center shadow-inner text-blue-600 shrink-0">
<i data-lucide="user" class="w-8 h-8"></i>
</div> </div>
<div> <div>
<h3 id="workerName" class="font-black text-slate-800 text-lg uppercase leading-tight">Juan Pérez</h3> <h3 id="workerName" class="font-black text-slate-800 text-xl uppercase leading-tight tracking-tight">Juan Pérez</h3>
<p class="text-xs text-slate-500 font-medium mt-0.5">Operario Especialista</p> <p class="text-xs text-slate-500 font-medium mt-1">Operario Especialista</p>
</div> </div>
</div> </div>
<div class="grid grid-cols-2 gap-3">
<a href="#" id="btnCall" class="bg-white border border-blue-200 text-blue-700 font-black py-3 rounded-xl flex justify-center items-center gap-2 shadow-sm hover:bg-blue-50 transition active:scale-95 text-xs uppercase tracking-wider"> <div class="grid grid-cols-2 gap-4">
<a href="#" id="btnCall" class="bg-white border-2 border-slate-100 text-slate-700 font-black py-3.5 rounded-2xl flex justify-center items-center gap-2 shadow-sm hover:border-blue-200 hover:text-blue-600 transition-all active:scale-95 text-xs uppercase tracking-wider">
<i data-lucide="phone" class="w-4 h-4"></i> Llamar <i data-lucide="phone" class="w-4 h-4"></i> Llamar
</a> </a>
<a href="#" id="btnWa" class="bg-emerald-500 text-white font-black py-3 rounded-xl flex justify-center items-center gap-2 shadow-md shadow-emerald-200 hover:bg-emerald-600 transition active:scale-95 text-xs uppercase tracking-wider"> <a href="#" id="btnWa" class="bg-[#25D366] text-white font-black py-3.5 rounded-2xl flex justify-center items-center gap-2 shadow-lg shadow-[#25D366]/30 hover:bg-[#128C7E] transition-all active:scale-95 text-xs uppercase tracking-wider">
<i data-lucide="message-circle" class="w-4 h-4"></i> WhatsApp <i data-lucide="message-circle" class="w-4 h-4 text-white fill-white"></i> WhatsApp
</a> </a>
</div> </div>
</div> </div>
<div class="bg-white p-6 rounded-[2rem] shadow-sm border border-slate-100 space-y-5"> <div class="bg-white/80 backdrop-blur-xl p-7 rounded-[2.5rem] shadow-xl shadow-slate-200/40 border border-white space-y-6 fade-in" style="animation-delay: 0.4s;">
<p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-2">Detalles del Aviso <span id="serviceRef" class="float-right text-slate-300">#0000</span></p> <p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-2 border-b border-slate-100 pb-3">Información del Aviso</p>
<div class="flex items-start gap-3"> <div class="flex items-start gap-4">
<div class="bg-slate-50 p-2 rounded-lg text-slate-400 mt-0.5"><i data-lucide="map-pin" class="w-4 h-4"></i></div> <div class="bg-slate-50 border border-slate-100 w-10 h-10 flex items-center justify-center rounded-2xl text-slate-400 shrink-0"><i data-lucide="map-pin" class="w-5 h-5"></i></div>
<div> <div>
<p class="text-xs font-bold text-slate-400 uppercase">Dirección</p> <p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-0.5">Dirección</p>
<p id="serviceAddress" class="font-bold text-slate-700 text-sm mt-0.5 uppercase"></p> <p id="serviceAddress" class="font-bold text-slate-700 text-sm uppercase leading-snug"></p>
</div> </div>
</div> </div>
<div class="flex items-start gap-3"> <div class="flex items-start gap-4">
<div class="bg-slate-50 p-2 rounded-lg text-slate-400 mt-0.5"><i data-lucide="phone" class="w-4 h-4"></i></div> <div class="bg-slate-50 border border-slate-100 w-10 h-10 flex items-center justify-center rounded-2xl text-slate-400 shrink-0"><i data-lucide="phone" class="w-5 h-5"></i></div>
<div> <div>
<p class="text-xs font-bold text-slate-400 uppercase">Teléfono de Contacto</p> <p class="text-[10px] font-black text-slate-400 uppercase tracking-widest mb-0.5">Teléfono de Contacto</p>
<p id="servicePhone" class="font-bold text-slate-700 text-sm mt-0.5"></p> <p id="servicePhone" class="font-black text-slate-700 text-sm"></p>
</div> </div>
</div> </div>
<div class="flex items-start gap-3"> <div class="flex items-start gap-4">
<div class="bg-amber-50 p-2 rounded-lg text-amber-500 mt-0.5"><i data-lucide="alert-triangle" class="w-4 h-4"></i></div> <div class="bg-amber-50 border border-amber-100 w-10 h-10 flex items-center justify-center rounded-2xl text-amber-500 shrink-0"><i data-lucide="alert-triangle" class="w-5 h-5"></i></div>
<div> <div class="w-full">
<p class="text-xs font-bold text-amber-500 uppercase">Avería Reportada</p> <p class="text-[10px] font-black text-amber-600 uppercase tracking-widest mb-1.5">Avería Reportada</p>
<p id="serviceDesc" class="font-medium text-slate-600 text-sm mt-1 bg-slate-50 p-3 rounded-xl leading-relaxed"></p> <div class="bg-slate-50 border border-slate-100 p-4 rounded-2xl">
<p id="serviceDesc" class="font-medium text-slate-600 text-sm leading-relaxed"></p>
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="text-center mt-4 mb-2">
<p class="text-[10px] font-bold text-slate-400">Tecnología de gestión por IntegraRepara</p>
</div>
</div> </div>
</main> </main>
<script> <script>
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
? 'http://localhost:3000' ? 'http://localhost:3000'
: 'https://integrarepara-api.integrarepara.es'; // <-- Asegúrate de que esta URL es correcta : 'https://integrarepara-api.integrarepara.es';
</script> </script>
<script> <script>
document.addEventListener("DOMContentLoaded", async () => { document.addEventListener("DOMContentLoaded", async () => {
lucide.createIcons(); lucide.createIcons();
// 1. Extraer variables de la URL
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const token = urlParams.get('token'); const token = urlParams.get('token');
const serviceId = urlParams.get('service'); const serviceId = urlParams.get('service');
@@ -127,17 +156,14 @@
} }
try { try {
// 2. Pedir datos al servidor usando el token
const res = await fetch(`${API_URL}/public/portal/${token}`); const res = await fetch(`${API_URL}/public/portal/${token}`);
const data = await res.json(); const data = await res.json();
if (!data.ok) throw new Error("Token inválido"); if (!data.ok) throw new Error("Token inválido");
// 3. Buscar el servicio específico
const service = data.services.find(s => String(s.id) === String(serviceId)); const service = data.services.find(s => String(s.id) === String(serviceId));
if (!service) throw new Error("Servicio no encontrado"); if (!service) throw new Error("Servicio no encontrado");
// 4. Renderizar datos en pantalla
renderPortal(data.client, data.company, service); renderPortal(data.client, data.company, service);
} catch (e) { } catch (e) {
@@ -156,18 +182,16 @@
} }
function renderPortal(client, company, service) { function renderPortal(client, company, service) {
// Textos básicos y Logo // Textos básicos y Logo rediseñado
document.getElementById('companyName').innerText = company.name || "Empresa Reparadora"; document.getElementById('companyName').innerText = company.name || "Empresa Reparadora";
if (company.logo) { if (company.logo) {
document.getElementById('companyLogo').src = company.logo; document.getElementById('companyLogo').src = company.logo;
document.getElementById('companyLogoContainer').classList.remove('hidden'); document.getElementById('companyLogoContainer').classList.remove('hidden');
} }
document.getElementById('clientName').innerText = client.name.split(' ')[0]; // Solo el primer nombre
document.getElementById('clientName').innerText = client.name.split(' ')[0];
document.getElementById('serviceRef').innerText = "#" + (service.title.replace('Expediente #', '') || service.id); document.getElementById('serviceRef').innerText = "#" + (service.title.replace('Expediente #', '') || service.id);
// Dirección, Teléfono y Descripción
// NOTA: Como la API no devuelve la dirección dentro de service directamente en public/portal, usamos la del cliente por ahora.
// Si quieres la exacta del parte, tendremos que añadirla a la API después.
document.getElementById('serviceAddress').innerText = client.addresses[0] || "Dirección no especificada"; document.getElementById('serviceAddress').innerText = client.addresses[0] || "Dirección no especificada";
document.getElementById('servicePhone').innerText = client.phone; document.getElementById('servicePhone').innerText = client.phone;
document.getElementById('serviceDesc').innerText = service.description || "Avería general reportada."; document.getElementById('serviceDesc').innerText = service.description || "Avería general reportada.";
@@ -177,41 +201,43 @@
document.getElementById('workerCard').classList.remove('hidden'); document.getElementById('workerCard').classList.remove('hidden');
document.getElementById('workerName').innerText = service.assigned_worker; document.getElementById('workerName').innerText = service.assigned_worker;
// NOTA TÉCNICA: De momento el servidor no devuelve el teléfono del operario.
// Ponemos los botones con un alert temporal hasta que actualicemos server.js
document.getElementById('btnCall').onclick = (e) => { e.preventDefault(); alert("Falta conectar el teléfono del operario en el servidor. Lo haremos en el siguiente paso."); }; document.getElementById('btnCall').onclick = (e) => { e.preventDefault(); alert("Falta conectar el teléfono del operario en el servidor. Lo haremos en el siguiente paso."); };
document.getElementById('btnWa').onclick = (e) => { e.preventDefault(); alert("Falta conectar el teléfono del operario en el servidor. Lo haremos en el siguiente paso."); }; document.getElementById('btnWa').onclick = (e) => { e.preventDefault(); alert("Falta conectar el teléfono del operario en el servidor. Lo haremos en el siguiente paso."); };
} }
// ¿Hay cita o está pendiente de agendar? // ¿Hay cita o está pendiente de agendar? (Rediseño de la tarjeta interior)
const dateContainer = document.getElementById('dateContainer'); const dateContainer = document.getElementById('dateContainer');
if (service.scheduled_date) { if (service.scheduled_date) {
// Ya tiene cita // Nuevo diseño de Cita Confirmada (Gradient Premium)
dateContainer.innerHTML = ` dateContainer.innerHTML = `
<div class="bg-emerald-50 border border-emerald-200 p-4 rounded-2xl flex items-center gap-4"> <div class="bg-gradient-to-br from-emerald-400 to-emerald-600 p-5 rounded-[1.5rem] flex items-center gap-5 text-white shadow-lg shadow-emerald-500/30 relative overflow-hidden">
<div class="w-12 h-12 bg-white rounded-xl flex flex-col items-center justify-center shadow-sm shrink-0 border border-emerald-100"> <div class="absolute -right-4 -top-4 opacity-10">
<span class="text-[10px] font-black text-emerald-500 uppercase leading-none">Cita</span> <i data-lucide="calendar-check" class="w-32 h-32"></i>
<i data-lucide="check" class="w-5 h-5 text-emerald-600 mt-1"></i>
</div> </div>
<div> <div class="w-14 h-14 bg-white/20 rounded-2xl flex flex-col items-center justify-center backdrop-blur-md border border-white/30 shrink-0 relative z-10">
<p class="font-black text-slate-800 uppercase text-sm">${formatDate(service.scheduled_date)}</p> <i data-lucide="calendar-check" class="w-7 h-7 text-white"></i>
<p class="text-xs font-bold text-emerald-600 mt-0.5 flex items-center gap-1"><i data-lucide="clock" class="w-3 h-3"></i> Turno: ${service.scheduled_time || 'A convenir'}</p> </div>
<div class="relative z-10">
<p class="text-[9px] font-black uppercase tracking-widest text-emerald-100 mb-1">Visita Confirmada</p>
<p class="font-black uppercase text-lg leading-none mb-1.5">${formatDate(service.scheduled_date)}</p>
<p class="text-sm font-bold text-emerald-50 flex items-center gap-1.5"><i data-lucide="clock" class="w-4 h-4"></i> Turno: ${service.scheduled_time || 'A convenir'}</p>
</div> </div>
</div> </div>
`; `;
} else { } else {
// NO tiene cita (Mostrar botón de Agendar) // Nuevo diseño de Pendiente de Cita (Llamada a la acción vibrante)
dateContainer.innerHTML = ` dateContainer.innerHTML = `
<div class="bg-amber-50 border border-amber-200 p-5 rounded-2xl text-center"> <div class="bg-blue-50/50 border border-blue-100 p-6 rounded-[1.5rem] text-center">
<div class="w-12 h-12 bg-amber-100 text-amber-600 rounded-full flex items-center justify-center mx-auto mb-3"> <div class="w-14 h-14 bg-blue-100 text-blue-600 rounded-full flex items-center justify-center mx-auto mb-4 relative">
<i data-lucide="calendar-plus" class="w-6 h-6"></i> <span class="absolute inset-0 bg-blue-200 rounded-full animate-ping opacity-50"></span>
<i data-lucide="calendar-clock" class="w-7 h-7 relative z-10"></i>
</div> </div>
<h4 class="font-black text-slate-800 uppercase text-lg leading-tight">Pendiente de Cita</h4> <h4 class="font-black text-slate-800 uppercase text-lg leading-tight tracking-tight">Pendiente de Cita</h4>
<p class="text-xs text-slate-600 font-medium mt-1 mb-4">El técnico necesita saber cuándo puede pasar por tu domicilio.</p> <p class="text-xs text-slate-500 font-medium mt-2 mb-5">El técnico necesita saber cuándo puede pasar por tu domicilio para la reparación.</p>
<button onclick="startBooking()" class="w-full bg-slate-900 text-white font-black py-4 rounded-xl shadow-lg hover:bg-blue-600 transition-all active:scale-95 flex justify-center items-center gap-2 uppercase tracking-widest text-xs"> <button onclick="startBooking()" class="w-full bg-blue-600 text-white font-black py-4 rounded-2xl shadow-xl shadow-blue-600/30 hover:bg-blue-700 hover:shadow-blue-700/40 transition-all active:scale-95 flex justify-center items-center gap-2 uppercase tracking-widest text-xs">
<i data-lucide="calendar-check" class="w-4 h-4"></i> Agendar Visita Ahora Agendar Visita Ahora <i data-lucide="arrow-right" class="w-4 h-4"></i>
</button> </button>
</div> </div>
`; `;
@@ -241,10 +267,8 @@
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const token = urlParams.get('token'); const token = urlParams.get('token');
const serviceId = urlParams.get('service'); const serviceId = urlParams.get('service');
// Redirige a la nueva web pasándole los datos
window.location.href = `cita.html?token=${token}&service=${serviceId}`; window.location.href = `cita.html?token=${token}&service=${serviceId}`;
} }
</script> </script>
</body> </body>
</html> </html>