import { useMemo } from 'react'; import styled from 'styled-components'; import { timelineDate } from '../../util/date'; import { Flex, Text, Button, Icon, FlexProps } from '../../../general'; import { NotificationButtonType, NotificationType, } from './Notifications.types'; type NotificationProps = { appInfo?: { image: string; name: string; key: string; }; isGrouped?: boolean; canHover?: boolean; containerWidth: number; notification: NotificationType; showApp?: boolean; showDismiss?: boolean; onLinkClick: (app: string, path: string, link?: string) => void; onDismiss: (app: string, path: string, id: number) => void; }; export const Notification = ({ isGrouped = false, showApp = true, canHover = false, appInfo, onDismiss, onLinkClick, notification, containerWidth, }: NotificationProps) => { const { id, image, app, path, buttons } = notification; const displayDate = timelineDate(new Date(notification.createdAt)); const textWidth = useMemo( () => (image ? containerWidth - 112 : containerWidth - 76), [containerWidth, image] ); return ( ) => { evt.stopPropagation(); onLinkClick(app, path, notification.link); }} > {image && } {notification.title} {displayDate} {notification.content} { evt.stopPropagation(); onDismiss(app, path, id); }} > {/* {buttons && ()} */} {app && showApp && appInfo && ( { return () => { console.log(`poke button ${button.label}`); }; }) : [] } /> )} ); }; export type NotifAppRowProps = { appInfo: { image: string; name: string; key: string; }; buttons?: NotificationButtonType[]; buttonsOnClick?: Array<() => void>; }; export const NotifAppRow = ({ appInfo, buttons, buttonsOnClick, }: NotifAppRowProps) => { return ( {appInfo.name} {buttons && ( {buttons .slice() .reverse() .map((button, index) => { // NOTE: there should only be two buttons max const ButtonTag = button.metadata && JSON.parse(button.metadata).variant === 'secondary' ? Button.Secondary : Button.Minimal; return ( { const buttonClickFunc = buttonsOnClick ? buttonsOnClick[index] : () => {}; evt.stopPropagation(); buttonClickFunc(); }} > {button.label} ); })} )} ); }; // Styles below type NotifRowProps = { isGrouped: boolean; hasRead: boolean; canHover: boolean; } & FlexProps; const NotifRow = styled(Flex)` display: inline-flex; gap: 8px; flex-direction: column; justify-content: space-between; padding: 6px; color: rgba(var(--rlm-text-rgba)); border-radius: var(--rlm-border-radius-6); background: ${(props) => props.isGrouped ? 'transparent' : props.hasRead ? 'rgba(var(--rlm-card-rgba), 0.7)' : 'rgba(var(--rlm-accent-rgba), 0.08)'}; transition: var(--transition); &:hover { transition: var(--transition); background: ${(props) => props.canHover && 'rgba(0, 0, 0, 0.06)'}; cursor: pointer; .notification-date { opacity: 0; } .notification-dismiss { opacity: 0.5; } } .notification-image { margin-left: 2px; width: 34px; height: 34px; } .notification-date { position: absolute; opacity: 0.3; } .notification-dismiss { position: absolute; opacity: 0; right: 4px; } `; const AppRow = styled(Flex)` display: inline-flex; gap: 6px; align-items: center; flex-direction: row; width: 100%; height: 27px; justify-content: space-between; margin-top: 4px; .notif-app-image { border-radius: 3px; width: 20px; height: 20px; } `;