From baba307a9f7f63516e714c3df3c4f51973ed0229 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Mon, 25 Oct 2021 21:45:52 +0530 Subject: [PATCH] Feature/cal 605 add webhook test check during webhook (#1035) * starting point * lint fix * add mock placeholder * simplified a bit * add some placeholder ui * err handling * multiple fixes * post rebase fixes * removed extra webhook enabled button * finishing touches * added translations * removed debug remnants * requested changes Co-authored-by: KATT --- pages/integrations/index.tsx | 69 ++++++++++++++++++++++++++-- public/static/locales/en/common.json | 5 ++ server/routers/viewer.tsx | 6 ++- server/routers/viewer/webhook.tsx | 58 +++++++++++++++++++++++ 4 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 server/routers/viewer/webhook.tsx 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 (
+