2024-01-11 13:05:14 +01:00
|
|
|
import { VFC, useState } from 'react';
|
2023-08-22 14:40:38 +02:00
|
|
|
import useAddons from 'hooks/api/getters/useAddons/useAddons';
|
|
|
|
import { AvailableIntegrations } from './AvailableIntegrations/AvailableIntegrations';
|
2023-09-05 14:14:03 +02:00
|
|
|
import { ConfiguredIntegrations } from './ConfiguredIntegrations/ConfiguredIntegrations';
|
2024-01-10 11:33:51 +01:00
|
|
|
import { Tab, Tabs, styled, useTheme } from '@mui/material';
|
|
|
|
import { Add } from '@mui/icons-material';
|
|
|
|
import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
|
|
|
|
import { useUiFlag } from 'hooks/useUiFlag';
|
|
|
|
import { useIncomingWebhooks } from 'hooks/api/getters/useIncomingWebhooks/useIncomingWebhooks';
|
|
|
|
import { PageContent } from 'component/common/PageContent/PageContent';
|
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
|
|
|
import { PageHeader } from 'component/common/PageHeader/PageHeader';
|
|
|
|
import { TabLink } from 'component/common/TabNav/TabLink';
|
|
|
|
import ResponsiveButton from 'component/common/ResponsiveButton/ResponsiveButton';
|
|
|
|
import { ADMIN } from 'component/providers/AccessProvider/permissions';
|
2024-01-11 13:05:14 +01:00
|
|
|
import { IIncomingWebhook } from 'interfaces/incomingWebhook';
|
|
|
|
import { IncomingWebhooks } from 'component/incomingWebhooks/IncomingWebhooks';
|
2024-01-10 11:33:51 +01:00
|
|
|
|
|
|
|
const StyledHeader = styled('div')(() => ({
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
alignItems: 'center',
|
|
|
|
}));
|
|
|
|
|
|
|
|
const StyledTabsContainer = styled('div')({
|
|
|
|
flex: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
const StyledActions = styled('div')({
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
});
|
2023-08-22 14:40:38 +02:00
|
|
|
|
2023-09-05 14:14:03 +02:00
|
|
|
export const IntegrationList: VFC = () => {
|
2024-01-10 11:33:51 +01:00
|
|
|
const { pathname } = useLocation();
|
|
|
|
const navigate = useNavigate();
|
|
|
|
const theme = useTheme();
|
|
|
|
const incomingWebhooksEnabled = useUiFlag('incomingWebhooks');
|
2023-08-22 14:40:38 +02:00
|
|
|
const { providers, addons, loading } = useAddons();
|
2024-01-10 11:33:51 +01:00
|
|
|
const { incomingWebhooks } = useIncomingWebhooks();
|
|
|
|
|
2024-01-11 13:05:14 +01:00
|
|
|
const [selectedIncomingWebhook, setSelectedIncomingWebhook] =
|
|
|
|
useState<IIncomingWebhook>();
|
|
|
|
const [incomingWebhookModalOpen, setIncomingWebhookModalOpen] =
|
|
|
|
useState(false);
|
|
|
|
|
2024-01-10 11:33:51 +01:00
|
|
|
const onNewIncomingWebhook = () => {
|
|
|
|
navigate('/integrations/incoming-webhooks');
|
2024-01-11 13:05:14 +01:00
|
|
|
setSelectedIncomingWebhook(undefined);
|
|
|
|
setIncomingWebhookModalOpen(true);
|
2024-01-10 11:33:51 +01:00
|
|
|
};
|
2023-09-05 14:14:03 +02:00
|
|
|
|
2024-01-10 11:33:51 +01:00
|
|
|
const tabs = [
|
|
|
|
{
|
|
|
|
label: 'Integrations',
|
|
|
|
path: '/integrations',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: `Incoming webhooks (${incomingWebhooks.length})`,
|
|
|
|
path: '/integrations/incoming-webhooks',
|
|
|
|
},
|
|
|
|
];
|
2023-08-22 14:40:38 +02:00
|
|
|
|
|
|
|
return (
|
2024-01-10 11:33:51 +01:00
|
|
|
<PageContent
|
|
|
|
header={
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={incomingWebhooksEnabled}
|
|
|
|
show={
|
|
|
|
<StyledHeader>
|
|
|
|
<StyledTabsContainer>
|
|
|
|
<Tabs
|
|
|
|
value={pathname}
|
|
|
|
indicatorColor='primary'
|
|
|
|
textColor='primary'
|
|
|
|
variant='scrollable'
|
|
|
|
allowScrollButtonsMobile
|
|
|
|
>
|
|
|
|
{tabs.map(({ label, path }) => (
|
|
|
|
<Tab
|
|
|
|
key={label}
|
|
|
|
value={path}
|
|
|
|
label={
|
|
|
|
<TabLink to={path}>
|
|
|
|
{label}
|
|
|
|
</TabLink>
|
|
|
|
}
|
|
|
|
sx={{
|
|
|
|
padding: 0,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Tabs>
|
|
|
|
</StyledTabsContainer>
|
|
|
|
<StyledActions>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={pathname.includes(
|
|
|
|
'incoming-webhooks',
|
|
|
|
)}
|
|
|
|
show={
|
|
|
|
<ResponsiveButton
|
|
|
|
onClick={onNewIncomingWebhook}
|
|
|
|
maxWidth={`${theme.breakpoints.values.sm}px`}
|
|
|
|
Icon={Add}
|
|
|
|
permission={ADMIN}
|
|
|
|
>
|
|
|
|
New incoming webhook
|
|
|
|
</ResponsiveButton>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</StyledActions>
|
|
|
|
</StyledHeader>
|
|
|
|
}
|
|
|
|
elseShow={<PageHeader title='Integrations' />}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
isLoading={loading}
|
|
|
|
withTabs={incomingWebhooksEnabled}
|
|
|
|
>
|
|
|
|
<Routes>
|
|
|
|
<Route
|
|
|
|
path='incoming-webhooks'
|
2024-01-11 13:05:14 +01:00
|
|
|
element={
|
|
|
|
<IncomingWebhooks
|
|
|
|
modalOpen={incomingWebhookModalOpen}
|
|
|
|
setModalOpen={setIncomingWebhookModalOpen}
|
|
|
|
selectedIncomingWebhook={selectedIncomingWebhook}
|
|
|
|
setSelectedIncomingWebhook={
|
|
|
|
setSelectedIncomingWebhook
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
}
|
2024-01-10 11:33:51 +01:00
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path='*'
|
|
|
|
element={
|
|
|
|
<>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={addons.length > 0}
|
|
|
|
show={
|
|
|
|
<ConfiguredIntegrations
|
|
|
|
addons={addons}
|
|
|
|
providers={providers}
|
|
|
|
loading={loading}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<AvailableIntegrations
|
|
|
|
providers={providers}
|
|
|
|
onNewIncomingWebhook={onNewIncomingWebhook}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Routes>
|
|
|
|
</PageContent>
|
2023-08-22 14:40:38 +02:00
|
|
|
);
|
|
|
|
};
|