Actualizar calendario.html
This commit is contained in:
@@ -650,10 +650,10 @@
|
||||
safeLoadIcons();
|
||||
}
|
||||
|
||||
async function openService(id) {
|
||||
async function openService(id) {
|
||||
let s = localServices.find(x => x.id === id);
|
||||
|
||||
// 🔥 SOLUCIÓN: Si no lo encontramos en memoria, lo pedimos al servidor
|
||||
// 🔥 1. Si no lo encontramos en memoria, lo pedimos al servidor
|
||||
if (!s) {
|
||||
showToast("Cargando expediente...");
|
||||
try {
|
||||
@@ -662,23 +662,33 @@
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.ok) {
|
||||
// Lo buscamos en la base de datos completa de servicios activos
|
||||
s = data.services.find(x => x.id === id);
|
||||
if (s) {
|
||||
// Lo añadimos a la memoria local para que funcione bien el modal
|
||||
localServices.push(s);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error buscando servicio fantasma:", e);
|
||||
console.error("Error buscando servicio:", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 👻 2. EL MATA-FANTASMAS: Si definitivamente NO existe (está archivado o reasignado)
|
||||
if (!s || s.provider === 'SYSTEM_BLOCK') {
|
||||
showToast("No se pudo cargar el expediente", true);
|
||||
try {
|
||||
// Lo marcamos como leído a la fuerza en la base de datos para matar el globo rojo
|
||||
await fetch(`${API_URL}/services/${id}/chat/read`, {
|
||||
method: 'POST',
|
||||
headers: { 'Authorization': `Bearer ${localStorage.getItem("token")}` }
|
||||
});
|
||||
// Refrescamos las notificaciones visuales
|
||||
if (typeof checkNotifications === "function") checkNotifications();
|
||||
} catch(e) {}
|
||||
|
||||
showToast("Expediente archivado o reasignado. Notificación borrada.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Si existe, lo abrimos normalmente
|
||||
const raw = s.raw_data;
|
||||
currentServiceId = id;
|
||||
|
||||
@@ -727,7 +737,7 @@
|
||||
setTimeout(() => modal.classList.remove('translate-y-full'), 10);
|
||||
calculateDistance(fullAddress);
|
||||
|
||||
// 🔥 MEJORA: Al abrir desde notificación, abrimos el chat automáticamente
|
||||
// 🔥 AL ABRIR DESDE NOTIFICACIÓN, ABRIMOS EL CHAT AUTOMÁTICAMENTE
|
||||
if (activeNotifications.includes(id)) {
|
||||
document.getElementById('chatContainer').classList.remove('hidden');
|
||||
document.getElementById('chatContainer').classList.add('flex');
|
||||
@@ -740,7 +750,6 @@
|
||||
}
|
||||
|
||||
safeLoadIcons();
|
||||
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
|
||||
Reference in New Issue
Block a user