Attempt to fix duplicate webhooks

pull/4589/head
zomars 2022-09-19 01:58:36 +01:00
parent ac276a9654
commit 7d277ad89f
2 changed files with 11 additions and 8 deletions

View File

@ -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({

View File

@ -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 }],
{