import React from "react"; import Image from "next/image"; import { useRouter } from "next/router"; // hooks import useToast from "hooks/use-toast"; // icons import { CustomMenu, Icon, Tooltip } from "components/ui"; // helper import { stripHTML, replaceUnderscoreIfSnakeCase } from "helpers/string.helper"; import { formatDateDistance, render12HourFormatTime, renderLongDateFormat, renderShortDate, renderShortDateWithYearFormat, } from "helpers/date-time.helper"; // type import type { IUserNotification } from "types"; type NotificationCardProps = { notification: IUserNotification; markNotificationReadStatus: (notificationId: string) => Promise; markNotificationArchivedStatus: (notificationId: string) => Promise; setSelectedNotificationForSnooze: (notificationId: string) => void; markSnoozeNotification: (notificationId: string, dateTime?: Date | undefined) => Promise; }; const snoozeOptions = [ { label: "1 days", value: new Date(new Date().getTime() + 24 * 60 * 60 * 1000), }, { label: "3 days", value: new Date(new Date().getTime() + 3 * 24 * 60 * 60 * 1000), }, { label: "5 days", value: new Date(new Date().getTime() + 5 * 24 * 60 * 60 * 1000), }, { label: "1 week", value: new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000), }, { label: "2 weeks", value: new Date(new Date().getTime() + 14 * 24 * 60 * 60 * 1000), }, { label: "Custom", value: null, }, ]; export const NotificationCard: React.FC = (props) => { const { notification, markNotificationReadStatus, markNotificationArchivedStatus, setSelectedNotificationForSnooze, markSnoozeNotification, } = props; const router = useRouter(); const { workspaceSlug } = router.query; const { setToastAlert } = useToast(); return (
{ markNotificationReadStatus(notification.id); router.push( `/${workspaceSlug}/projects/${notification.project}/issues/${notification.data.issue.id}` ); }} className={`group relative py-3 px-6 cursor-pointer ${ notification.read_at === null ? "bg-custom-primary-70/5" : "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.field !== "comment" && notification.data.issue_activity.verb}{" "} {notification.data.issue_activity.field === "comment" ? "commented" : notification.data.issue_activity.field === "None" ? null : replaceUnderscoreIfSnakeCase(notification.data.issue_activity.field)}{" "} {notification.data.issue_activity.field !== "comment" && notification.data.issue_activity.field !== "None" ? "to" : ""} {" "} {notification.data.issue_activity.field !== "None" ? ( notification.data.issue_activity.field !== "comment" ? ( notification.data.issue_activity.field === "target_date" ? ( renderShortDateWithYearFormat(notification.data.issue_activity.new_value) ) : notification.data.issue_activity.field === "attachment" ? ( "the issue" ) : stripHTML(notification.data.issue_activity.new_value).length > 55 ? ( stripHTML(notification.data.issue_activity.new_value).slice(0, 50) + "..." ) : ( stripHTML(notification.data.issue_activity.new_value) ) ) : ( {`"`} {notification.data.issue_activity.new_value.length > 55 ? notification?.data?.issue_activity?.issue_comment?.slice(0, 50) + "..." : notification.data.issue_activity.issue_comment} {`"`} ) ) : ( "the issue and assigned it to you." )}

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

{notification.snoozed_till ? (

Till {renderShortDate(notification.snoozed_till)},{" "} {render12HourFormatTime(notification.snoozed_till)}

) : (

{formatDateDistance(notification.created_at)}

)}
{[ { id: 1, name: notification.read_at ? "Mark as Unread" : "Mark as Read", icon: "chat_bubble", onClick: () => { markNotificationReadStatus(notification.id).then(() => { setToastAlert({ title: notification.read_at ? "Notification marked as unread" : "Notification marked as read", type: "success", }); }); }, }, { id: 2, name: notification.archived_at ? "Unarchive Notification" : "Archive Notification", icon: "archive", onClick: () => { markNotificationArchivedStatus(notification.id).then(() => { setToastAlert({ title: notification.archived_at ? "Notification un-archived" : "Notification archived", type: "success", }); }); }, }, ].map((item) => ( ))} { e.stopPropagation(); }} customButton={ } optionsClassName="!z-20" > {snoozeOptions.map((item) => ( { e.stopPropagation(); if (!item.value) { setSelectedNotificationForSnooze(notification.id); return; } markSnoozeNotification(notification.id, item.value).then(() => { setToastAlert({ title: `Notification snoozed till ${renderLongDateFormat(item.value)}`, type: "success", }); }); }} > {item.label} ))}
); };