"use client"; import * as React from "react"; import { BellIcon, CheckIcon, MoreHorizontal } from "lucide-react"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Badge } from "@/components/ui/badge"; import { ScrollArea } from "@/components/ui/scroll-area"; import { formatDistanceToNow } from "date-fns"; import { ko } from "date-fns/locale"; import { useNotifications } from "@/lib/notification/NotificationContext"; export function NotificationDropdown() { const { notifications, unreadCount, markAsRead, markAllAsRead } = useNotifications(); const handleNotificationClick = (notification: any) => { if (!notification.isRead) { markAsRead(notification.id); } // 관련 레코드로 이동 if (notification.relatedRecordId && notification.relatedRecordType) { const url = getNotificationUrl(notification.relatedRecordType, notification.relatedRecordId); window.location.href = url; } }; const getNotificationUrl = (type: string, id: string) => { const baseUrl = window.location.pathname.split('/').slice(0, 3).join('/'); switch (type) { case 'project': return `${baseUrl}/projects/${id}`; case 'task': return `${baseUrl}/tasks/${id}`; case 'order': return `${baseUrl}/orders/${id}`; default: return baseUrl; } }; const getNotificationIcon = (type: string) => { switch (type) { case 'assignment': return '📝'; case 'update': return '🔄'; case 'reminder': return '⏰'; case 'approval': return '✅'; default: return '🔔'; } }; return (
알림 {unreadCount > 0 && ( )}
{notifications.length === 0 ? (
새로운 알림이 없습니다
) : ( {notifications.slice(0, 10).map((notification) => ( handleNotificationClick(notification)} >
{getNotificationIcon(notification.type)}

{notification.title}

{!notification.isRead && (
)}

{notification.message}

{formatDistanceToNow(new Date(notification.createdAt), { addSuffix: true, locale: ko })}

))} {notifications.length > 10 && ( 더 많은 알림 보기... )} )} ); }