2023-11-27 11:45:48 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2023-11-15 10:26:57 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { observer } from "mobx-react-lite";
|
2023-11-27 11:45:48 +00:00
|
|
|
import useSWR from "swr";
|
|
|
|
// 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 { DeleteWebhookModal, WebhookDeleteSection, WebhookForm } from "components/web-hooks";
|
|
|
|
// ui
|
2023-11-15 10:26:57 +00:00
|
|
|
import { Spinner } from "@plane/ui";
|
2023-11-27 11:45:48 +00:00
|
|
|
// types
|
|
|
|
import { NextPageWithLayout } from "types/app";
|
2023-11-15 10:26:57 +00:00
|
|
|
|
2023-11-27 11:45:48 +00:00
|
|
|
const WebhookDetailsPage: NextPageWithLayout = observer(() => {
|
|
|
|
// states
|
|
|
|
const [deleteWebhookModal, setDeleteWebhookModal] = useState(false);
|
|
|
|
// router
|
2023-11-15 10:26:57 +00:00
|
|
|
const router = useRouter();
|
2023-11-27 11:45:48 +00:00
|
|
|
const { workspaceSlug, webhookId, isCreated } = router.query;
|
|
|
|
// mobx store
|
|
|
|
const {
|
|
|
|
webhook: { currentWebhook, clearSecretKey, fetchWebhookById },
|
|
|
|
user: { currentWorkspaceRole },
|
|
|
|
} = useMobxStore();
|
2023-11-15 10:26:57 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-11-27 11:45:48 +00:00
|
|
|
if (isCreated !== "true") clearSecretKey();
|
|
|
|
}, [clearSecretKey, isCreated]);
|
2023-11-15 10:26:57 +00:00
|
|
|
|
2023-11-27 11:45:48 +00:00
|
|
|
const isAdmin = currentWorkspaceRole === 20;
|
|
|
|
|
|
|
|
useSWR(
|
|
|
|
workspaceSlug && webhookId && isAdmin ? `WEBHOOK_DETAILS_${workspaceSlug}_${webhookId}` : null,
|
|
|
|
workspaceSlug && webhookId && isAdmin
|
|
|
|
? () => fetchWebhookById(workspaceSlug.toString(), webhookId.toString())
|
2023-11-15 10:26:57 +00:00
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-11-27 11:45:48 +00:00
|
|
|
if (!isAdmin)
|
|
|
|
return (
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="mt-10 flex h-full w-full justify-center p-4">
|
|
|
|
<p className="text-sm text-custom-text-300">You are not authorized to access this page.</p>
|
2023-11-27 11:45:48 +00:00
|
|
|
</div>
|
|
|
|
);
|
2023-11-15 10:26:57 +00:00
|
|
|
|
2023-11-27 11:45:48 +00:00
|
|
|
if (!currentWebhook)
|
|
|
|
return (
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="grid h-full w-full place-items-center p-4">
|
2023-11-27 11:45:48 +00:00
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
);
|
2023-11-15 10:26:57 +00:00
|
|
|
|
|
|
|
return (
|
2023-11-27 11:45:48 +00:00
|
|
|
<>
|
|
|
|
<DeleteWebhookModal isOpen={deleteWebhookModal} onClose={() => setDeleteWebhookModal(false)} />
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="w-full space-y-8 overflow-y-auto py-8 pr-9">
|
2023-11-27 11:45:48 +00:00
|
|
|
<WebhookForm data={currentWebhook} />
|
|
|
|
{currentWebhook && <WebhookDeleteSection openDeleteModal={() => setDeleteWebhookModal(true)} />}
|
|
|
|
</div>
|
|
|
|
</>
|
2023-11-15 10:26:57 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-11-27 11:45:48 +00:00
|
|
|
WebhookDetailsPage.getLayout = function getLayout(page: React.ReactElement) {
|
|
|
|
return (
|
|
|
|
<AppLayout header={<WorkspaceSettingHeader title="Webhook settings" />}>
|
|
|
|
<WorkspaceSettingLayout>{page}</WorkspaceSettingLayout>
|
|
|
|
</AppLayout>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default WebhookDetailsPage;
|