Files
twenty_crm/packages/twenty-front/src/modules/activities/emails/components/Threads.tsx
Weiko dc7fccb0a8 Merge messages and threads #1 (#3583)
* Merge messages and threads

* rename messageChannelSync to messageChannelMessage

* add merge logic

* remove deprecated methods

* restore enqueue GmailFullSyncJob after connectedAccount creation
2024-01-23 17:28:14 +01:00

86 lines
2.5 KiB
TypeScript

import { useQuery } from '@apollo/client';
import styled from '@emotion/styled';
import { ThreadPreview } from '@/activities/emails/components/ThreadPreview';
import { getTimelineThreadsFromCompanyId } from '@/activities/emails/queries/getTimelineThreadsFromCompanyId';
import { getTimelineThreadsFromPersonId } from '@/activities/emails/queries/getTimelineThreadsFromPersonId';
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
import {
H1Title,
H1TitleFontColor,
} from '@/ui/display/typography/components/H1Title';
import { Card } from '@/ui/layout/card/components/Card';
import { Section } from '@/ui/layout/section/components/Section';
import { TimelineThread } from '~/generated/graphql';
const StyledContainer = styled.div`
display: flex;
flex-direction: column;
gap: ${({ theme }) => theme.spacing(6)};
padding: ${({ theme }) => theme.spacing(6, 6, 2)};
`;
const StyledH1Title = styled(H1Title)`
display: flex;
gap: ${({ theme }) => theme.spacing(2)};
`;
const StyledEmailCount = styled.span`
color: ${({ theme }) => theme.font.color.light};
`;
export const Threads = ({ entity }: { entity: ActivityTargetableObject }) => {
const threadQuery =
entity.targetObjectNameSingular === 'person'
? getTimelineThreadsFromPersonId
: getTimelineThreadsFromCompanyId;
const threadQueryVariables =
entity.targetObjectNameSingular === 'person'
? { personId: entity.id }
: { companyId: entity.id };
const threads = useQuery(threadQuery, {
variables: threadQueryVariables,
});
if (threads.loading) {
return;
}
const timelineThreads: TimelineThread[] =
threads.data[
entity.targetObjectNameSingular === 'Person'
? 'getTimelineThreadsFromPersonId'
: 'getTimelineThreadsFromCompanyId'
];
return (
<StyledContainer>
<Section>
<StyledH1Title
title={
<>
Inbox{' '}
<StyledEmailCount>
{timelineThreads && timelineThreads.length}
</StyledEmailCount>
</>
}
fontColor={H1TitleFontColor.Primary}
/>
<Card>
{timelineThreads &&
timelineThreads.map((thread: TimelineThread, index: number) => (
<ThreadPreview
key={index}
divider={index < timelineThreads.length - 1}
thread={thread}
/>
))}
</Card>
</Section>
</StyledContainer>
);
};