import { Button, IconButton } from "@mui/joy"; import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { webhookServiceClient } from "@/grpcweb"; import useCurrentUser from "@/hooks/useCurrentUser"; import { Webhook } from "@/types/proto/api/v2/webhook_service"; import { useTranslate } from "@/utils/i18n"; import showCreateWebhookDialog from "../CreateWebhookDialog"; import { showCommonDialog } from "../Dialog/CommonDialog"; import Icon from "../Icon"; const listWebhooks = async (userId: number) => { const { webhooks } = await webhookServiceClient.listWebhooks({ creatorId: userId, }); return webhooks; }; const WebhookSection = () => { const t = useTranslate(); const currentUser = useCurrentUser(); const [webhooks, setWebhooks] = useState([]); useEffect(() => { listWebhooks(currentUser.id).then((webhooks) => { setWebhooks(webhooks); }); }, []); const handleCreateAccessTokenDialogConfirm = async () => { const webhooks = await listWebhooks(currentUser.id); setWebhooks(webhooks); }; const handleDeleteWebhook = async (webhook: Webhook) => { showCommonDialog({ title: "Delete Webhook", content: `Are you sure to delete webhook \`${webhook.name}\`? You cannot undo this action.`, style: "danger", dialogName: "delete-webhook-dialog", onConfirm: async () => { await webhookServiceClient.deleteWebhook({ id: webhook.id }); setWebhooks(webhooks.filter((item) => item.id !== webhook.id)); }, }); }; return (

Webhooks

{webhooks.map((webhook) => ( ))} {webhooks.length === 0 && ( )}
Name Url {t("common.delete")}
{webhook.name} {webhook.url} { handleDeleteWebhook(webhook); }} >
No webhooks found.
{t("common.learn-more")}
); }; export default WebhookSection;