import React, { FC, useMemo } from 'react' import { Avatar, AvatarBadge, Box, Flex, Heading, Icon, Text } from '@chakra-ui/react' import { formatRelative } from 'date-fns' import itLocale from 'date-fns/locale/it' import { AiOutlineMail } from 'react-icons/ai' export type NotificationItemProps = { id: string title: string body?: string icon?: string senderIcon?: string senderName?: string createdAt: string isUnread?: boolean clickUrl?: string onClick?: (id: string, clickUrl?: string) => void } export const NotificationItem: FC = ({ title, body, icon, senderIcon, senderName, id, createdAt, isUnread, clickUrl, onClick, }) => { const formattedCreatedAt = useMemo(() => { return formatRelative(new Date(createdAt), new Date(), { locale: itLocale }) }, [createdAt]) const bgColor = useMemo(() => { return isUnread ? 'gray.100' : 'white' }, [isUnread]) const handleClick = useMemo(() => { return () => { onClick?.(id, clickUrl) } }, [clickUrl, id, onClick]) return ( {icon && (senderIcon || senderName) ? ( ) : icon ? ( ) : senderIcon || senderName ? ( ) : ( } /> )} {title && body && ( {title} )} {!body ? title : body} {formattedCreatedAt} ) }