import { Box, Typography, styled, Avatar, ListItemButton, useTheme, } from '@mui/material'; import { NotificationsSchemaItem, NotificationsSchemaItemNotificationType, } from 'openapi'; import { ReactComponent as ChangesAppliedIcon } from 'assets/icons/merge.svg'; import TimeAgo from 'react-timeago'; import { ToggleOffOutlined } from '@mui/icons-material'; import { flexRow } from 'themes/themeStyles'; const StyledContainerBox = styled(Box, { shouldForwardProp: (prop) => prop !== 'readAt', })<{ readAt: boolean }>(({ theme, readAt }) => ({ padding: theme.spacing(0.5), marginRight: theme.spacing(1.5), backgroundColor: readAt ? theme.palette.neutral.light : theme.palette.secondary.light, width: '30px', height: '30px', display: 'flex', justifyContent: 'center', alignItems: 'center', borderRadius: `${theme.shape.borderRadius}px`, top: 3, left: 7, })); const StyledListItemButton = styled(ListItemButton)(({ theme }) => ({ position: 'relative', cursor: 'pointer', padding: theme.spacing(2.5, 2, 3, 2), borderRadius: theme.shape.borderRadiusMedium, width: '100%', '&:after': { content: '""', width: `calc(100% - ${theme.spacing(4)})`, height: '1px', position: 'absolute', bottom: 0, backgroundColor: theme.palette.divider, }, })); const StyledNotificationMessageBox = styled(Box)(({ theme }) => ({ display: 'flex', flexDirection: 'column', width: '100%', })); const StyledSecondaryInfoBox = styled(Box)(({ theme }) => ({ display: 'flex', justifyContent: 'space-between', alignItems: 'center', margin: theme.spacing(1, 0, 0, 5.25), })); const StyledMessageTypography = styled(Typography, { shouldForwardProp: (prop) => prop !== 'readAt', })<{ readAt: boolean }>(({ theme, readAt }) => ({ display: 'flex', alignItems: 'center', fontSize: theme.fontSizes.smallBody, fontWeight: readAt ? 'normal' : 'bold', textDecoration: 'none', color: 'inherit', wordBreak: 'break-all', })); const StyledTimeAgoTypography = styled(Typography)(({ theme }) => ({ fontSize: theme.fontSizes.smallerBody, color: theme.palette.neutral.main, })); const StyledUserContainer = styled(Box)(({ theme }) => ({ ...flexRow, })); const StyledAvatar = styled(Avatar)(({ theme }) => ({ width: '18px', height: '18px', })); const StyledCreatedBy = styled(Typography)(({ theme }) => ({ fontSize: theme.fontSizes.smallBody, color: theme.palette.neutral.main, marginLeft: theme.spacing(1), })); interface INotificationProps { notification: NotificationsSchemaItem; onNotificationClick: (notification: NotificationsSchemaItem) => void; } export const Notification = ({ notification, onNotificationClick, }: INotificationProps) => { const theme = useTheme(); const { readAt } = notification; const resolveIcon = (type: NotificationsSchemaItemNotificationType) => { if (type === 'change-request') { return ( ); } if (type === 'toggle') { return ( ({ height: '20px', width: '20px', color: readAt ? theme.palette.neutral.main : theme.palette.primary.main, })} /> ); } }; return ( onNotificationClick(notification)}> {resolveIcon(notification.notificationType)}{' '} {notification.message} Created by {notification.createdBy.username} ); };