This commit is contained in:
lizandrogd
2026-01-21 15:03:27 -05:00
parent 0f882f6b40
commit 972dc80c78
2 changed files with 39 additions and 2 deletions
+8 -1
View File
@@ -550,10 +550,17 @@
async loadNotifications() {
try {
const resp = await fetch('api/get_notifications.php');
const resp = await fetch('api/get_notifications.php', { credentials: 'same-origin' });
if (resp.status === 401) {
console.warn('Notifications fetch: unauthorized (session may have expired)');
return;
}
const json = await resp.json();
console.debug('loadNotifications response:', json);
if (json && json.success && Array.isArray(json.data)) {
json.data.forEach(n => this.showNotificationToast(n));
} else if (json && json.success === false) {
console.warn('get_notifications returned error:', json.error || json);
}
} catch (e) {
console.error('Error loading notifications', e);
+31 -1
View File
@@ -958,8 +958,14 @@ try {
},
async loadNotifications() {
try {
const resp = await fetch('api/get_notifications.php');
const resp = await fetch('api/get_notifications.php', { credentials: 'same-origin' });
if (resp.status === 401) {
console.warn('Notifications fetch: unauthorized (session may have expired)');
this.showSessionExpiredToast();
return;
}
const json = await resp.json();
console.debug('NotificationManager.loadNotifications response:', json);
if (json && json.success && Array.isArray(json.data)) {
const unreadCount = json.data.length;
if (unreadCount > 0) {
@@ -969,11 +975,35 @@ try {
this.countEl.style.display = 'none';
}
json.data.forEach(n => this.showToast(n));
} else if (json && json.success === false) {
console.warn('Notification API error:', json.error || json);
}
} catch (e) {
console.error('Error loading global notifications', e);
}
},
showSessionExpiredToast() {
const toast = document.createElement('div');
toast.className = 'notification-toast';
toast.style.background = '#fff7f7';
toast.style.border = '1px solid #f5c6cb';
toast.style.padding = '10px 14px';
toast.style.marginTop = '8px';
toast.style.borderRadius = '6px';
toast.style.minWidth = '220px';
const msg = document.createElement('div');
msg.textContent = 'La sesión ha expirado. Por favor, vuelve a iniciar sesión.';
toast.appendChild(msg);
const btn = document.createElement('button');
btn.className = 'btn btn-sm btn-primary';
btn.textContent = 'Ir a login';
btn.onclick = () => { window.location.href = 'login.php'; };
const actions = document.createElement('div');
actions.style.marginTop = '8px';
actions.appendChild(btn);
toast.appendChild(actions);
this.toastsContainer.appendChild(toast);
}
showToast(notification) {
const toast = document.createElement('div');
toast.className = 'notification-toast';