Team webhooks (#8917)

* allow event type specific webhooks for all event types

* first version of team webhooks

* add empty view

* design fixes when no teams + invalidate query on delete/update

* linke to new webhooks page with teamId in query

* make one button with dropdown instead of a button for every team

* add subtitle to dropdown

* add avatar fallback

* authorization when editing webhook

* fix event type webhooks

* fix authorization for delete handler

* code clean up

* fix disabled switch

* add migration

* fix subscriberUrlReservered function and fix authorization

* fix type error

* fix type error

* fix switch not updating

* make sure webhooks are triggered for the correct even types

* code clean up

* only show teams were user has write access

* make webhooks read-only for members

* fix comment

* fix type error

* fix webhook tests for team event types

* implement feedback

* code clean up from feedback

* code clean up (feedback)

* throw error if param missing in subscriberUrlReservered

* handle null/undefined values in getWebhooks itself

* better variable naming

* better check if webhook is readonly

* create assertPartOfTeamWithRequiredAccessLevel to remove duplicate code

---------

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: alannnc <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-05-23 01:15:29 +00:00
1 parent b83ee2d57d
commit 84efda07e9
33 files changed
+691 -211

No files matched your search

@@ -7,16 +7,13 @@ import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hook
import { WebhookForm } from "@calcom/features/webhooks/components";
import type { WebhookFormSubmitData } from "@calcom/features/webhooks/components/WebhookForm";
import WebhookListItem from "@calcom/features/webhooks/components/WebhookListItem";
import { APP_NAME } from "@calcom/lib/constants";
import { subscriberUrlReserved } from "@calcom/features/webhooks/lib/subscriberUrlReserved";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { Alert, Button, Dialog, DialogContent, EmptyScreen, showToast } from "@calcom/ui";
import { Plus, Lock } from "@calcom/ui/components/icon";
export const EventTeamWebhooksTab = ({
eventType,
team,
}: Pick<EventTypeSetupProps, "eventType" | "team">) => {
export const EventWebhooksTab = ({ eventType }: Pick<EventTypeSetupProps, "eventType">) => {
const { t } = useLocale();
const utils = trpc.useContext();
@@ -32,12 +29,6 @@ export const EventTeamWebhooksTab = ({
const [editModalOpen, setEditModalOpen] = useState(false);
const [webhookToEdit, setWebhookToEdit] = useState<Webhook>();
const subscriberUrlReserved = (subscriberUrl: string, id?: string): boolean => {
return !!webhooks?.find(
(webhook) => webhook.subscriberUrl === subscriberUrl && (!id || webhook.id !== id)
);
};
const editWebhookMutation = trpc.viewer.webhook.edit.useMutation({
async onSuccess() {
setEditModalOpen(false);
@@ -61,7 +52,14 @@ export const EventTeamWebhooksTab = ({
});
const onCreateWebhook = async (values: WebhookFormSubmitData) => {
if (subscriberUrlReserved(values.subscriberUrl, values.id)) {
if (
subscriberUrlReserved({
subscriberUrl: values.subscriberUrl,
id: values.id,
webhooks,
eventTypeId: eventType.id,
})
) {
showToast(t("webhook_subscriber_url_reserved"), "error");
return;
}
@@ -102,7 +100,7 @@ export const EventTeamWebhooksTab = ({
return (
<div>
{team && webhooks && !isLoading && (
{webhooks && !isLoading && (
<>
<div>
<div>
@@ -139,7 +137,7 @@ export const EventTeamWebhooksTab = ({
<EmptyScreen
Icon={TbWebhook}
headline={t("create_your_first_webhook")}
description={t("create_your_first_team_webhook_description", { appName: APP_NAME })}
description={t("first_event_type_webhook_description")}
buttonRaw={
isChildrenManagedEventType && !isManagedEventType ? (
<Button StartIcon={Lock} color="secondary" disabled>
@@ -176,7 +174,14 @@ export const EventTeamWebhooksTab = ({
apps={installedApps?.items.map((app) => app.slug)}
onCancel={() => setEditModalOpen(false)}
onSubmit={(values: WebhookFormSubmitData) => {
if (subscriberUrlReserved(values.subscriberUrl, webhookToEdit?.id || "")) {
if (
subscriberUrlReserved({
subscriberUrl: values.subscriberUrl,
id: values.id,
webhooks,
eventTypeId: eventType.id,
})
) {
showToast(t("webhook_subscriber_url_reserved"), "error");
return;
}