import { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import api from '@/services/api' import type { Notification } from '@/types' import dayjs from 'dayjs' export default function NotificationsPage() { const [notifications, setNotifications] = useState([]) const [unreadOnly, setUnreadOnly] = useState(false) const [unreadCount, setUnreadCount] = useState(0) const navigate = useNavigate() const fetchNotifications = () => { const params = new URLSearchParams() if (unreadOnly) params.set('unread_only', 'true') api.get(`/notifications?${params}`).then(({ data }) => setNotifications(data)) api.get<{ count: number }>('/notifications/count').then(({ data }) => setUnreadCount(data.count)).catch(() => {}) } useEffect(() => { fetchNotifications() }, [unreadOnly]) const markRead = async (id: number) => { await api.post(`/notifications/${id}/read`) fetchNotifications() } const markAllRead = async () => { await api.post('/notifications/read-all') fetchNotifications() } return (

🔔 Notifications {unreadCount > 0 && {unreadCount}}

{unreadCount > 0 && ( )}
{notifications.map((n) => (
{ if (!n.is_read) markRead(n.id) if (n.task_code) navigate(`/tasks/${n.task_code}`) }} >
{n.is_read ? '' : '●'}

{n.message}

{dayjs(n.created_at).format('MM-DD HH:mm')}
))} {notifications.length === 0 &&

No notifications

}
) }