diff --git a/pages/integrations/index.tsx b/pages/integrations/index.tsx index 3e8169b37d..3338f553a6 100644 --- a/pages/integrations/index.tsx +++ b/pages/integrations/index.tsx @@ -1,9 +1,16 @@ -import { PencilAltIcon, TrashIcon } from "@heroicons/react/outline"; +import { + PencilAltIcon, + SwitchHorizontalIcon, + TrashIcon, + ChevronDownIcon, + ChevronUpIcon, +} from "@heroicons/react/outline"; import { ClipboardIcon } from "@heroicons/react/solid"; import { WebhookTriggerEvents } from "@prisma/client"; +import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@radix-ui/react-collapsible"; import Image from "next/image"; -import { useState } from "react"; -import { Controller, useForm } from "react-hook-form"; +import React, { useState } from "react"; +import { Controller, useForm, useWatch } from "react-hook-form"; import { useMutation } from "react-query"; import { QueryCell } from "@lib/QueryCell"; @@ -113,6 +120,60 @@ function WebhookListItem(props: { webhook: TWebhook; onEditWebhook: () => void } ); } +function WebhookTestDisclosure() { + const subscriberUrl: string = useWatch({ name: "subscriberUrl" }); + const { t } = useLocale(); + const [open, setOpen] = useState(false); + const mutation = trpc.useMutation("viewer.webhook.testTrigger", { + onError(err) { + showToast(err.message, "error"); + }, + }); + + return ( + setOpen(!open)}> + + {t("webhook_test")}{" "} + {open ? ( + + ) : ( + + )} + + + +
+

{t("webhook_response")}

+ +
+
+ {!mutation.data && {t("no_data_yet")}} + {mutation.status === "success" && ( + <> +
+ {mutation.data.status === 200 ? t("success") : t("failed")} +
+
{JSON.stringify(mutation.data, null, 4)}
+ + )} +
+
+
+
+ ); +} + function WebhookDialogForm(props: { // defaultValues?: TWebhook; @@ -133,6 +194,7 @@ function WebhookDialogForm(props: { const form = useForm({ defaultValues, }); + return (
+