import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Link } from "@/i18n/routing"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { cn } from "@/lib/utils"; import shortImage from "@/public/images/all-img/short-image-2.png"; import { Icon } from "@/components/ui/icon"; import { useEffect, useState } from "react"; import { getNotifications } from "@/service/notifications/notifications"; import { format, formatDate } from "date-fns"; import { CalendarCheck, CheckCheck, 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 Notifications = () => { const router = useRouter(); const [notifications, setNotifications] = useState([]); const [notificationTotal, setNotificationTotal] = useState(0); useEffect(() => { async function initState() { const response = await getNotifications(); setNotifications(response?.data?.data?.content); setNotificationTotal(response?.data?.data?.totalElements); console.log("notif", response?.data?.data?.content); } initState(); }, []); const formatDate = (dateString: string) => { const date = new Date(dateString); return format(date, "dd/MM/yyyy HH:mm"); }; const handleNotificationClick = (redirectUrl: string) => { router.push(redirectUrl); }; return (
you have {notificationTotal > 99 ? "99+" : notificationTotal}{" "} notifications
View all
{notifications?.map((item: Notification, index: number) => ( handleNotificationClick(item?.redirectUrl)} >
{getNotificationIcon(item.notificationTypeId)}
{item?.message}
{/*
{item?.desc}
*/}
{" "} {formatDate(item?.createdAt)}
{/* {item?.unreadmessage && (
)} */}
))}
); }; export default Notifications;