'use client' import React from 'react' import { IoClose } from 'react-icons/io5' interface NotificationType { id: number detector_id: number detector_name: string type: string status: string message: string timestamp: string location: string object: string acknowledged: boolean priority: string } interface DetectorType { detector_id: number name: string serial_number: string object: string status: string type: string location: string floor: number checked: boolean notifications: Array<{ id: number type: string message: string timestamp: string acknowledged: boolean priority: string }> } interface DetectorsDataType { detectors: Record } interface NotificationsProps { objectId?: string detectorsData: DetectorsDataType onNotificationClick: (notification: NotificationType) => void onClose: () => void } const Notifications: React.FC = ({ objectId, detectorsData, onNotificationClick, onClose }) => { const allNotifications = React.useMemo(() => { const notifications: NotificationType[] = []; Object.values(detectorsData.detectors).forEach(detector => { if (detector.notifications && detector.notifications.length > 0) { detector.notifications.forEach(notification => { notifications.push({ ...notification, detector_id: detector.detector_id, detector_name: detector.name, location: detector.location, object: detector.object, status: detector.status }); }); } }); return notifications; }, [detectorsData]); // сортировка по objectId const filteredNotifications = objectId ? allNotifications.filter(notification => notification.object.toString() === objectId.toString()) : allNotifications // сортировка по timestamp const sortedNotifications = [...filteredNotifications].sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()) const getStatusColor = (type: string) => { switch (type.toLowerCase()) { case 'critical': return 'bg-red-500' case 'warning': return 'bg-orange-500' case 'info': return 'bg-green-500' default: return 'bg-gray-500' } } return (

Уведомления

{/* Список уведомлений*/}
{sortedNotifications.length === 0 ? (

Уведомления не найдены

) : (
{sortedNotifications.map((notification) => (
{notification.detector_name}
{notification.message}
))}
)}
) } export default Notifications