2023-11-15 10:26:57 +00:00
|
|
|
import React from "react";
|
2023-11-27 11:45:48 +00:00
|
|
|
import Link from "next/link";
|
2023-11-15 10:26:57 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import useSWR from "swr";
|
|
|
|
import { observer } from "mobx-react-lite";
|
2023-11-27 11:45:48 +00:00
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
// layouts
|
2023-11-15 10:26:57 +00:00
|
|
|
import { AppLayout } from "layouts/app-layout";
|
|
|
|
import { WorkspaceSettingLayout } from "layouts/settings-layout";
|
|
|
|
// components
|
|
|
|
import { WorkspaceSettingHeader } from "components/headers";
|
2023-11-27 11:45:48 +00:00
|
|
|
import { WebhooksList, WebhooksEmptyState } from "components/web-hooks";
|
|
|
|
// ui
|
|
|
|
import { Button, Spinner } from "@plane/ui";
|
2023-11-15 10:26:57 +00:00
|
|
|
// types
|
2023-11-27 11:45:48 +00:00
|
|
|
import { NextPageWithLayout } from "types/app";
|
2023-11-15 10:26:57 +00:00
|
|
|
|
2023-11-27 11:45:48 +00:00
|
|
|
const WebhooksListPage: NextPageWithLayout = observer(() => {
|
2023-11-15 10:26:57 +00:00
|
|
|
const router = useRouter();
|
2023-11-27 11:45:48 +00:00
|
|
|
const { workspaceSlug } = router.query;
|
2023-11-15 10:26:57 +00:00
|
|
|
|
|
|
|
const {
|
2023-11-27 11:45:48 +00:00
|
|
|
webhook: { fetchWebhooks, webhooks },
|
|
|
|
user: { currentWorkspaceRole },
|
|
|
|
} = useMobxStore();
|
|
|
|
|
|
|
|
const isAdmin = currentWorkspaceRole === 20;
|
2023-11-15 10:26:57 +00:00
|
|
|
|
|
|
|
useSWR(
|
2023-11-27 11:45:48 +00:00
|
|
|
workspaceSlug && isAdmin ? `WEBHOOKS_LIST_${workspaceSlug}` : null,
|
|
|
|
workspaceSlug && isAdmin ? () => fetchWebhooks(workspaceSlug.toString()) : null
|
2023-11-15 10:26:57 +00:00
|
|
|
);
|
|
|
|
|
2023-11-27 11:45:48 +00:00
|
|
|
if (!isAdmin)
|
|
|
|
return (
|
|
|
|
<div className="h-full w-full flex justify-center mt-10 p-4">
|
|
|
|
<p className="text-custom-text-300 text-sm">You are not authorized to access this page.</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!webhooks)
|
|
|
|
return (
|
|
|
|
<div className="h-full w-full grid place-items-center p-4">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2023-11-15 10:26:57 +00:00
|
|
|
return (
|
2023-11-27 11:45:48 +00:00
|
|
|
<div className="h-full w-full py-8 pr-9 overflow-hidden">
|
|
|
|
{Object.keys(webhooks).length > 0 ? (
|
|
|
|
<div className="h-full w-full flex flex-col">
|
|
|
|
<div className="flex items-center justify-between gap-4 pb-3.5 border-b border-custom-border-200">
|
|
|
|
<div className="text-xl font-medium">Webhooks</div>
|
|
|
|
<Link href={`/${workspaceSlug}/settings/webhooks/create`}>
|
|
|
|
<Button variant="primary" size="sm">
|
|
|
|
Add webhook
|
|
|
|
</Button>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
<WebhooksList />
|
2023-11-15 10:26:57 +00:00
|
|
|
</div>
|
2023-11-27 11:45:48 +00:00
|
|
|
) : (
|
|
|
|
<div className="mx-auto">
|
|
|
|
<WebhooksEmptyState />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-11-15 10:26:57 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-11-27 11:45:48 +00:00
|
|
|
WebhooksListPage.getLayout = function getLayout(page: React.ReactElement) {
|
|
|
|
return (
|
|
|
|
<AppLayout header={<WorkspaceSettingHeader title="Webhook settings" />}>
|
|
|
|
<WorkspaceSettingLayout>{page}</WorkspaceSettingLayout>
|
|
|
|
</AppLayout>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default WebhooksListPage;
|