"use client"; import { useState } from "react"; import { WebhookDeliveriesPanel } from "./WebhookDeliveriesPanel"; export type WebhookKind = "slack" | "telegram" | "discord" | "custom"; export interface WebhookItem { id: string; url: string; events: string[]; secret: string | null; enabled: boolean; description: string; created_at: string; last_triggered_at: string | null; last_status: number | null; failure_count: number; kind: WebhookKind; metadata_encrypted?: string | null; } const KIND_ICONS: Record = { slack: "chat", telegram: "send", discord: "forum", custom: "webhook", }; const KIND_COLORS: Record = { slack: "text-emerald-500", telegram: "text-blue-500", discord: "text-violet-500", custom: "text-amber-500", }; function getStatus(wh: WebhookItem): "active" | "inactive" | "errored" { if (!wh.enabled) return "inactive"; if (wh.failure_count > 0 || (wh.last_status !== null && wh.last_status >= 400)) return "errored"; return "active"; } interface WebhookCardProps { webhook: WebhookItem; t: (key: string, opts?: Record) => string; testingId: string | null; onTest: (wh: WebhookItem) => void; onToggleEnabled: (wh: WebhookItem) => void; onEdit: (wh: WebhookItem) => void; onDelete: (wh: WebhookItem) => void; } export function WebhookCard({ webhook, t, testingId, onTest, onToggleEnabled, onEdit, onDelete, }: WebhookCardProps) { const [expanded, setExpanded] = useState(false); const status = getStatus(webhook); const isTesting = testingId === webhook.id; return (
{KIND_ICONS[webhook.kind]}

{webhook.description || t("unnamedWebhook")}

{webhook.url}

{t(status)}
{expanded && (
{webhook.events.map((ev) => ( {ev === "*" ? t("allEvents") : ev} ))}

{t("deliveries.title")}

)}
); }