Improve the frontend 3

This commit is contained in:
Urtzi Alfaro
2025-10-30 21:08:07 +01:00
parent 36217a2729
commit 63f5c6d512
184 changed files with 21512 additions and 7442 deletions

View File

@@ -1,7 +1,7 @@
import React, { createContext, useContext, useEffect, useRef, useState, ReactNode } from 'react';
import { useAuthStore } from '../stores/auth.store';
import { useUIStore } from '../stores/ui.store';
import { useCurrentTenant } from '../stores/tenant.store';
import { showToast } from '../utils/toast';
interface SSEEvent {
type: string;
@@ -41,7 +41,6 @@ export const SSEProvider: React.FC<SSEProviderProps> = ({ children }) => {
const reconnectAttempts = useRef(0);
const { isAuthenticated, token } = useAuthStore();
const { showToast } = useUIStore();
const currentTenant = useCurrentTenant();
const connect = () => {
@@ -137,12 +136,7 @@ export const SSEProvider: React.FC<SSEProviderProps> = ({ children }) => {
toastType = 'info';
}
showToast({
type: toastType,
title: data.title || 'Notificación',
message: data.message,
duration: data.severity === 'urgent' ? 0 : 5000,
});
showToast[toastType](data.message, { title: data.title || 'Notificación', duration: data.severity === 'urgent' ? 0 : 5000 });
}
// Trigger registered listeners
@@ -200,12 +194,7 @@ export const SSEProvider: React.FC<SSEProviderProps> = ({ children }) => {
else if (data.severity === 'medium') toastType = 'warning';
else toastType = 'info';
showToast({
type: toastType,
title: data.title || 'Alerta',
message: data.message,
duration: data.severity === 'urgent' ? 0 : 5000,
});
showToast[toastType](data.message, { title: data.title || 'Alerta', duration: data.severity === 'urgent' ? 0 : 5000 });
// Trigger listeners
const listeners = eventListenersRef.current.get('alert');
@@ -230,12 +219,7 @@ export const SSEProvider: React.FC<SSEProviderProps> = ({ children }) => {
setLastEvent(sseEvent);
// Show recommendation toast
showToast({
type: 'info',
title: data.title || 'Recomendación',
message: data.message,
duration: 5000,
});
showToast.info(data.message, { title: data.title || 'Recomendación', duration: 5000 });
// Trigger listeners
const listeners = eventListenersRef.current.get('recommendation');
@@ -262,12 +246,7 @@ export const SSEProvider: React.FC<SSEProviderProps> = ({ children }) => {
// Show urgent alert toast
const toastType = data.severity === 'urgent' ? 'error' : 'error';
showToast({
type: toastType,
title: data.title || 'Alerta de Inventario',
message: data.message,
duration: data.severity === 'urgent' ? 0 : 5000,
});
showToast[toastType](data.message, { title: data.title || 'Alerta de Inventario', duration: data.severity === 'urgent' ? 0 : 5000 });
// Trigger alert listeners
const listeners = eventListenersRef.current.get('alert');
@@ -297,12 +276,7 @@ export const SSEProvider: React.FC<SSEProviderProps> = ({ children }) => {
else if (data.severity === 'high') toastType = 'warning';
else if (data.severity === 'medium') toastType = 'info';
showToast({
type: toastType,
title: data.title || 'Notificación',
message: data.message,
duration: data.severity === 'urgent' ? 0 : 5000,
});
showToast[toastType](data.message, { title: data.title || 'Notificación', duration: data.severity === 'urgent' ? 0 : 5000 });
// Trigger listeners for both notification and specific type
const notificationListeners = eventListenersRef.current.get('notification');