Actualizar crear-cita.html
This commit is contained in:
@@ -109,6 +109,10 @@
|
|||||||
<button type="submit" id="btnSubmitFinal" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-black py-4 rounded-xl shadow-xl shadow-blue-200 transition-all flex items-center justify-center gap-2 active:scale-95 uppercase tracking-wider text-sm mt-4">
|
<button type="submit" id="btnSubmitFinal" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-black py-4 rounded-xl shadow-xl shadow-blue-200 transition-all flex items-center justify-center gap-2 active:scale-95 uppercase tracking-wider text-sm mt-4">
|
||||||
<span>Buscar Técnico</span> <i data-lucide="search" class="w-4 h-4"></i>
|
<span>Buscar Técnico</span> <i data-lucide="search" class="w-4 h-4"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button type="button" onclick="logoutClient()" class="w-full text-slate-400 text-xs font-bold uppercase tracking-wider mt-4 hover:text-slate-600 transition-colors">
|
||||||
|
Cambiar de número de teléfono
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -153,6 +157,37 @@
|
|||||||
// Estado del cliente
|
// Estado del cliente
|
||||||
let currentClient = null;
|
let currentClient = null;
|
||||||
|
|
||||||
|
// 🔄 AUTO-LOGIN: Comprobar sesión guardada al abrir la web
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
const sesionGuardada = localStorage.getItem('clienteSesion');
|
||||||
|
if (sesionGuardada) {
|
||||||
|
try {
|
||||||
|
const datos = JSON.parse(sesionGuardada);
|
||||||
|
// Comprobamos si la fecha actual es menor que la fecha de caducidad (10 días)
|
||||||
|
if (Date.now() < datos.expires) {
|
||||||
|
console.log("Sesión recuperada. Saltando validación...");
|
||||||
|
// Rellenamos el teléfono por debajo para que el formulario final lo pueda leer
|
||||||
|
document.getElementById('cliPhone').value = datos.phone;
|
||||||
|
prepareStep3(datos.client);
|
||||||
|
goToStep(3);
|
||||||
|
} else {
|
||||||
|
// Si pasaron 10 días, borramos la sesión
|
||||||
|
localStorage.removeItem('clienteSesion');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
localStorage.removeItem('clienteSesion');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 🚪 FUNCIÓN PARA CERRAR SESIÓN
|
||||||
|
function logoutClient() {
|
||||||
|
localStorage.removeItem('clienteSesion');
|
||||||
|
document.getElementById('cliPhone').value = "";
|
||||||
|
document.getElementById('cliCode').value = "";
|
||||||
|
goToStep(1);
|
||||||
|
}
|
||||||
|
|
||||||
// --- NAVEGACIÓN ENTRE PASOS ---
|
// --- NAVEGACIÓN ENTRE PASOS ---
|
||||||
function goToStep(step) {
|
function goToStep(step) {
|
||||||
document.getElementById('step1').classList.add('hidden');
|
document.getElementById('step1').classList.add('hidden');
|
||||||
@@ -235,6 +270,14 @@
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (data.ok) {
|
if (data.ok) {
|
||||||
|
// 💾 MAGIA: Guardamos la sesión por 10 días
|
||||||
|
const caducidad = Date.now() + (10 * 24 * 60 * 60 * 1000);
|
||||||
|
localStorage.setItem('clienteSesion', JSON.stringify({
|
||||||
|
phone: phone,
|
||||||
|
client: data.exists ? data.client : null,
|
||||||
|
expires: caducidad
|
||||||
|
}));
|
||||||
|
|
||||||
prepareStep3(data.exists ? data.client : null);
|
prepareStep3(data.exists ? data.client : null);
|
||||||
goToStep(3);
|
goToStep(3);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user