import { WebhookTriggerEvents } from "@prisma/client"; import classNames from "@calcom/lib/classNames"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Badge, Button, showToast, Switch, Tooltip } from "@calcom/ui"; import { FiAlertCircle, FiTrash } from "@calcom/ui/components/icon"; type WebhookProps = { id: string; subscriberUrl: string; payloadTemplate: string | null; active: boolean; eventTriggers: WebhookTriggerEvents[]; secret: string | null; eventTypeId: number | null; }; export default function WebhookListItem(props: { webhook: WebhookProps; onEditWebhook: () => void; lastItem: boolean; }) { const { t } = useLocale(); const utils = trpc.useContext(); const { webhook } = props; const deleteWebhook = trpc.viewer.webhook.delete.useMutation({ async onSuccess() { await utils.viewer.webhook.list.invalidate(); showToast(t("webhook_removed_successfully"), "success"); }, }); const toggleWebhook = trpc.viewer.webhook.edit.useMutation({ async onSuccess(data) { console.log("data", data); await utils.viewer.webhook.list.invalidate(); // TODO: Better success message showToast(t(data?.active ? "enabled" : "disabled"), "success"); }, }); return (

{webhook.subscriberUrl}

{webhook.eventTriggers.map((trigger) => ( {t(`${trigger.toLowerCase()}`)} ))}
toggleWebhook.mutate({ id: webhook.id, active: !webhook.active, payloadTemplate: webhook.payloadTemplate, eventTypeId: webhook.eventTypeId || undefined, }) } />
); }