"use client"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { ZTestTriggerInputSchema } from "@calcom/trpc/server/routers/viewer/webhook/testTrigger.schema"; import { toastManager } from "@coss/ui/components/toast"; import { Badge } from "@coss/ui/components/badge"; import { Button } from "@coss/ui/components/button"; import { Card, CardFrame, CardPanel } from "@coss/ui/components/card"; import { Label } from "@coss/ui/components/label"; import { ActivityIcon } from "lucide-react"; import { useWatch } from "react-hook-form"; import { ZodError } from "zod"; import { WebhookTestHeader } from "../views/webhook-test-header"; export default function WebhookTestDisclosure() { const [subscriberUrl, webhookSecret]: [string, string] = useWatch({ name: ["subscriberUrl", "secret"] }); const payloadTemplate = useWatch({ name: "payloadTemplate" }) || null; const { t } = useLocale(); const mutation = trpc.viewer.webhook.testTrigger.useMutation({ onError(err) { toastManager.add({ title: err.message, type: "error" }); }, }); return ( { try { ZTestTriggerInputSchema.parse({ url: subscriberUrl, secret: webhookSecret, type: "PING", payloadTemplate, }); mutation.mutate({ url: subscriberUrl, secret: webhookSecret, type: "PING", payloadTemplate }); } catch (error) { if (error instanceof ZodError) { const errorMessage = error.errors.map((e) => e.message).join(", "); toastManager.add({ title: errorMessage, type: "error" }); } else { toastManager.add({ title: t("unexpected_error_try_again"), type: "error" }); } } }}> {t("ping_test")} } />
{mutation.data && ( {mutation.data.ok ? t("passed") : t("failed")} )}
{!mutation.data &&

{t("no_data_yet")}

} {mutation.status === "success" && mutation.data && (
{t("status")}:{" "} {mutation.data.status}
)}
); }