From b6dc08e599c31bd57c27f815c06c66bf948db34e Mon Sep 17 00:00:00 2001 From: josedario87 Date: Thu, 30 Oct 2025 18:03:37 -0600 Subject: [PATCH] Feat: Implementar sistema de notificaciones con historial por usuario MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Crear composable useNotifications con gestión por localStorage - Almacenamiento separado por usuario usando UID de Authentik - Auto-limpieza de notificaciones mayores a 30 días - Sincronización automática entre pestañas - Filtrado por tipo, búsqueda y gestión completa - Crear wrapper useToast para guardar toasts automáticamente - Intercepta todos los toasts de la aplicación - Guarda historial sin afectar funcionalidad existente - Implementar endpoints de API para notificaciones del backend - POST /api/notifications/send para enviar notificaciones - GET /api/notifications/list para obtener pendientes - Actualizar página de notificaciones con funcionalidad real - Búsqueda y filtros por tipo (info, warning, success, error) - Eliminar individual o todas las notificaciones - Marcar como leídas individual o todas - Badges de origen (toast, backend, manual) - Estados vacíos con mensajes informativos - Actualizar badge del sidebar con contador dinámico - Muestra número real de notificaciones no leídas - Se oculta cuando no hay notificaciones - Inicializar sistema en app.vue - Auto-inicialización al montar la app - Limpieza automática de notificaciones antiguas --- nuxt4-app/app/app.vue | 9 + nuxt4-app/app/components/app/AppSidebar.vue | 9 +- nuxt4-app/app/composables/useNotifications.ts | 267 +++++++++++ nuxt4-app/app/composables/useToast.ts | 80 ++++ nuxt4-app/app/pages/notifications.vue | 422 +++++++++++++----- .../server/api/notifications/list.get.ts | 71 +++ .../server/api/notifications/send.post.ts | 95 ++++ 7 files changed, 831 insertions(+), 122 deletions(-) create mode 100644 nuxt4-app/app/composables/useNotifications.ts create mode 100644 nuxt4-app/app/composables/useToast.ts create mode 100644 nuxt4-app/server/api/notifications/list.get.ts create mode 100644 nuxt4-app/server/api/notifications/send.post.ts diff --git a/nuxt4-app/app/app.vue b/nuxt4-app/app/app.vue index 73ce1ad..c7d8edb 100644 --- a/nuxt4-app/app/app.vue +++ b/nuxt4-app/app/app.vue @@ -13,6 +13,9 @@ // Inicializar sistema de temas const { loadTheme, initStorageListener, cleanupStorageListener } = useTheme() +// Inicializar sistema de notificaciones +const { initialize: initNotifications, cleanupOldNotifications } = useNotifications() + // Signal that the app is ready onMounted(() => { // Cargar tema guardado (o aplicar el por defecto) @@ -21,6 +24,12 @@ onMounted(() => { // Inicializar sincronización de tema entre pestañas initStorageListener() + // Inicializar sistema de notificaciones + initNotifications() + + // Limpiar notificaciones antiguas (> 30 días) + cleanupOldNotifications() + // Add class to HTML element to hide loading screen if (process.client) { // Small delay to ensure everything is painted diff --git a/nuxt4-app/app/components/app/AppSidebar.vue b/nuxt4-app/app/components/app/AppSidebar.vue index 96f0c41..ad6235b 100644 --- a/nuxt4-app/app/components/app/AppSidebar.vue +++ b/nuxt4-app/app/components/app/AppSidebar.vue @@ -156,12 +156,12 @@ Notificaciones -