-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathUserSourceIntegrationList.tsx
More file actions
105 lines (99 loc) · 3.36 KB
/
UserSourceIntegrationList.tsx
File metadata and controls
105 lines (99 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import type { ReactElement } from 'react';
import React from 'react';
import { useSourceIntegrationsQuery } from '../../hooks/integrations/useSourceIntegrationsQuery';
import { ProfileImageSize } from '../ProfilePicture';
import { SourceAvatar } from '../profile/source';
import {
Typography,
TypographyType,
TypographyColor,
TypographyTag,
} from '../typography/Typography';
import { Button, ButtonIconPosition, ButtonVariant } from '../buttons/Button';
import { MiniCloseIcon } from '../icons';
import { useLazyModal } from '../../hooks/useLazyModal';
import { LazyModal } from '../modals/common/types';
import { useIntegration } from '../../hooks/integrations/useIntegration';
export type UserSourceIntegrationListProps = {
integrationId: string;
};
export const UserSourceIntegrationList = ({
integrationId,
}: UserSourceIntegrationListProps): ReactElement => {
const { data: sourceIntegrations, isPending } = useSourceIntegrationsQuery({
integrationId,
});
const { openModal } = useLazyModal();
const { removeSourceIntegration } = useIntegration();
if (!sourceIntegrations?.length && !isPending) {
return (
<Typography className="px-2" type={TypographyType.Body} bold>
No connected sources, go to your squad page to connect.
</Typography>
);
}
return (
<ul>
{sourceIntegrations?.map((sourceIntegration) => {
const onClick = async (event: React.MouseEvent) => {
event.stopPropagation();
await removeSourceIntegration({
sourceId: sourceIntegration.source.id!,
integrationId,
integrationType: sourceIntegration.userIntegration.type,
});
};
return (
<li
key={`${sourceIntegration.userIntegration.id}-${sourceIntegration.source.id}`}
className="flex w-full items-center justify-center"
>
<Button
className="flex-1 pl-2 pr-3"
variant={ButtonVariant.Tertiary}
iconPosition={ButtonIconPosition.Right}
icon={
<button type="button" onClick={onClick}>
<MiniCloseIcon />
</button>
}
onClick={() => {
openModal({
type: LazyModal.SlackIntegration,
props: {
source: sourceIntegration.source,
},
});
}}
>
<div className="flex flex-1">
<SourceAvatar
source={sourceIntegration.source}
size={ProfileImageSize.Small}
/>
<Typography
type={TypographyType.Callout}
color={TypographyColor.Primary}
>
<Typography
tag={TypographyTag.Span}
bold
color={TypographyColor.Primary}
>
{sourceIntegration.source.name}
</Typography>{' '}
<Typography
tag={TypographyTag.Span}
color={TypographyColor.Tertiary}
>
@{sourceIntegration.source.handle}
</Typography>
</Typography>
</div>
</Button>
</li>
);
})}
</ul>
);
};