import React, { memo, useState, useEffect } from 'react'; import { Button, Row, Col, Card, Badge, Input, Typography, Space } from 'antd'; import { CloseCircleFilled, WarningFilled, CheckCircleFilled, InfoCircleFilled, ClockCircleOutlined, EnvironmentOutlined, LinkOutlined, SendOutlined, MailOutlined, UserOutlined, FileTextOutlined, HistoryOutlined, EyeOutlined, } from '@ant-design/icons'; import { useNavigate } from 'react-router-dom'; const { Text, Paragraph, Link } = Typography; // Dummy data untuk notifikasi const initialNotifications = [ { id: 1, type: 'critical', title: 'Compressor Unit A', issue: 'Overheat detected (85°C)', description: '⚠️ Compressor Unit A - Overheat Detected (85°C) 🚨', timestamp: '04-11-2025 11.39 WIB', location: 'Lantai 2, Area Produksi A, Zona 3', details: 'Terjadi kenaikan suhu melebihi ambang batas pada Compressor Unit A. Pengecekan potensi kerusakan dibutuhkan.', link: 'https://tinyurl.com/compA85', isRead: false, }, { id: 2, type: 'warning', title: 'Compressor Unit C', issue: 'Pressure slightly high (7.2 bar)', description: '🔧 Compressor Unit C - Pressure High (7.2 bar)', timestamp: '04-11-2025 11.30 WIB', location: 'Lantai 1, Area Produksi C, Zona 1', details: 'Tekanan mendekati ambang batas atas. Perlu monitoring lebih lanjut oleh engineer.', link: 'https://tinyurl.com/compC72', isRead: false, }, { id: 3, type: 'resolved', title: 'Compressor Unit B', issue: 'Vibration issue resolved', description: '✅ Compressor Unit B - Vibration Resolved', timestamp: '04-11-2025 10.05 WIB', location: 'Lantai 2, Area Produksi B, Zona 2', details: 'Getaran pada Unit B telah kembali normal setelah perbaikan.', link: 'https://tinyurl.com/compBresolved', isRead: true, }, ]; const ListNotification = memo(function ListNotification(props) { const [notifications, setNotifications] = useState(initialNotifications); const [activeTab, setActiveTab] = useState('all'); const [searchTerm, setSearchTerm] = useState(''); const navigate = useNavigate(); useEffect(() => { const token = localStorage.getItem('token'); if (!token) { navigate('/signin'); } }, [navigate]); const getIconAndColor = (type) => { switch (type) { case 'critical': return { IconComponent: CloseCircleFilled, color: '#ff4d4f', bgColor: '#fff1f0', }; case 'warning': return { IconComponent: WarningFilled, color: '#faad14', bgColor: '#fffbe6', }; case 'resolved': return { IconComponent: CheckCircleFilled, color: '#52c41a', bgColor: '#f6ffed', }; default: return { IconComponent: InfoCircleFilled, color: '#1890ff', bgColor: '#e6f7ff', }; } }; const handleMarkAsRead = (id) => { setNotifications((prev) => prev.map((n) => (n.id === id ? { ...n, isRead: true } : n)) ); }; const filteredNotifications = notifications .filter((n) => { if (activeTab === 'all') return true; if (activeTab === 'unread') return !n.isRead; if (activeTab === 'read') return n.isRead; return true; }) .filter((n) => { if (!searchTerm) return true; const searchableText = `${n.title} ${n.issue} ${n.description} ${n.location} ${n.details}`.toLowerCase(); return searchableText.includes(searchTerm.toLowerCase()); }); const getUnreadCount = () => { return notifications.filter((n) => !n.isRead).length; }; const tabButtonStyle = (isActive) => ({ padding: '12px 16px', border: 'none', background: 'none', cursor: 'pointer', fontSize: '14px', fontWeight: 500, color: isActive ? '#FF6B35' : '#595959', borderBottom: isActive ? '2px solid #FF6B35' : '2px solid transparent', marginBottom: '-1px', transition: 'all 0.3s', }); return (

Notification

Riwayat notifikasi yang dikirim ke engineer

setSearchTerm(value)} onChange={(e) => setSearchTerm(e.target.value)} style={{ marginBottom: '24px', width: 300 }} /> {/* Tabs */}
{/* Notification List */} {filteredNotifications.length === 0 ? (
Tidak ada notifikasi
) : ( filteredNotifications.map((notification) => { const { IconComponent, color, bgColor } = getIconAndColor( notification.type ); return ( handleMarkAsRead(notification.id)} >
{/* Icon */}
{/* Content */}
{/* Left: Title and Issue */}
{notification.title}
{notification.issue}
{!notification.isRead && ( )}
{/* Middle: Description and Details */}
{notification.description}
{notification.details}
{notification.timestamp} {notification.location} {notification.link} {/* Right: Action Icons */}
); }) )}
); }); export default ListNotification;