"use client"; import { useTranslations } from "next-intl"; import { ReactElement, useEffect, useState } from "react"; import { usePageUrlGenerator } from "../../../../hooks"; import { Link } from "../../../../shadcnui"; import { UserInterface } from "../../../user"; import { UserAvatar } from "../../../user/components"; import { NotificationInterface } from "../../data"; type TaskCommentedOnProps = { notification: NotificationInterface; closePopover: () => void; }; export const generateNotificationData = (params: { notification: NotificationInterface; generateUrl: any; }): { title: string; actor?: UserInterface; url?: string; taskId?: string } => { const response: any = {}; response.actor = params.notification.actor; // Use actionUrl from notification if available (for notifications without actor relationships) if (params.notification.actionUrl) { response.url = params.notification.actionUrl; } return response; }; export function NotificationToast( notification: NotificationInterface, t: any, generateUrl: any, reouter: any, ): { title: string; description: string | ReactElement; action?: { label: string; onClick: () => void; }; } { const data = generateNotificationData({ notification: notification, generateUrl: generateUrl }); return { title: t(`notification.${notification.notificationType}.title`), description: (
{data.actor ? (
) : (
)}

{t.rich(`notification.${notification.notificationType}.description`, { strong: (chunks: any) => {chunks}, actor: data.actor?.name ?? "", title: data.title, message: notification.message ?? "", })}

{new Date(notification.createdAt).toLocaleString()}
), action: data.url ? { label: t(`notification.${notification.notificationType}.buttons.action`), onClick: () => { reouter.push(data.url!); }, } : undefined, }; } export function NotificationMenuItem({ notification, closePopover }: TaskCommentedOnProps) { const generateUrl = usePageUrlGenerator(); const [isRead, setIsRead] = useState(false); const t = useTranslations(); useEffect(() => { setIsRead(notification.isRead); }, []); const data = generateNotificationData({ notification: notification, generateUrl: generateUrl }); const response = (
{data.actor ? (
) : (
)}

{t.rich(`notification.${notification.notificationType}.description` as any, { strong: (chunks: any) => {chunks}, actor: data.actor?.name ?? "", title: data.title, message: notification.message ?? "", })}

{new Date(notification.createdAt).toLocaleString()}
); if (!data.url) return response; return ( {response} ); }