Catch graphql errors (#3634)
* Catch graphql errors * update according to comment
This commit is contained in:
@ -12,6 +12,7 @@ import {
|
|||||||
H1Title,
|
H1Title,
|
||||||
H1TitleFontColor,
|
H1TitleFontColor,
|
||||||
} from '@/ui/display/typography/components/H1Title';
|
} from '@/ui/display/typography/components/H1Title';
|
||||||
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||||
import { Card } from '@/ui/layout/card/components/Card';
|
import { Card } from '@/ui/layout/card/components/Card';
|
||||||
import { Section } from '@/ui/layout/section/components/Section';
|
import { Section } from '@/ui/layout/section/components/Section';
|
||||||
import { TimelineThread } from '~/generated/graphql';
|
import { TimelineThread } from '~/generated/graphql';
|
||||||
@ -39,6 +40,8 @@ export const EmailThreads = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { openEmailThread } = useEmailThread();
|
const { openEmailThread } = useEmailThread();
|
||||||
|
|
||||||
|
const { enqueueSnackBar } = useSnackBar();
|
||||||
|
|
||||||
const threadQuery =
|
const threadQuery =
|
||||||
entity.targetObjectNameSingular === CoreObjectNameSingular.Person
|
entity.targetObjectNameSingular === CoreObjectNameSingular.Person
|
||||||
? getTimelineThreadsFromPersonId
|
? getTimelineThreadsFromPersonId
|
||||||
@ -56,16 +59,22 @@ export const EmailThreads = ({
|
|||||||
variables: threadQueryVariables,
|
variables: threadQueryVariables,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (threads.error) {
|
||||||
|
enqueueSnackBar(threads.error.message || 'Error loading email threads', {
|
||||||
|
variant: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (threads.loading) {
|
if (threads.loading) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const timelineThreads: TimelineThread[] =
|
const timelineThreads: TimelineThread[] =
|
||||||
threads.data[
|
threads?.data?.[
|
||||||
entity.targetObjectNameSingular === CoreObjectNameSingular.Person
|
entity.targetObjectNameSingular === CoreObjectNameSingular.Person
|
||||||
? 'getTimelineThreadsFromPersonId'
|
? 'getTimelineThreadsFromPersonId'
|
||||||
: 'getTimelineThreadsFromCompanyId'
|
: 'getTimelineThreadsFromCompanyId'
|
||||||
];
|
] ?? [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledContainer>
|
<StyledContainer>
|
||||||
@ -80,15 +89,14 @@ export const EmailThreads = ({
|
|||||||
fontColor={H1TitleFontColor.Primary}
|
fontColor={H1TitleFontColor.Primary}
|
||||||
/>
|
/>
|
||||||
<Card>
|
<Card>
|
||||||
{timelineThreads &&
|
{timelineThreads.map((thread: TimelineThread, index: number) => (
|
||||||
timelineThreads.map((thread: TimelineThread, index: number) => (
|
<EmailThreadPreview
|
||||||
<EmailThreadPreview
|
key={index}
|
||||||
key={index}
|
divider={index < timelineThreads.length - 1}
|
||||||
divider={index < timelineThreads.length - 1}
|
thread={thread}
|
||||||
thread={thread}
|
onClick={() => openEmailThread(thread)}
|
||||||
onClick={() => openEmailThread(thread)}
|
/>
|
||||||
/>
|
))}
|
||||||
))}
|
|
||||||
</Card>
|
</Card>
|
||||||
</Section>
|
</Section>
|
||||||
</StyledContainer>
|
</StyledContainer>
|
||||||
|
|||||||
Reference in New Issue
Block a user