"use client"; import React, { useState, useEffect } from "react"; import { Button } from "@/components/ui/button"; import { getNotifications } from "@/service/notifications/notifications"; import { CalendarCheck, CheckCheck, ChevronLeft, ChevronRight, CircleAlert, Clock7, MessageCircle, SquareCheck, UploadIcon, } from "lucide-react"; import { useRouter } from "next/navigation"; export type Notification = { id: number; notificationTypeId: number; message: string; createdAt: string; isActive: boolean; isPublic: boolean; isRead: boolean; redirectUrl: string; userGroupIdDst: string | null; userIdDst: string | null; userLevelIdDst: string; userLevelNumberDst: string | null; userRoleIdDst: string; }; const getNotificationIcon = (notificationTypeId: number) => { switch (notificationTypeId) { case 2: return ; case 3: return ; case 4: return ; case 5: return ; case 6: return ; case 7: return ; case 8: return ; default: return ; } }; const NotificationsList: React.FC = () => { const router = useRouter(); const [notifications, setNotifications] = useState([]); const [totalData, setTotalData] = useState(0); const [page, setPage] = useState(1); const [pageSize] = useState(10); const [totalPage, setTotalPage] = useState(1); useEffect(() => { async function fetchNotifications() { const response = await getNotifications(page - 1, pageSize); setNotifications(response?.data?.data?.content || []); setTotalData(response?.data?.data?.totalElements || 0); setTotalPage(response?.data?.data?.totalPages); } fetchNotifications(); }, [page, pageSize]); const handleNotificationClick = (redirectUrl: string) => { router.push(redirectUrl); }; const handlePageChange = (newPage: number) => { setPage(newPage); }; return ( {notifications.length > 0 ? ( notifications?.map((notification) => ( handleNotificationClick(notification.redirectUrl)} > {getNotificationIcon(notification.notificationTypeId)} {notification.message} {new Date(notification.createdAt).toLocaleString()} )) ) : ( Tidak ada notifikasi. )} {/* Pagination */} handlePageChange(page - 1)} disabled={page === 1} variant="outline" className="rounded-full" size="sm" > Page {page} of {totalPage} handlePageChange(page + 1)} disabled={page === totalPage} variant="outline" className="rounded-full" size="sm" > ); }; export default NotificationsList;
{notification.message}
{new Date(notification.createdAt).toLocaleString()}
Tidak ada notifikasi.
Page {page} of {totalPage}