From 7d277ad89f53dc30b13bdabe98df0dff387260b8 Mon Sep 17 00:00:00 2001 From: zomars Date: Mon, 19 Sep 2022 01:58:36 +0100 Subject: [PATCH] Attempt to fix duplicate webhooks --- .../webhooks/components/WebhookForm.tsx | 18 +++++++++++------- .../webhooks/pages/webhook-new-view.tsx | 1 - 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/features/webhooks/components/WebhookForm.tsx b/packages/features/webhooks/components/WebhookForm.tsx index f9b52fedd3..df07ac159b 100644 --- a/packages/features/webhooks/components/WebhookForm.tsx +++ b/packages/features/webhooks/components/WebhookForm.tsx @@ -1,5 +1,5 @@ import { WebhookTriggerEvents } from "@prisma/client"; -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { classNames } from "@calcom/lib"; @@ -47,14 +47,18 @@ const WebhookForm = (props: { apps?: (keyof typeof WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2)[]; onSubmit: (event: WebhookFormSubmitData) => void; }) => { + const { apps = [] } = props; const { t } = useLocale(); + const triggerOptions = useMemo( + () => + apps.reduce((acc, app) => { + if (!WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2[app]) return acc; + acc.push(...WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2[app]); + return acc; + }, WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2["core"]), + [apps] + ); - const triggerOptions: WebhookTriggerEventOptions = WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2["core"]; - if (props.apps) { - for (const app of props.apps) { - triggerOptions.push(...WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2[app]); - } - } const translatedTriggerOptions = triggerOptions.map((option) => ({ ...option, label: t(option.label) })); const formMethods = useForm({ diff --git a/packages/features/webhooks/pages/webhook-new-view.tsx b/packages/features/webhooks/pages/webhook-new-view.tsx index 0bfed41e7b..35ac4e895a 100644 --- a/packages/features/webhooks/pages/webhook-new-view.tsx +++ b/packages/features/webhooks/pages/webhook-new-view.tsx @@ -13,7 +13,6 @@ const NewWebhookView = () => { const { t } = useLocale(); const utils = trpc.useContext(); const router = useRouter(); - // const appId = props.app; const { data: installedApps, isLoading } = trpc.useQuery( ["viewer.integrations", { variant: "other", onlyInstalled: true }], {