import { ActionIcon, Group, Text, Tooltip, UnstyledButton, } from "@mantine/core"; import { IconBell, IconCheck, IconFileDescription, IconPointFilled, } from "@tabler/icons-react"; import { Avatar } from "@mantine/core"; import { CustomAvatar } from "@/components/ui/custom-avatar"; import { INotification } from "../types/notification.types"; import { Trans, useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; import { useState } from "react"; import { useMarkReadMutation } from "../queries/notification-query"; import { buildPageUrl } from "@/features/page/page.utils"; import { formatRelativeTime } from "../notification.utils"; import classes from "../notification.module.css"; type NotificationItemProps = { notification: INotification; onNavigate: () => void; }; export function NotificationItem({ notification, onNavigate, }: NotificationItemProps) { const { t } = useTranslation(); const markRead = useMarkReadMutation(); const [hovered, setHovered] = useState(false); const isUnread = !notification.readAt; const getNotificationMessageKey = (): string => { switch (notification.type) { case "comment.user_mention": return "{{name}} mentioned you in a comment"; case "comment.created": return "{{name}} commented on a page"; case "comment.resolved": return "{{name}} resolved a comment"; case "page.user_mention": return "{{name}} mentioned you on a page"; case "page.permission_granted": return notification.data?.role === "writer" ? "{{name}} gave you edit access to a page" : "{{name}} gave you view access to a page"; case "page.updated": return "{{name}} updated a page"; case "page.verified": return "{{name}} verified a page"; case "page.approval_requested": return "{{name}} submitted a page for your approval"; case "page.approval_rejected": return "{{name}} returned a page for revision"; case "page.verification_expiring": return "Page verification expires soon"; case "page.verification_expired": return "Page verification has expired"; default: return ""; } }; const pageUrl = notification.page && notification.space ? buildPageUrl( notification.space.slug, notification.page.slugId, notification.page.title, ) : undefined; const markReadIfNeeded = () => { if (isUnread) { markRead.mutate([notification.id]); } }; const handleClick = () => { markReadIfNeeded(); onNavigate(); }; const handleMarkRead = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); markReadIfNeeded(); }; return ( e.button === 1 && markReadIfNeeded()} onMouseEnter={() => setHovered(true)} onMouseLeave={() => setHovered(false)} w="100%" className={classes.notificationItem} > {notification.actor ? ( ) : ( )}
}} /> {notification.page && ( {notification.page.icon ? ( {notification.page.icon} ) : ( )} {notification.page.title || t("Untitled")} )}
{hovered && isUnread ? ( ) : ( {formatRelativeTime(notification.createdAt)} )} {isUnread && ( )}
); }