import styled from '@emotion/styled'; import { Avatar, GRAY_SCALE } from 'twenty-ui'; import { ActivityRow } from '@/activities/components/ActivityRow'; import { EmailThreadNotShared } from '@/activities/emails/components/EmailThreadNotShared'; import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu'; import { MessageChannelVisibility, TimelineThread } from '~/generated/graphql'; import { formatToHumanReadableDate } from '~/utils/date-utils'; const StyledHeading = styled.div<{ unread: boolean }>` display: flex; overflow: hidden; width: 20%; `; const StyledParticipantsContainer = styled.div` align-items: flex-start; display: flex; `; const StyledAvatar = styled(Avatar)` margin-left: ${({ theme }) => theme.spacing(-1)}; `; const StyledSenderNames = styled.span` display: flex; margin: ${({ theme }) => theme.spacing(0, 1)}; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; `; const StyledThreadCount = styled.span` color: ${({ theme }) => theme.font.color.tertiary}; `; const StyledSubjectAndBody = styled.div` align-items: center; display: flex; flex: 1; gap: ${({ theme }) => theme.spacing(2)}; overflow: hidden; `; const StyledSubject = styled.span` color: ${({ theme }) => theme.font.color.primary}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; `; const StyledBody = styled.span` color: ${({ theme }) => theme.font.color.tertiary}; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; `; const StyledReceivedAt = styled.div` font-size: ${({ theme }) => theme.font.size.sm}; font-weight: ${({ theme }) => theme.font.weight.regular}; padding: ${({ theme }) => theme.spacing(0, 1)}; `; type EmailThreadPreviewProps = { thread: TimelineThread; }; export const EmailThreadPreview = ({ thread }: EmailThreadPreviewProps) => { const { openEmailThreadInCommandMenu } = useCommandMenu(); const visibility = thread.visibility; const senderNames = thread.firstParticipant.displayName + (thread?.lastTwoParticipants?.[0]?.displayName ? `, ${thread.lastTwoParticipants?.[0]?.displayName}` : '') + (thread?.lastTwoParticipants?.[1]?.displayName ? `, ${thread.lastTwoParticipants?.[1]?.displayName}` : ''); const [finalDisplayedName, finalAvatarUrl, isCountIcon] = thread.participantCount > 3 ? [`${thread.participantCount}`, '', true] : [ thread?.lastTwoParticipants?.[1]?.displayName, thread?.lastTwoParticipants?.[1]?.avatarUrl, false, ]; const handleThreadClick = () => { const canOpen = thread.visibility === MessageChannelVisibility.SHARE_EVERYTHING; if (canOpen) { openEmailThreadInCommandMenu(thread.id); } }; const isDisabled = visibility !== MessageChannelVisibility.SHARE_EVERYTHING; return ( {thread?.lastTwoParticipants?.[0] && ( )} {finalDisplayedName && ( )} {senderNames} {thread.numberOfMessagesInThread} {visibility !== MessageChannelVisibility.METADATA && ( {thread.subject} )} {visibility === MessageChannelVisibility.SHARE_EVERYTHING && ( {thread.lastMessageBody} )} {visibility !== MessageChannelVisibility.SHARE_EVERYTHING && ( )} {formatToHumanReadableDate(thread.lastMessageReceivedAt)} ); };