import { ExternalLinkIcon, TrashIcon } from "lucide-react"; import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { Button } from "@/components/ui/button"; import { webhookServiceClient } from "@/grpcweb"; import useCurrentUser from "@/hooks/useCurrentUser"; import { Webhook } from "@/types/proto/api/v1/webhook_service"; import { useTranslate } from "@/utils/i18n"; import showCreateWebhookDialog from "../CreateWebhookDialog"; const WebhookSection = () => { const t = useTranslate(); const currentUser = useCurrentUser(); const [webhooks, setWebhooks] = useState([]); const listWebhooks = async () => { if (!currentUser) return []; const { webhooks } = await webhookServiceClient.listWebhooks({ parent: currentUser.name, }); return webhooks; }; useEffect(() => { listWebhooks().then((webhooks) => { setWebhooks(webhooks); }); }, [currentUser]); const handleCreateWebhookDialogConfirm = async () => { const webhooks = await listWebhooks(); setWebhooks(webhooks); }; const handleDeleteWebhook = async (webhook: Webhook) => { const confirmed = window.confirm(`Are you sure to delete webhook \`${webhook.displayName}\`? You cannot undo this action.`); if (confirmed) { await webhookServiceClient.deleteWebhook({ name: webhook.name }); setWebhooks(webhooks.filter((item) => item.name !== webhook.name)); } }; return (

{t("setting.webhook-section.title")}

{webhooks.map((webhook) => ( ))} {webhooks.length === 0 && ( )}
{t("common.name")} {t("setting.webhook-section.url")} {t("common.delete")}
{webhook.displayName} {webhook.url}
{t("setting.webhook-section.no-webhooks-found")}
{t("common.learn-more")}
); }; export default WebhookSection;