import React from "react"; // next import Image from "next/image"; import { useRouter } from "next/router"; // hooks import useUserNotification from "hooks/use-user-notifications"; // icons import { ArchiveIcon, ClockIcon, SingleCommentCard } from "components/icons"; // helper import { stripHTML, replaceUnderscoreIfSnakeCase } from "helpers/string.helper"; import { formatDateDistance, renderShortDateWithYearFormat } from "helpers/date-time.helper"; // type import type { IUserNotification } from "types"; type NotificationCardProps = { notification: IUserNotification; markNotificationReadStatus: (notificationId: string) => void; markNotificationArchivedStatus: (notificationId: string) => void; setSelectedNotificationForSnooze: (notificationId: string) => void; }; export const NotificationCard: React.FC = (props) => { const { notification, markNotificationReadStatus, markNotificationArchivedStatus, setSelectedNotificationForSnooze, } = props; const router = useRouter(); const { workspaceSlug } = router.query; return (
{ markNotificationReadStatus(notification.id); router.push( `/${workspaceSlug}/projects/${notification.project}/issues/${notification.data.issue.id}` ); }} className={`px-4 ${ notification.read_at === null ? "bg-custom-primary-70/10" : "hover:bg-custom-background-200" }`} >
{notification.read_at === null && ( )}
{notification.triggered_by_details.avatar && notification.triggered_by_details.avatar !== "" ? ( profile image ) : (
{notification.triggered_by_details.first_name[0].toUpperCase()}
)}

{notification.triggered_by_details.first_name}{" "} {notification.triggered_by_details.last_name}{" "} {notification.data.issue_activity.verb}{" "} {notification.data.issue_activity.field !== "comment" ? replaceUnderscoreIfSnakeCase(notification.data.issue_activity.field) : "commented"}{" "} {notification.data.issue_activity.field !== "comment" ? "to" : ""} {" "} {notification.data.issue_activity.field !== "comment" ? ( notification.data.issue_activity.field === "target_date" ? ( renderShortDateWithYearFormat(notification.data.issue_activity.new_value) ) : ( stripHTML(notification.data.issue_activity.new_value) ) ) : ( {`"`} {notification.data.issue_activity.new_value.length > 50 ? notification?.data?.issue_activity?.issue_comment?.slice(0, 50) + "..." : notification.data.issue_activity.issue_comment} {`"`} )}

{notification.data.issue.identifier}-{notification.data.issue.sequence_id}{" "} {notification.data.issue.name}

{formatDateDistance(notification.created_at)}

{[ { id: 1, name: notification.read_at ? "Mark as Unread" : "Mark as Read", icon: SingleCommentCard, onClick: () => { markNotificationReadStatus(notification.id); }, }, { id: 2, name: notification.archived_at ? "Unarchive Notification" : "Archive Notification", icon: ArchiveIcon, onClick: () => { markNotificationArchivedStatus(notification.id); }, }, { id: 3, name: notification.snoozed_till ? "Unsnooze Notification" : "Snooze Notification", icon: ClockIcon, onClick: () => { setSelectedNotificationForSnooze(notification.id); }, }, ].map((item) => ( ))}
); };