* feat: Cal.diy — community-driven MIT-licensed fork of Cal.com This squashed commit contains all Cal.diy changes applied on top of calcom/cal.com main: - Rebrand Cal.com to Cal.diy across the entire codebase - Remove Enterprise Edition (EE) features, license checks, and AGPL restrictions - Switch license from AGPL-3.0 to MIT - Remove docs/ directory (migrated to Nextra at cal.diy) - Remove dead code: org tests, EE tips, platform nav, premium username, SAML/SSO, etc. - Clean up .env.example for self-hosted Cal.diy - Update Docker image references to calcom/cal.diy - Update README, CONTRIBUTING.md, and issue templates for Cal.diy community fork - Add PR welcome bot for Cal.diy contributors - Fix API v2 breaking changes oasdiff ignore entries - Replace Blacksmith CI runners with default GitHub Actions 3893 files changed, 20789 insertions(+), 411020 deletions(-) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * refactor: remove org-specific /organizations/:orgId endpoints from API v2 atoms controllers (#1701) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: revert Cal.diy Inc to Cal.com, Inc. in license files, copyright notices, and package metadata (#1702) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * rip out org related comments in api v2 --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
111 lines
3.8 KiB
TypeScript
111 lines
3.8 KiB
TypeScript
"use client";
|
|
|
|
import { WEBHOOK_TRIGGER_EVENTS } from "@calcom/features/webhooks/lib/constants";
|
|
import type { WebhookVersion } from "@calcom/features/webhooks/lib/interface/IWebhookRepository";
|
|
import { subscriberUrlReserved } from "@calcom/features/webhooks/lib/subscriberUrlReserved";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import type { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import { revalidateWebhooksList } from "@calcom/web/app/(use-page-wrapper)/settings/(settings-layout)/developer/webhooks/(with-loader)/actions";
|
|
import { toastManager } from "@coss/ui/components/toast";
|
|
import { useRouter } from "next/navigation";
|
|
import type { WebhookFormSubmitData } from "../components/WebhookForm";
|
|
import WebhookForm from "../components/WebhookForm";
|
|
import { WebhookVersionCTA } from "../components/WebhookVersionCTA";
|
|
import { WebhookFormHeader } from "./webhook-form-header";
|
|
import { WebhookFormSkeleton } from "./webhook-form-skeleton";
|
|
|
|
type WebhookProps = {
|
|
id: string;
|
|
userId: number | null;
|
|
teamId: number | null;
|
|
subscriberUrl: string;
|
|
payloadTemplate: string | null;
|
|
active: boolean;
|
|
eventTriggers: WebhookTriggerEvents[];
|
|
secret: string | null;
|
|
platform: boolean;
|
|
version: WebhookVersion;
|
|
};
|
|
|
|
export function EditWebhookView({ webhook }: { webhook?: WebhookProps }) {
|
|
const { t } = useLocale();
|
|
const router = useRouter();
|
|
const { data: installedApps, isPending } = trpc.viewer.apps.integrations.useQuery(
|
|
{ variant: "other", onlyInstalled: true },
|
|
{
|
|
suspense: true,
|
|
enabled: !!webhook,
|
|
}
|
|
);
|
|
|
|
const { data: webhooks } = trpc.viewer.webhook.list.useQuery(undefined, {
|
|
suspense: true,
|
|
enabled: !!webhook,
|
|
});
|
|
const editWebhookMutation = trpc.viewer.webhook.edit.useMutation({
|
|
onSuccess() {
|
|
toastManager.add({ title: t("webhook_updated_successfully"), type: "success" });
|
|
router.push("/settings/developer/webhooks");
|
|
revalidateWebhooksList();
|
|
},
|
|
onError(error) {
|
|
toastManager.add({ title: error.message, type: "error" });
|
|
},
|
|
});
|
|
|
|
if (isPending || !webhook) return <WebhookFormSkeleton titleKey="edit_webhook" />;
|
|
|
|
return (
|
|
<WebhookForm
|
|
webhook={webhook}
|
|
headerWrapper={(formMethods, children) => (
|
|
<>
|
|
<WebhookFormHeader titleKey="edit_webhook" CTA={<WebhookVersionCTA formMethods={formMethods} />} />
|
|
{children}
|
|
</>
|
|
)}
|
|
onSubmit={(values: WebhookFormSubmitData) => {
|
|
if (
|
|
subscriberUrlReserved({
|
|
subscriberUrl: values.subscriberUrl,
|
|
id: webhook.id,
|
|
webhooks,
|
|
teamId: webhook.teamId ?? undefined,
|
|
userId: webhook.userId ?? undefined,
|
|
platform: webhook.platform ?? undefined,
|
|
})
|
|
) {
|
|
toastManager.add({ title: t("webhook_subscriber_url_reserved"), type: "error" });
|
|
return;
|
|
}
|
|
|
|
if (values.changeSecret) {
|
|
values.secret = values.newSecret.trim().length ? values.newSecret : null;
|
|
}
|
|
|
|
if (!values.payloadTemplate) {
|
|
values.payloadTemplate = null;
|
|
}
|
|
|
|
editWebhookMutation.mutate({
|
|
id: webhook.id,
|
|
subscriberUrl: values.subscriberUrl,
|
|
eventTriggers: values.eventTriggers.filter((trigger) =>
|
|
WEBHOOK_TRIGGER_EVENTS.includes(trigger as (typeof WEBHOOK_TRIGGER_EVENTS)[number])
|
|
) as unknown as Parameters<typeof editWebhookMutation.mutate>[0]["eventTriggers"],
|
|
active: values.active,
|
|
payloadTemplate: values.payloadTemplate,
|
|
secret: values.secret,
|
|
time: values.time,
|
|
timeUnit: values.timeUnit,
|
|
version: values.version,
|
|
});
|
|
}}
|
|
apps={installedApps?.items.map((app) => app.slug)}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default EditWebhookView;
|