Actualizar calendario.html
This commit is contained in:
@@ -653,7 +653,7 @@
|
|||||||
async function openService(id) {
|
async function openService(id) {
|
||||||
let s = localServices.find(x => x.id === 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) {
|
if (!s) {
|
||||||
showToast("Cargando expediente...");
|
showToast("Cargando expediente...");
|
||||||
try {
|
try {
|
||||||
@@ -662,23 +662,33 @@
|
|||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.ok) {
|
if (data.ok) {
|
||||||
// Lo buscamos en la base de datos completa de servicios activos
|
|
||||||
s = data.services.find(x => x.id === id);
|
s = data.services.find(x => x.id === id);
|
||||||
if (s) {
|
if (s) {
|
||||||
// Lo añadimos a la memoria local para que funcione bien el modal
|
|
||||||
localServices.push(s);
|
localServices.push(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} 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') {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. Si existe, lo abrimos normalmente
|
||||||
const raw = s.raw_data;
|
const raw = s.raw_data;
|
||||||
currentServiceId = id;
|
currentServiceId = id;
|
||||||
|
|
||||||
@@ -727,7 +737,7 @@
|
|||||||
setTimeout(() => modal.classList.remove('translate-y-full'), 10);
|
setTimeout(() => modal.classList.remove('translate-y-full'), 10);
|
||||||
calculateDistance(fullAddress);
|
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)) {
|
if (activeNotifications.includes(id)) {
|
||||||
document.getElementById('chatContainer').classList.remove('hidden');
|
document.getElementById('chatContainer').classList.remove('hidden');
|
||||||
document.getElementById('chatContainer').classList.add('flex');
|
document.getElementById('chatContainer').classList.add('flex');
|
||||||
@@ -740,7 +750,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
safeLoadIcons();
|
safeLoadIcons();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
|
|||||||
Reference in New Issue
Block a user