Skip to content

Scheduling infrastructure for absolutely everyone.

V2 settings - developer view (#4085)

Joe Au-Yeungded1fce6fae9
diff --git a/apps/web/components/webhook/WebhookDialogForm.tsx b/apps/web/components/webhook/WebhookDialogForm.tsx
index e1988a5c0af..6a803f94c47 100644
--- a/apps/web/components/webhook/WebhookDialogForm.tsx
+++ b/apps/web/components/webhook/WebhookDialogForm.tsx
@@ -2,6 +2,7 @@ import { Webhook } from "@prisma/client";
import { useEffect, useState } from "react";
import { Controller, useForm } from "react-hook-form";
+import customTemplate, { hasTemplateIntegration } from "@calcom/features/webhooks/utils/integrationTemplate";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import showToast from "@calcom/lib/notification";
import { trpc } from "@calcom/trpc/react";
@@ -11,11 +12,11 @@ import Switch from "@calcom/ui/Switch";
import { FieldsetLegend, Form, InputGroupBox, TextArea, TextField } from "@calcom/ui/form/fields";
import { WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP } from "@lib/webhooks/constants";
-import customTemplate, { hasTemplateIntegration } from "@lib/webhooks/integrationTemplate";
import { TWebhook } from "@components/webhook/WebhookListItem";
import WebhookTestDisclosure from "@components/webhook/WebhookTestDisclosure";
+/** @deprecated Moved to `packages/features/webhooks` */
export default function WebhookDialogForm(props: {
eventTypeId?: number;
defaultValues?: TWebhook;
diff --git a/apps/web/components/webhook/WebhookListContainer.tsx b/apps/web/components/webhook/WebhookListContainer.tsx
index 74f99e8b351..7d0f8a3f204 100644
--- a/apps/web/components/webhook/WebhookListContainer.tsx
+++ b/apps/web/components/webhook/WebhookListContainer.tsx
@@ -21,6 +21,7 @@ export type WebhookListContainerType = {
appId?: string;
};
+/** @deprecated Moved to `packages/features/webhooks` */
export default function WebhookListContainer(props: WebhookListContainerType) {
const router = useRouter();
const query = trpc.useQuery(
diff --git a/apps/web/components/webhook/WebhookListItem.tsx b/apps/web/components/webhook/WebhookListItem.tsx
index 65118b71597..e23a90344bf 100644
--- a/apps/web/components/webhook/WebhookListItem.tsx
+++ b/apps/web/components/webhook/WebhookListItem.tsx
@@ -11,6 +11,7 @@ import { useLocale } from "@lib/hooks/useLocale";
export type TWebhook = inferQueryOutput<"viewer.webhook.list">[number];
+/** @deprecated Moved to `packages/features/webhooks` */
export default function WebhookListItem(props: { webhook: TWebhook; onEditWebhook: () => void }) {
const { t } = useLocale();
const utils = trpc.useContext();
diff --git a/apps/web/components/webhook/WebhookTestDisclosure.tsx b/apps/web/components/webhook/WebhookTestDisclosure.tsx
index 34d2ae03d79..21a4d20a9e2 100644
--- a/apps/web/components/webhook/WebhookTestDisclosure.tsx
+++ b/apps/web/components/webhook/WebhookTestDisclosure.tsx
@@ -11,6 +11,7 @@ import { InputGroupBox } from "@calcom/ui/form/fields";
import { useLocale } from "@lib/hooks/useLocale";
+/** @deprecated Moved to `packages/features/webhooks` */
export default function WebhookTestDisclosure() {
const subscriberUrl: string = useWatch({ name: "subscriberUrl" });
const payloadTemplate = useWatch({ name: "payloadTemplate" }) || null;
diff --git a/apps/web/lib/webhooks/sendPayload.tsx b/apps/web/lib/webhooks/sendPayload.tsx
index be765d53ed0..e396f36258b 100644
--- a/apps/web/lib/webhooks/sendPayload.tsx
+++ b/apps/web/lib/webhooks/sendPayload.tsx
@@ -5,8 +5,6 @@ import { compile } from "handlebars";
import { getHumanReadableLocationValue } from "@calcom/app-store/locations";
import type { CalendarEvent } from "@calcom/types/Calendar";
-import { getTranslation } from "@server/lib/i18n";
-
type ContentType = "application/json" | "application/x-www-form-urlencoded";
export type EventTypeInfo = {
diff --git a/apps/web/middleware.ts b/apps/web/middleware.ts
index 8d53b468d42..b00d073d89e 100644
--- a/apps/web/middleware.ts
+++ b/apps/web/middleware.ts
@@ -7,6 +7,8 @@ import { extendEventData, nextCollectBasicSettings } from "@calcom/lib/telemetry
const V2_WHITELIST = [
"/settings/admin",
+ "/settings/developer/webhooks",
+ "/settings/developer/api-keys",
"/settings/my-account",
"/settings/security",
"/availability",
diff --git a/apps/web/pages/api/book/event.ts b/apps/web/pages/api/book/event.ts
index d9a5fe00075..aa3eee55bdc 100644
--- a/apps/web/pages/api/book/event.ts
+++ b/apps/web/pages/api/book/event.ts
@@ -21,6 +21,7 @@ import {
sendScheduledSeatsEmails,
} from "@calcom/emails";
import { scheduleWorkflowReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
+import getWebhooks from "@calcom/features/webhooks/utils/getWebhooks";
import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";
import { getDefaultEvent, getGroupName, getUsernameList } from "@calcom/lib/defaultEvents";
import { getErrorFromUnknown } from "@calcom/lib/errors";
@@ -28,7 +29,6 @@ import isOutOfBounds, { BookingDateInPastError } from "@calcom/lib/isOutOfBounds
import logger from "@calcom/lib/logger";
import { defaultResponder, getLuckyUser } from "@calcom/lib/server";
import { updateWebUser as syncServicesUpdateWebUser } from "@calcom/lib/sync/SyncServiceManager";
-import getSubscribers from "@calcom/lib/webhooks/subscriptions";
import prisma, { userSelect } from "@calcom/prisma";
import { extendedBookingCreateBody, requiredCustomInputSchema } from "@calcom/prisma/zod-utils";
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
@@ -827,7 +827,7 @@ async function handler(req: NextApiRequest) {
triggerEvent: WebhookTriggerEvents.MEETING_ENDED,
};
- const subscribersMeetingEnded = await getSubscribers(subscriberOptionsMeetingEnded);
+ const subscribersMeetingEnded = await getWebhooks(subscriberOptionsMeetingEnded);
subscribersMeetingEnded.forEach((subscriber) => {
if (rescheduleUid && originalRescheduledBooking) {
@@ -839,7 +839,7 @@ async function handler(req: NextApiRequest) {
});
// Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED
- const subscribers = await getSubscribers(subscriberOptions);
+ const subscribers = await getWebhooks(subscriberOptions);
console.log("evt:", {
...evt,
metadata: reqBody.metadata,
diff --git a/apps/web/pages/v2/settings/developer/api-keys.tsx b/apps/web/pages/v2/settings/developer/api-keys.tsx
new file mode 100644
index 00000000000..a128acb0dc3
--- /dev/null
+++ b/apps/web/pages/v2/settings/developer/api-keys.tsx
@@ -0,0 +1,88 @@
+import { useState } from "react";
+
+import { TApiKeys } from "@calcom/ee/api-keys/components/ApiKeyListItem";
+import LicenseRequired from "@calcom/ee/common/components/v2/LicenseRequired";
+import ApiKeyDialogForm from "@calcom/features/ee/api-keys/components/v2/ApiKeyDialogForm";
+import ApiKeyListItem from "@calcom/features/ee/api-keys/components/v2/ApiKeyListItem";
+import { useLocale } from "@calcom/lib/hooks/useLocale";
+import { trpc } from "@calcom/trpc/react";
+import { Icon } from "@calcom/ui";
+import SkeletonLoader from "@calcom/ui/apps/SkeletonLoader";
+import { EmptyScreen, Button } from "@calcom/ui/v2";
+import { Dialog, DialogContent } from "@calcom/ui/v2/core/Dialog";
+import Meta from "@calcom/ui/v2/core/Meta";
+import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout";
+
+const ApiKeysView = () => {
+ const { t } = useLocale();
+
+ const { data, isLoading } = trpc.useQuery(["viewer.apiKeys.list"]);
+
+ const [apiKeyModal, setApiKeyModal] = useState(false);
+ const [apiKeyToEdit, setApiKeyToEdit] = useState<(TApiKeys & { neverExpires?: boolean }) | undefined>(
+ undefined
+ );
+
+ const NewApiKeyButton = () => {
+ return (
+ <Button
+ color="secondary"
+ StartIcon={Icon.FiPlus}
+ onClick={() => {
+ setApiKeyToEdit(undefined);
+ setApiKeyModal(true);
+ }}>
+ {t("new_api_key")}
+ </Button>
+ );
+ };
+
+ return (
+ <>
+ <Meta title="api_keys" description="webhooks_description" />
+
+ <LicenseRequired>
+ <>
+ {isLoading && <SkeletonLoader />}
+ <div>
+ {data?.length ? (
+ <>
+ <div className="mt-6 mb-8 rounded-md border">
+ {data?.map((apiKey, index) => (
+ <ApiKeyListItem
+ key={apiKey.id}
+ apiKey={apiKey}
+ lastItem={data.length === index + 1}
+ onEditClick={() => {
+ setApiKeyToEdit(apiKey);
+ setApiKeyModal(true);
+ }}
+ />
+ ))}
+ </div>
+ <NewApiKeyButton />
+ </>
+ ) : (
+ <EmptyScreen
+ Icon={Icon.FiLink}
+ headline={t("create_first_api_key")}
+ description={t("create_first_api_key_description")}
+ buttonRaw={<NewApiKeyButton />}
+ />
+ )}
+ </div>
+ </>
+ </LicenseRequired>
+
+ <Dialog open={apiKeyModal} onOpenChange={setApiKeyModal}>
+ <DialogContent type="creation" useOwnActionButtons>
+ <ApiKeyDialogForm handleClose={() => setApiKeyModal(false)} defaultValues={apiKeyToEdit} />
+ </DialogContent>
+ </Dialog>
+ </>
+ );
+};
+
+ApiKeysView.getLayout = getLayout;
+
+export default ApiKeysView;
diff --git a/apps/web/pages/v2/settings/developer/webhooks/[id]/index.tsx b/apps/web/pages/v2/settings/developer/webhooks/[id]/index.tsx
new file mode 100644
index 00000000000..b8da5282848
--- /dev/null
+++ b/apps/web/pages/v2/settings/developer/webhooks/[id]/index.tsx
@@ -0,0 +1 @@
+export { default } from "@calcom/features/webhooks/pages/webhook-edit-view";
diff --git a/apps/web/pages/v2/settings/developer/webhooks/index.tsx b/apps/web/pages/v2/settings/developer/webhooks/index.tsx
new file mode 100644
index 00000000000..d06442e3d28
--- /dev/null
+++ b/apps/web/pages/v2/settings/developer/webhooks/index.tsx
@@ -0,0 +1 @@
+export { default } from "@calcom/features/webhooks/pages/webhooks-view";
diff --git a/apps/web/pages/v2/settings/developer/webhooks/new.tsx b/apps/web/pages/v2/settings/developer/webhooks/new.tsx
new file mode 100644
index 00000000000..05e067b1993
--- /dev/null
+++ b/apps/web/pages/v2/settings/developer/webhooks/new.tsx
@@ -0,0 +1 @@
+export { default } from "@calcom/features/webhooks/pages/webhook-new-view";
diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json
index d0cd0a5148b..1d2caa4f9ab 100644
--- a/apps/web/public/static/locales/en/common.json
+++ b/apps/web/public/static/locales/en/common.json
@@ -352,10 +352,10 @@
"booking_cancelled": "Booking Cancelled",
"booking_rescheduled": "Booking Rescheduled",
"booking_created": "Booking Created",
- "meeting_ended": "Meeting ended",
+ "meeting_ended": "Meeting Ended",
"form_submitted": "Form Submitted",
"event_triggers": "Event Triggers",
- "subscriber_url": "Subscriber Url",
+ "subscriber_url": "Subscriber URL",
"create_new_webhook": "Create a new webhook",
"webhooks": "Webhooks",
"team_webhooks": "Team Webhooks",
@@ -1166,6 +1166,8 @@
"download_responses": "Download Responses",
"create_your_first_form": "Create your first form",
"create_your_first_form_description": "With Routing Forms you can ask qualifying questions and route to the correct person or event type.",
+ "create_your_first_webhook": "Create your first Webhook",
+ "create_your_first_webhook_description": "With Webhooks you can receive meeting data in real-time when something happens in Cal.com.",
"for_a_maximum_of": "For a maximum of",
"event_one": "event",
"event_other": "events",
@@ -1187,6 +1189,23 @@
"add_new_form": "Add new form",
"form_description": "Create your form to route a booker",
"copy_link_to_form": "Copy link to form",
+ "add_webhook_description": "Receive meeting data in real-time when something happens in Cal.com",
+ "triggers_when": "Triggers when",
+ "test_webhook": "Please ping test before creating.",
+ "enable_webhook": "Enable Webhook",
+ "add_webhook": "Add Webhook",
+ "webhook_edited_successfully": "Webhook saved",
+ "webhooks_description": "Receive meeting data in real-time when something happens in Cal.com",
+ "api_keys_description": "Generate API keys for accessing your own account",
+ "new_api_key": "New API key",
+ "active": "Active",
+ "api_key_updated": "API key name updated",
+ "api_key_update_failed": "Error updating API key name",
+ "embeds_title": "HTML iframe embed",
+ "embeds_description": "Embed all your event types on your website",
+ "pending_payment": "Pending payment",
+ "create_first_api_key": "Create your first API key",
+ "create_first_api_key_description": "API keys allow other apps to communicate with Cal.com",
"back_to_signin": "Back to sign in",
"reset_link_sent": "Reset link sent",
"password_reset_email":"An email is on it’s way to {{email}} with instructions to reset your password.",
diff --git a/packages/app-store/ee/routing_forms/trpc-router.ts b/packages/app-store/ee/routing_forms/trpc-router.ts
index e3fdc9f816b..614c3dd67ac 100644
--- a/packages/app-store/ee/routing_forms/trpc-router.ts
+++ b/packages/app-store/ee/routing_forms/trpc-router.ts
@@ -2,8 +2,8 @@ import { Prisma, WebhookTriggerEvents } from "@prisma/client";
import { v4 as uuidv4 } from "uuid";
import { z } from "zod";
+import getWebhooks from "@calcom/features/webhooks/utils/getWebhooks";
import { sendGenericWebhookPayload } from "@calcom/lib/webhooks/sendPayload";
-import getWebhooks from "@calcom/lib/webhooks/subscriptions";
import { TRPCError } from "@calcom/trpc/server";
import { createProtectedRouter, createRouter } from "@calcom/trpc/server/createRouter";
diff --git a/packages/features/ee/api-keys/components/v2/ApiKeyDialogForm.tsx b/packages/features/ee/api-keys/components/v2/ApiKeyDialogForm.tsx
new file mode 100644
index 00000000000..0217d72cd76
--- /dev/null
+++ b/packages/features/ee/api-keys/components/v2/ApiKeyDialogForm.tsx
@@ -0,0 +1,182 @@
+import { useState } from "react";
+import { Controller, useForm } from "react-hook-form";
+
+import dayjs from "@calcom/dayjs";
+import { TApiKeys } from "@calcom/ee/api-keys/components/ApiKeyListItem";
+import LicenseRequired from "@calcom/ee/common/components/v2/LicenseRequired";
+import { useLocale } from "@calcom/lib/hooks/useLocale";
+import showToast from "@calcom/lib/notification";
+import { trpc } from "@calcom/trpc/react";
+import { DialogFooter } from "@calcom/ui/Dialog";
+import { ClipboardCopyIcon } from "@calcom/ui/Icon";
+import { Tooltip } from "@calcom/ui/Tooltip";
+import { DatePicker } from "@calcom/ui/v2";
+import Button from "@calcom/ui/v2/core/Button";
+import Switch from "@calcom/ui/v2/core/Switch";
+import { Form, TextField } from "@calcom/ui/v2/core/form/fields";
+
+export default function ApiKeyDialogForm({
+ defaultValues,
+ handleClose,
+}: {
+ defaultValues?: Omit<TApiKeys, "userId" | "createdAt" | "lastUsedAt"> & { neverExpires?: boolean };
+ handleClose: () => void;
+}) {
+ const { t } = useLocale();
+ const utils = trpc.useContext();
+
+ const updateApiKeyMutation = trpc.useMutation("viewer.apiKeys.edit", {
+ onSuccess() {
+ utils.invalidateQueries("viewer.apiKeys.list");
+ showToast(t("api_key_updated"), "success");
+ handleClose();
+ },
+ onError() {
+ showToast(t("api_key_update_failed"), "error");
+ },
+ });
+
+ const [apiKey, setApiKey] = useState("");
+ const [successfulNewApiKeyModal, setSuccessfulNewApiKeyModal] = useState(false);
+ const [apiKeyDetails, setApiKeyDetails] = useState({
+ expiresAt: null as Date | null,
+ note: "" as string | null,
+ neverExpires: false,
+ });
+
+ const form = useForm({
+ defaultValues: {
+ note: defaultValues?.note || "",
+ neverExpires: defaultValues?.neverExpires || false,
+ expiresAt: defaultValues?.expiresAt || dayjs().add(1, "month").toDate(),
+ },
+ });
+ const watchNeverExpires = form.watch("neverExpires");
+
+ return (
+ <LicenseRequired>
+ {successfulNewApiKeyModal ? (
+ <>
+ <div className="mb-10">
+ <h2 className="font-semi-bold font-cal mb-2 text-xl tracking-wide text-gray-900">
+ {t("success_api_key_created")}
+ </h2>
+ <div className="text-sm text-gray-900">
+ <span className="font-semibold">{t("success_api_key_created_bold_tagline")}</span>{" "}
+ {t("you_will_only_view_it_once")}
+ </div>
+ </div>
+ <div>
+ <div className="flex">
+ <code className="my-2 mr-1 w-full truncate rounded-sm bg-gray-100 py-2 px-3 align-middle font-mono text-gray-800">
+ {apiKey}
+ </code>
+ <Tooltip side="top" content={t("copy_to_clipboard")}>
+ <Button
+ onClick={() => {
+ navigator.clipboard.writeText(apiKey);
+ showToast(t("api_key_copied"), "success");
+ }}
+ type="button"
+ className=" my-2 px-4 text-base">
+ <ClipboardCopyIcon className="mr-2 h-5 w-5 text-neutral-100" />
+ {t("copy")}
+ </Button>
+ </Tooltip>
+ </div>
+ <span className="text-sm text-gray-400">
+ {apiKeyDetails.neverExpires
+ ? t("never_expire_key")
+ : `${t("expires")} ${apiKeyDetails?.expiresAt?.toLocaleDateString()}`}
+ </span>
+ </div>
+ <DialogFooter>
+ <Button type="button" color="secondary" onClick={handleClose} tabIndex={-1}>
+ {t("done")}
+ </Button>
+ </DialogFooter>
+ </>
+ ) : (
+ <Form
+ form={form}
+ handleSubmit={async (event) => {
+ if (defaultValues) {
+ console.log("Name changed");
+ await updateApiKeyMutation.mutate({ id: defaultValues.id, note: event.note });
+ } else {
+ const apiKey = await utils.client.mutation("viewer.apiKeys.create", event);
+ setApiKey(apiKey);
+ setApiKeyDetails({ ...event });
+ await utils.invalidateQueries(["viewer.apiKeys.list"]);
+ setSuccessfulNewApiKeyModal(true);
+ }
+ }}
+ className="space-y-4">
+ <div className="mb-10 mt-1">
+ <h2 className="font-semi-bold font-cal text-xl tracking-wide text-gray-900">
+ {defaultValues ? t("edit_api_key") : t("create_api_key")}
+ </h2>
+ <p className="mt-1 mb-5 text-sm text-gray-500">{t("api_key_modal_subtitle")}</p>
+ </div>
+ <div>
+ <Controller
+ name="note"
+ control={form.control}
+ render={({ field: { onChange, value } }) => (
+ <TextField
+ name="note"
+ label={t("personal_note")}
+ placeholder={t("personal_note_placeholder")}
+ value={value}
+ onChange={(e) => {
+ form.setValue("note", e?.target.value);
+ }}
+ type="text"
+ />
+ )}
+ />
+ </div>
+ {!defaultValues && (
+ <div className="flex flex-col">
+ <div className="flex justify-between py-2">
+ <span className="block text-sm font-medium text-gray-700">{t("expire_date")}</span>
+ <Controller
+ name="neverExpires"
+ control={form.control}
+ render={({ field: { onChange, value } }) => (
+ <Switch
+ label={t("never_expire_key")}
+ onCheckedChange={onChange}
+ checked={value}
+ disabled={!!defaultValues}
+ />
+ )}
+ />
+ </div>
+ <Controller
+ name="expiresAt"
+ render={({ field: { onChange, value } }) => (
+ <DatePicker
+ disabled={watchNeverExpires || !!defaultValues}
+ minDate={new Date()}
+ date={value}
+ onDatesChange={onChange}
+ />
+ )}
+ />
+ </div>
+ )}
+
+ <DialogFooter>
+ <Button type="button" color="secondary" onClick={handleClose} tabIndex={-1}>
+ {t("cancel")}
+ </Button>
+ <Button type="submit" loading={form.formState.isSubmitting}>
+ {apiKeyDetails ? t("save") : t("create")}
+ </Button>
+ </DialogFooter>
+ </Form>
+ )}
+ </LicenseRequired>
+ );
+}
diff --git a/packages/features/ee/api-keys/components/v2/ApiKeyListItem.tsx b/packages/features/ee/api-keys/components/v2/ApiKeyListItem.tsx
new file mode 100644
index 00000000000..3157c903101
--- /dev/null
+++ b/packages/features/ee/api-keys/components/v2/ApiKeyListItem.tsx
@@ -0,0 +1,92 @@
+import dayjs from "@calcom/dayjs";
+import { TApiKeys } from "@calcom/ee/api-keys/components/ApiKeyListItem";
+import { classNames } from "@calcom/lib";
+import { useLocale } from "@calcom/lib/hooks/useLocale";
+import { trpc } from "@calcom/trpc/react";
+import { Icon } from "@calcom/ui";
+import Badge from "@calcom/ui/v2/core/Badge";
+import Button from "@calcom/ui/v2/core/Button";
+import Dropdown, {
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from "@calcom/ui/v2/core/Dropdown";
+
+const ApiKeyListItem = ({
+ apiKey,
+ lastItem,
+ onEditClick,
+}: {
+ apiKey: TApiKeys;
+ lastItem: boolean;
+ onEditClick: () => void;
+}) => {
+ const { t } = useLocale();
+ const utils = trpc.useContext();
+
+ const isExpired = apiKey?.expiresAt ? apiKey.expiresAt < new Date() : null;
+ const neverExpires = apiKey?.expiresAt === null;
+
+ const deleteApiKey = trpc.useMutation("viewer.apiKeys.delete", {
+ async onSuccess() {
+ await utils.invalidateQueries(["viewer.apiKeys.list"]);
+ },
+ });
+
+ return (
+ <div
+ key={apiKey.id}
+ className={classNames("flex w-full justify-between p-4", lastItem ? "" : "border-b")}>
+ <div>
+ <p className="font-medium"> {apiKey?.note ? apiKey.note : t("api_key_no_note")}</p>
+ <div className="flex items-center space-x-3.5">
+ {!neverExpires && isExpired && (
+ <Badge className="-p-2" variant="red">
+ {t("expired")}
+ </Badge>
+ )}
+ {!isExpired && (
+ <Badge className="-p-2" variant="green">
+ {t("active")}
+ </Badge>
+ )}
+ <p className="text-gray-600">
+ {" "}
+ {neverExpires ? (
+ <div className="flex flex-row space-x-3 text-gray-500">{t("api_key_never_expires")}</div>
+ ) : (
+ `${isExpired ? t("expired") : t("expires")} ${dayjs(apiKey?.expiresAt?.toString()).fromNow()}`
+ )}
+ </p>
+ </div>
+ </div>
+ <div>
+ <Dropdown>
+ <DropdownMenuTrigger asChild>
+ <Button size="icon" StartIcon={Icon.FiMoreHorizontal} color="secondary" />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ <DropdownMenuItem
+ className="flex items-center space-x-2.5 py-3 pr-32 pl-3.5"
+ onClick={onEditClick}>
+ <Icon.FiEdit2 />
+ <p>{t("edit")}</p>
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ className="flex items-center space-x-2.5 py-3 pr-32 pl-3.5"
+ onClick={() =>
+ deleteApiKey.mutate({
+ id: apiKey.id,
+ })
+ }>
+ <Icon.FiTrash2 />
+ <p>{t("delete")}</p>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </Dropdown>
+ </div>
+ </div>
+ );
+};
+
+export default ApiKeyListItem;
diff --git a/packages/features/webhooks/components/WebhookForm.tsx b/packages/features/webhooks/components/WebhookForm.tsx
new file mode 100644
index 00000000000..d0d101029e3
--- /dev/null
+++ b/packages/features/webhooks/components/WebhookForm.tsx
@@ -0,0 +1,266 @@
+import { WebhookTriggerEvents } from "@prisma/client";
+import { useEffect, useState } from "react";
+import { Controller, useForm } from "react-hook-form";
+
+import { classNames } from "@calcom/lib";
+import { WEBAPP_URL } from "@calcom/lib/constants";
+import { useLocale } from "@calcom/lib/hooks/useLocale";
+import { inferQueryOutput } from "@calcom/trpc/react";
+import Button from "@calcom/ui/v2/core/Button";
+import Switch from "@calcom/ui/v2/core/Switch";
+import Select from "@calcom/ui/v2/core/form/Select";
+import { Form, Label, TextArea, TextField } from "@calcom/ui/v2/core/form/fields";
+
+import customTemplate, { hasTemplateIntegration } from "../utils/integrationTemplate";
+import WebhookTestDisclosure from "./WebhookTestDisclosure";
+
+export type TWebhook = inferQueryOutput<"viewer.webhook.list">[number];
+
+export type WebhookFormData = {
+ id?: string;
+ subscriberUrl: string;
+ active: boolean;
+ eventTriggers: WebhookTriggerEvents[];
+ secret: string | null;
+ payloadTemplate: string | undefined | null;
+};
+
+export type WebhookFormSubmitData = WebhookFormData & {
+ changeSecret: boolean;
+ newSecret: string;
+};
+
+type WebhookTriggerEventOptions = { value: WebhookTriggerEvents; label: string }[];
+
+const WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2: Record<string, WebhookTriggerEventOptions> = {
+ core: [
+ { value: WebhookTriggerEvents.BOOKING_CANCELLED, label: "booking_cancelled" },
+ { value: WebhookTriggerEvents.BOOKING_CREATED, label: "booking_created" },
+ { value: WebhookTriggerEvents.BOOKING_RESCHEDULED, label: "booking_rescheduled" },
+ { value: WebhookTriggerEvents.MEETING_ENDED, label: "meeting_ended" },
+ ],
+ routing_forms: [{ value: WebhookTriggerEvents.FORM_SUBMITTED, label: "form_submitted" }],
+};
+
+const WebhookForm = (props: {
+ webhook?: WebhookFormData;
+ apps?: (keyof typeof WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2)[];
+ onSubmit: (event: WebhookFormSubmitData) => void;
+}) => {
+ const { t } = useLocale();
+
+ 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({
+ defaultValues: {
+ subscriberUrl: props?.webhook?.subscriberUrl || "",
+ active: props?.webhook?.active || false,
+ eventTriggers: props?.webhook?.eventTriggers || [],
+ secret: props?.webhook?.secret || "",
+ payloadTemplate: props?.webhook?.payloadTemplate || undefined,
+ },
+ });
+
+ const [useCustomTemplate, setUseCustomTemplate] = useState(false);
+ const [newSecret, setNewSecret] = useState("");
+ const [changeSecret, setChangeSecret] = useState(false);
+ const hasSecretKey = !!props?.webhook?.secret;
+ // const currentSecret = props?.webhook?.secret;
+
+ useEffect(() => {
+ if (changeSecret) {
+ formMethods.unregister("secret", { keepDefaultValue: false });
+ }
+ }, [changeSecret]);
+
+ return (
+ <>
+ <Form
+ form={formMethods}
+ handleSubmit={(values) => props.onSubmit({ ...values, changeSecret, newSecret })}>
+ <Controller
+ name="subscriberUrl"
+ control={formMethods.control}
+ render={({ field: { value } }) => (
+ <>
+ <TextField
+ name="subscriberUrl"
+ label={t("subscriber_url")}
+ labelClassName="font-medium text-gray-900 font-sm"
+ value={value}
+ onChange={(e) => {
+ formMethods.setValue("subscriberUrl", e?.target.value);
+ if (hasTemplateIntegration({ url: e.target.value })) {
+ setUseCustomTemplate(true);
+ formMethods.setValue("payloadTemplate", customTemplate({ url: e.target.value }));
+ }
+ }}
+ />
+ </>
+ )}
+ />
+ <Controller
+ name="active"
+ control={formMethods.control}
+ render={({ field: { value } }) => (
+ <div className="font-sm mt-8 font-medium text-gray-900">
+ <Switch
+ label={t("enable_webhook")}
+ checked={value}
+ // defaultChecked={props?.webhook?.active ? props?.webhook?.active : true}
+ onCheckedChange={(value) => {
+ formMethods.setValue("active", value);
+ }}
+ />
+ </div>
+ )}
+ />
+ <Controller
+ name="eventTriggers"
+ control={formMethods.control}
+ render={({ field: { onChange } }) => (
+ <div className="mt-8">
+ <Label className="font-sm mt-8 font-medium text-gray-900">
+ <>{t("event_triggers")}</>
+ </Label>
+ <Select
+ options={translatedTriggerOptions}
+ isMulti
+ onChange={(event) => {
+ onChange(event.map((selection) => selection.value));
+ }}
+ />
+ </div>
+ )}
+ />
+ <Controller
+ name="secret"
+ control={formMethods.control}
+ render={({ field: { value } }) => (
+ <div className="mt-8 ">
+ {!!hasSecretKey && !changeSecret && (
+ <>
+ <Label className="font-sm font-medium text-gray-900">Secret</Label>
+ <div className="space-y-0 rounded-md border-0 border-neutral-200 bg-white sm:mx-0 md:border">
+ <div className="rounded-sm border-b p-2 text-sm text-neutral-900">
+ {t("forgotten_secret_description")}
+ </div>
+ <div className="p-2">
+ <Button
+ color="secondary"
+ type="button"
+ onClick={() => {
+ setChangeSecret(true);
+ }}>
+ {t("change_secret")}
+ </Button>
+ </div>
+ </div>
+ </>
+ )}
+ {!!hasSecretKey && changeSecret && (
+ <>
+ <TextField
+ autoComplete="off"
+ label={t("secret")}
+ labelClassName="font-medium text-gray-900 font-sm"
+ {...formMethods.register("secret")}
+ value={newSecret}
+ onChange={(event) => setNewSecret(event.currentTarget.value)}
+ type="text"
+ placeholder={t("leave_blank_to_remove_secret")}
+ />
+ <Button
+ color="secondary"
+ type="button"
+ className="py-1 text-xs"
+ onClick={() => {
+ setChangeSecret(false);
+ }}>
+ {t("cancel")}
+ </Button>
+ </>
+ )}
+ {!hasSecretKey && (
+ <TextField
+ name="secret"
+ label={t("secret")}
+ labelClassName="font-medium text-gray-900 font-sm"
+ value={value}
+ onChange={(e) => {
+ formMethods.setValue("secret", e?.target.value);
+ }}
+ />
+ )}
+ </div>
+ )}
+ />
+
+ <Controller
+ name="payloadTemplate"
+ control={formMethods.control}
+ render={({ field: { value } }) => (
+ <>
+ <Label className="font-sm mt-8 text-gray-900">
+ <>{t("event_triggers")}</>
+ </Label>
+ <div className="flex rounded-md border">
+ <div
+ className={classNames(
+ "px-1/2 w-1/2 rounded-md py-2.5 text-center font-medium text-gray-900",
+ !useCustomTemplate && "bg-gray-200"
+ )}
+ onClick={() => {
+ setUseCustomTemplate(false);
+ formMethods.setValue("payloadTemplate", undefined);
+ }}>
+ <p>{t("default")}</p>
+ </div>
+ <div
+ className={classNames(
+ "px-1/2 w-1/2 rounded-md py-2.5 text-center font-medium text-gray-900",
+ useCustomTemplate && "bg-gray-200"
+ )}
+ onClick={() => setUseCustomTemplate(true)}>
+ <p>{t("custom")}</p>
+ </div>
+ </div>
+ {useCustomTemplate && (
+ <TextArea
+ name="customPayloadTemplate"
+ rows={3}
+ value={value}
+ onChange={(e) => {
+ formMethods.setValue("payloadTemplate", e?.target.value);
+ }}
+ />
+ )}
+ </>
+ )}
+ />
+ <div className="mt-8">
+ <p className="font-medium text-black">{t("webhook_test")}</p>
+ <p className="font-sm mb-4 text-gray-600">{t("test_webhook")}</p>
+ <WebhookTestDisclosure />
+ </div>
+
+ <div className="mt-12 flex place-content-end space-x-4">
+ <Button type="button" color="minimal" href={`${WEBAPP_URL}/v2/settings/developer/webhooks`}>
+ {t("cancel")}
+ </Button>
+ <Button type="submit" loading={formMethods.formState.isSubmitting}>
+ {props?.webhook?.id ? t("save") : t("create")}
+ </Button>
+ </div>
+ </Form>
+ </>
+ );
+};
+
+export default WebhookForm;
diff --git a/packages/features/webhooks/components/WebhookListItem.tsx b/packages/features/webhooks/components/WebhookListItem.tsx
new file mode 100644
index 00000000000..9d219cb2c42
--- /dev/null
+++ b/packages/features/webhooks/components/WebhookListItem.tsx
@@ -0,0 +1,78 @@
+import classNames from "@calcom/lib/classNames";
+import { useLocale } from "@calcom/lib/hooks/useLocale";
+import showToast from "@calcom/lib/notification";
+import { inferQueryOutput, trpc } from "@calcom/trpc/react";
+import { Icon } from "@calcom/ui/Icon";
+import Badge from "@calcom/ui/v2/core/Badge";
+import Button from "@calcom/ui/v2/core/Button";
+import Switch from "@calcom/ui/v2/core/Switch";
+import { Tooltip } from "@calcom/ui/v2/core/Tooltip";
+
+export type TWebhook = inferQueryOutput<"viewer.webhook.list">[number];
+
+export default function WebhookListItem(props: {
+ webhook: TWebhook;
+ onEditWebhook: () => void;
+ lastItem: boolean;
+}) {
+ const { t } = useLocale();
+ const utils = trpc.useContext();
+ const { webhook } = props;
+ const deleteWebhook = trpc.useMutation("viewer.webhook.delete", {
+ async onSuccess() {
+ await utils.invalidateQueries(["viewer.webhook.list"]);
+ // TODO: Better success message
+ showToast(t("deleted"), "success");
+ },
+ });
+ const toggleWebhook = trpc.useMutation("viewer.webhook.edit", {
+ async onSuccess(data) {
+ console.log("data", data);
+ await utils.invalidateQueries(["viewer.webhook.list"]);
+ // TODO: Better success message
+ showToast(t(data?.active ? "enabled" : "disabled"), "success");
+ },
+ });
+
+ return (
+ <div className={classNames("flex w-full justify-between p-4", props.lastItem ? "" : "border-b")}>
+ <div>
+ <p className="text-sm font-medium text-gray-900">{webhook.subscriberUrl}</p>
+ <Tooltip
+ content={webhook.eventTriggers.map((trigger) => (
+ <p key={trigger}>{t(`${trigger.toLowerCase()}`)}</p>
+ ))}>
+ <div className="mt-2.5 w-max">
+ <Badge variant="gray" bold StartIcon={Icon.FiAlertCircle}>
+ {t("triggers_when")}
+ </Badge>
+ </div>
+ </Tooltip>
+ </div>
+ <div className="flex items-center space-x-4">
+ <Switch
+ defaultChecked={webhook.active}
+ onCheckedChange={() =>
+ toggleWebhook.mutate({
+ id: webhook.id,
+ active: !webhook.active,
+ payloadTemplate: webhook.payloadTemplate,
+ })
+ }
+ />
+ <Button color="secondary" onClick={props.onEditWebhook}>
+ {t("edit")}
+ </Button>
+ <Button
+ color="destructive"
+ StartIcon={Icon.FiTrash}
+ size="icon"
+ onClick={() => {
+ // TODO: Confimation dialog before deleting
+ deleteWebhook.mutate({ id: webhook.id });
+ }}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/packages/features/webhooks/components/WebhookListItemSkeleton.tsx b/packages/features/webhooks/components/WebhookListItemSkeleton.tsx
new file mode 100644
index 00000000000..09711aadffd
--- /dev/null
+++ b/packages/features/webhooks/components/WebhookListItemSkeleton.tsx
@@ -0,0 +1,19 @@
+import { SkeletonText } from "@calcom/ui/v2";
+
+export default function WebhookListItemSkeleton() {
+ return (
+ <div className="flex w-full justify-between p-4">
+ <div>
+ <p className="text-sm font-medium text-gray-900">
+ <SkeletonText className="h-4 w-56" />
+ </p>
+ <div className="mt-2.5 w-max">
+ <SkeletonText className="h-5 w-28" />
+ </div>
+ </div>
+ <div className="flex items-center space-x-4">
+ <SkeletonText className="h-9 w-9" />
+ </div>
+ </div>
+ );
+}
diff --git a/packages/features/webhooks/components/WebhookListSkeleton.tsx b/packages/features/webhooks/components/WebhookListSkeleton.tsx
new file mode 100644
index 00000000000..2e77941ea1e
--- /dev/null
+++ b/packages/features/webhooks/components/WebhookListSkeleton.tsx
@@ -0,0 +1,15 @@
+import { SkeletonContainer } from "@calcom/ui/v2";
+
+import WebhookListItemSkeleton from "./WebhookListItemSkeleton";
+
+export default function WebhookListSkeleton() {
+ return (
+ <SkeletonContainer>
+ <div className="mt-6 mb-8 divide-y rounded-md border">
+ <WebhookListItemSkeleton />
+ <WebhookListItemSkeleton />
+ <WebhookListItemSkeleton />
+ </div>
+ </SkeletonContainer>
+ );
+}
diff --git a/packages/features/webhooks/components/WebhookTestDisclosure.tsx b/packages/features/webhooks/components/WebhookTestDisclosure.tsx
new file mode 100644
index 00000000000..3581788bf48
--- /dev/null
+++ b/packages/features/webhooks/components/WebhookTestDisclosure.tsx
@@ -0,0 +1,48 @@
+import { useWatch } from "react-hook-form";
+
+import { useLocale } from "@calcom/lib/hooks/useLocale";
+import showToast from "@calcom/lib/notification";
+import { trpc } from "@calcom/trpc/react";
+import { Icon } from "@calcom/ui/Icon";
+import Badge from "@calcom/ui/v2/core/Badge";
+import Button from "@calcom/ui/v2/core/Button";
+
+export default function WebhookTestDisclosure() {
+ const subscriberUrl: string = useWatch({ name: "subscriberUrl" });
+ const payloadTemplate = useWatch({ name: "payloadTemplate" }) || null;
+ const { t } = useLocale();
+ const mutation = trpc.useMutation("viewer.webhook.testTrigger", {
+ onError(err) {
+ showToast(err.message, "error");
+ },
+ });
+
+ return (
+ <div className="space-y-0 rounded-md border-0 border-neutral-200 bg-white sm:mx-0 md:border">
+ <div className="flex justify-between border-b p-4">
+ <div className="flex items-center space-x-1">
+ <h3 className="font-sm self-center font-medium text-black">{t("webhook_response")}</h3>
+ {mutation.data && (
+ <Badge variant={mutation.data.ok ? "green" : "red"}>
+ {mutation.data.ok ? t("passed") : t("failed")}
+ </Badge>
+ )}
+ </div>
+ <Button
+ type="button"
+ color="secondary"
+ disabled={mutation.isLoading}
+ StartIcon={Icon.FiActivity}
+ onClick={() => mutation.mutate({ url: subscriberUrl, type: "PING", payloadTemplate })}>
+ {t("ping_test")}
+ </Button>
+ </div>
+ <div className="p-4">
+ {!mutation.data && <em>{t("no_data_yet")}</em>}
+ {mutation.status === "success" && (
+ <div className="overflow-x-auto text-gray-900">{JSON.stringify(mutation.data, null, 4)}</div>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/packages/features/webhooks/components/index.ts b/packages/features/webhooks/components/index.ts
new file mode 100644
index 00000000000..86351d5243a
--- /dev/null
+++ b/packages/features/webhooks/components/index.ts
@@ -0,0 +1,5 @@
+export { default as WebhookForm } from "./WebhookForm";
+export { default as WebhookListItem } from "./WebhookListItem";
+export { default as WebhookListItemSkeleton } from "./WebhookListItemSkeleton";
+export { default as WebhookListSkeleton } from "./WebhookListSkeleton";
+export { default as WebhookTestDisclosure } from "./WebhookTestDisclosure";
diff --git a/packages/features/webhooks/pages/webhook-edit-view.tsx b/packages/features/webhooks/pages/webhook-edit-view.tsx
new file mode 100644
index 00000000000..ef7f298920e
--- /dev/null
+++ b/packages/features/webhooks/pages/webhook-edit-view.tsx
@@ -0,0 +1,89 @@
+import { useRouter } from "next/router";
+import z from "zod";
+
+import { useLocale } from "@calcom/lib/hooks/useLocale";
+import { trpc } from "@calcom/trpc/react";
+import { SkeletonContainer } from "@calcom/ui/v2";
+import Meta from "@calcom/ui/v2/core/Meta";
+import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout";
+import showToast from "@calcom/ui/v2/core/notifications";
+
+import WebhookForm, { WebhookFormSubmitData } from "../components/WebhookForm";
+
+const querySchema = z.object({ id: z.string() });
+
+const EditWebhook = () => {
+ const { t } = useLocale();
+ const utils = trpc.useContext();
+ const router = useRouter();
+ const { id: webhookId } = querySchema.parse(router.query);
+
+ const { data: installedApps, isLoading } = trpc.useQuery(
+ ["viewer.integrations", { variant: "other", onlyInstalled: true }],
+ {
+ suspense: true,
+ enabled: router.isReady,
+ }
+ );
+ const { data: webhook } = trpc.useQuery(["viewer.webhook.get", { webhookId }], {
+ suspense: true,
+ enabled: router.isReady,
+ });
+ const { data: webhooks } = trpc.useQuery(["viewer.webhook.list"], {
+ suspense: true,
+ enabled: router.isReady,
+ });
+ const editWebhookMutation = trpc.useMutation("viewer.webhook.edit", {
+ async onSuccess() {
+ await utils.invalidateQueries(["viewer.webhook.list"]);
+ },
+ onError(error) {
+ showToast(`${error.message}`, "error");
+ },
+ });
+
+ const subscriberUrlReserved = (subscriberUrl: string, id: string): boolean => {
+ return !!webhooks?.find((webhook) => webhook.subscriberUrl === subscriberUrl && webhook.id !== id);
+ };
+
+ if (isLoading || !webhook) return <SkeletonContainer />;
+
+ return (
+ <>
+ <Meta title="edit_webhook" description="add_webhook_description" backButton />
+ <WebhookForm
+ webhook={webhook}
+ onSubmit={(values: WebhookFormSubmitData) => {
+ if (subscriberUrlReserved(values.subscriberUrl, webhook.id)) {
+ showToast(t("webhook_subscriber_url_reserved"), "error");
+ return;
+ }
+
+ if (values.changeSecret) {
+ values.secret = values.newSecret.length ? values.newSecret : null;
+ }
+
+ if (!values.payloadTemplate) {
+ values.payloadTemplate = null;
+ }
+
+ editWebhookMutation.mutate({
+ id: webhook.id,
+ subscriberUrl: values.subscriberUrl,
+ eventTriggers: values.eventTriggers,
+ active: values.active,
+ payloadTemplate: values.payloadTemplate,
+ secret: values.secret,
+ });
+ showToast(t("webhook_updated_successfully"), "success");
+ router.back();
+ }}
+ apps={installedApps?.items.map((app) => app.slug)}
+ />
+ </>
+ );
+};
+
+EditWebhook.getLayout = getLayout;
+
+export default EditWebhook;
diff --git a/packages/features/webhooks/pages/webhook-new-view.tsx b/packages/features/webhooks/pages/webhook-new-view.tsx
new file mode 100644
index 00000000000..0bfed41e7b8
--- /dev/null
+++ b/packages/features/webhooks/pages/webhook-new-view.tsx
@@ -0,0 +1,76 @@
+import { useRouter } from "next/router";
+
+import { useLocale } from "@calcom/lib/hooks/useLocale";
+import { trpc } from "@calcom/trpc/react";
+import { SkeletonContainer } from "@calcom/ui/v2";
+import Meta from "@calcom/ui/v2/core/Meta";
+import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout";
+import showToast from "@calcom/ui/v2/core/notifications";
+
+import WebhookForm, { WebhookFormSubmitData } from "../components/WebhookForm";
+
+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 }],
+ {
+ suspense: true,
+ enabled: router.isReady,
+ }
+ );
+ const { data: webhooks } = trpc.useQuery(["viewer.webhook.list"], {
+ suspense: true,
+ enabled: router.isReady,
+ });
+
+ const createWebhookMutation = trpc.useMutation("viewer.webhook.create", {
+ async onSuccess() {
+ await utils.invalidateQueries(["viewer.webhook.list"]);
+ },
+ onError(error) {
+ showToast(`${error.message}`, "error");
+ },
+ });
+
+ const subscriberUrlReserved = (subscriberUrl: string, id: string): boolean => {
+ return !!webhooks?.find((webhook) => webhook.subscriberUrl === subscriberUrl && webhook.id !== id);
+ };
+
+ const onCreateWebhook = async (values: WebhookFormSubmitData) => {
+ if (values.id && subscriberUrlReserved(values.subscriberUrl, values.id)) {
+ showToast(t("webhook_subscriber_url_reserved"), "error");
+ return;
+ }
+
+ if (!values.payloadTemplate) {
+ values.payloadTemplate = null;
+ }
+
+ createWebhookMutation.mutate({
+ subscriberUrl: values.subscriberUrl,
+ eventTriggers: values.eventTriggers,
+ active: values.active,
+ payloadTemplate: values.payloadTemplate,
+ secret: values.secret,
+ });
+ showToast(t("webhook_created_successfully"), "success");
+ router.back();
+ };
+
+ if (isLoading) return <SkeletonContainer />;
+
+ return (
+ <>
+ <Meta title="add_webhook" description="add_webhook_description" backButton />
+
+ <WebhookForm onSubmit={onCreateWebhook} apps={installedApps?.items.map((app) => app.slug)} />
+ </>
+ );
+};
+
+NewWebhookView.getLayout = getLayout;
+
+export default NewWebhookView;
diff --git a/packages/features/webhooks/pages/webhooks-view.tsx b/packages/features/webhooks/pages/webhooks-view.tsx
new file mode 100644
index 00000000000..8591204478e
--- /dev/null
+++ b/packages/features/webhooks/pages/webhooks-view.tsx
@@ -0,0 +1,81 @@
+import { useRouter } from "next/router";
+import { Suspense } from "react";
+
+import { WEBAPP_URL } from "@calcom/lib/constants";
+import { useLocale } from "@calcom/lib/hooks/useLocale";
+import { trpc } from "@calcom/trpc/react";
+import { Icon } from "@calcom/ui";
+import { ButtonGroup, EmptyScreen, SkeletonText } from "@calcom/ui/v2";
+import { Button } from "@calcom/ui/v2/core/Button";
+import Meta from "@calcom/ui/v2/core/Meta";
+import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout";
+
+import { WebhookListItem, WebhookListSkeleton } from "../components";
+
+const WebhooksView = () => {
+ return (
+ <>
+ <Meta title="webhooks" description="webhooks_description" />
+ <div>
+ <Suspense fallback={<WebhookListSkeleton />}>
+ <WebhooksList />
+ </Suspense>
+ </div>
+ </>
+ );
+};
+
+const NewWebhookButton = () => {
+ const { t, isLocaleReady } = useLocale();
+ return (
+ <Button
+ color="secondary"
+ StartIcon={Icon.FiPlus}
+ href={`${WEBAPP_URL}/v2/settings/developer/webhooks/new`}>
+ {isLocaleReady ? t("new_webhook") : <SkeletonText className="h-4 w-24" />}
+ </Button>
+ );
+};
+
+const WebhooksList = () => {
+ const { t } = useLocale();
+ const router = useRouter();
+
+ const { data: webhooks } = trpc.useQuery(["viewer.webhook.list"], {
+ suspense: true,
+ enabled: router.isReady,
+ });
+
+ return (
+ <>
+ {webhooks?.length ? (
+ <>
+ <div className="mt-6 mb-8 rounded-md border">
+ {webhooks.map((webhook, index) => (
+ <WebhookListItem
+ key={webhook.id}
+ webhook={webhook}
+ lastItem={webhooks.length === index + 1}
+ onEditWebhook={() =>
+ router.push(`${WEBAPP_URL}/v2/settings/developer/webhooks/${webhook.id} `)
+ }
+ />
+ ))}
+ </div>
+ <NewWebhookButton />
+ </>
+ ) : (
+ <EmptyScreen
+ Icon={Icon.FiLink}
+ headline={t("create_your_first_webhook")}
+ description={t("create_your_first_webhook_description")}
+ buttonRaw={<NewWebhookButton />}
+ />
+ )}
+ </>
+ );
+};
+
+WebhooksView.getLayout = getLayout;
+
+export default WebhooksView;
diff --git a/packages/lib/webhooks/subscriptions.tsx b/packages/features/webhooks/utils/getWebhooks.tsx
similarity index 100%
rename from packages/lib/webhooks/subscriptions.tsx
rename to packages/features/webhooks/utils/getWebhooks.tsx
diff --git a/apps/web/lib/webhooks/integrationTemplate.tsx b/packages/features/webhooks/utils/integrationTemplate.tsx
similarity index 100%
rename from apps/web/lib/webhooks/integrationTemplate.tsx
rename to packages/features/webhooks/utils/integrationTemplate.tsx
diff --git a/packages/lib/webhooks/integrationTemplate.tsx b/packages/lib/webhooks/integrationTemplate.tsx
deleted file mode 100644
index a461789cb9b..00000000000
--- a/packages/lib/webhooks/integrationTemplate.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-const supportedWebhookIntegrationList = ["https://discord.com/api/webhooks/"];
-
-type WebhookIntegrationProps = {
- url: string;
-};
-
-export const hasTemplateIntegration = (props: WebhookIntegrationProps) => {
- const ind = supportedWebhookIntegrationList.findIndex((integration) => {
- return props.url.includes(integration);
- });
- return ind > -1;
-};
-
-const customTemplate = (props: WebhookIntegrationProps) => {
- const ind = supportedWebhookIntegrationList.findIndex((integration) => {
- return props.url.includes(integration);
- });
- return integrationTemplate(supportedWebhookIntegrationList[ind]) || "";
-};
-
-const integrationTemplate = (webhookIntegration: string) => {
- switch (webhookIntegration) {
- case "https://discord.com/api/webhooks/":
- return '{"content": "An event has been scheduled/updated","embeds": [{"color": 2697513,"fields": [{"name": "Event Trigger","value": "{{triggerEvent}}"}, {"name": "What","value": "{{title}} ({{type}})"},{"name": "When","value": "Start: {{startTime}} \\n End: {{endTime}} \\n Timezone: ({{organizer.timeZone}})"},{"name": "Who","value": "Organizer: {{organizer.name}} ({{organizer.email}}) \\n Booker: {{attendees.0.name}} ({{attendees.0.email}})" },{"name":"Description", "value":": {{description}}"},{"name":"Where","value":": {{location}} "}]}]}';
- }
-};
-
-export default customTemplate;
diff --git a/packages/trpc/server/routers/viewer/bookings.tsx b/packages/trpc/server/routers/viewer/bookings.tsx
index ecb58766fa4..0bcff0ec013 100644
--- a/packages/trpc/server/routers/viewer/bookings.tsx
+++ b/packages/trpc/server/routers/viewer/bookings.tsx
@@ -16,10 +16,10 @@ import EventManager from "@calcom/core/EventManager";
import dayjs from "@calcom/dayjs";
import { sendDeclinedEmails, sendLocationChangeEmails, sendScheduledEmails } from "@calcom/emails";
import { scheduleWorkflowReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
+import getWebhooks from "@calcom/features/webhooks/utils/getWebhooks";
import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";
import logger from "@calcom/lib/logger";
import { getTranslation } from "@calcom/lib/server";
-import getSubscribers from "@calcom/lib/webhooks/subscriptions";
import { bookingConfirmPatchBodySchema } from "@calcom/prisma/zod-utils";
import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar";
@@ -485,7 +485,7 @@ export const bookingsRouter = createProtectedRouter()
triggerEvent: WebhookTriggerEvents.MEETING_ENDED,
};
- const subscribersMeetingEnded = await getSubscribers(subscriberOptionsMeetingEnded);
+ const subscribersMeetingEnded = await getWebhooks(subscriberOptionsMeetingEnded);
subscribersMeetingEnded.forEach((subscriber) => {
updatedBookings.forEach((booking) => {
diff --git a/packages/trpc/server/routers/viewer/webhook.tsx b/packages/trpc/server/routers/viewer/webhook.tsx
index 047baf8603d..8266e7adb4f 100644
--- a/packages/trpc/server/routers/viewer/webhook.tsx
+++ b/packages/trpc/server/routers/viewer/webhook.tsx
@@ -92,6 +92,26 @@ export const webhookRouter = createProtectedRouter()
});
},
})
+ .query("get", {
+ input: z.object({
+ webhookId: z.string().optional(),
+ }),
+ resolve({ ctx, input }) {
+ return ctx.prisma.webhook.findUniqueOrThrow({
+ where: {
+ id: input.webhookId,
+ },
+ select: {
+ id: true,
+ subscriberUrl: true,
+ payloadTemplate: true,
+ active: true,
+ eventTriggers: true,
+ secret: true,
+ },
+ });
+ },
+ })
.mutation("create", {
input: z.object({
subscriberUrl: z.string().url(),
diff --git a/packages/ui/v2/core/Meta.tsx b/packages/ui/v2/core/Meta.tsx
index 24eb384949d..f29056b2d50 100644
--- a/packages/ui/v2/core/Meta.tsx
+++ b/packages/ui/v2/core/Meta.tsx
@@ -6,11 +6,13 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
type MetaType = {
title: string;
description: string;
+ backButton?: boolean;
};
const initialMeta = {
title: "",
description: "",
+ backButton: false,
};
const MetaContext = createContext({
@@ -39,12 +41,12 @@ export function MetaProvider({ children }: { children: React.ReactNode }) {
* elsewhere (ie. on a Heading, Title, Subtitle, etc.)
* @example <Meta title="Password" description="Manage settings for your account passwords" />
*/
-export default function Meta({ title, description }: MetaType) {
+export default function Meta({ title, description, backButton }: MetaType) {
const { t } = useLocale();
const { setMeta, meta } = useMeta();
/* @TODO: maybe find a way to have this data on first render to prevent flicker */
if (meta.title !== title || meta.description !== description) {
- setMeta({ title, description });
+ setMeta({ title, description, backButton });
}
return (
diff --git a/packages/ui/v2/core/form/fields.tsx b/packages/ui/v2/core/form/fields.tsx
index 6a7efb6d73d..5d763d12833 100644
--- a/packages/ui/v2/core/form/fields.tsx
+++ b/packages/ui/v2/core/form/fields.tsx
@@ -160,6 +160,7 @@ type InputFieldProps = {
t?: (key: string) => string;
} & React.ComponentProps<typeof Input> & {
labelProps?: React.ComponentProps<typeof Label>;
+ labelClassName?: string;
};
const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function InputField(props, ref) {
@@ -170,6 +171,7 @@ const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function InputF
const {
label = t(name),
labelProps,
+ labelClassName,
/** Prevents displaying untranslated placeholder keys */
placeholder = t(name + "_placeholder") !== name + "_placeholder" ? t(name + "_placeholder") : "",
className,
@@ -191,7 +193,7 @@ const InputField = forwardRef<HTMLInputElement, InputFieldProps>(function InputF
<Label
htmlFor={id}
{...labelProps}
- className={classNames(labelSrOnly && "sr-only", props.error && "text-red-900")}>
+ className={classNames(labelClassName, labelSrOnly && "sr-only", props.error && "text-red-900")}>
{label}
</Label>
)}
diff --git a/packages/ui/v2/core/layouts/AdminLayout.tsx b/packages/ui/v2/core/layouts/AdminLayout.tsx
index 8c408c61fc3..bdc1babb43e 100644
--- a/packages/ui/v2/core/layouts/AdminLayout.tsx
+++ b/packages/ui/v2/core/layouts/AdminLayout.tsx
@@ -2,6 +2,7 @@ import { useSession } from "next-auth/react";
import { useRouter } from "next/router";
import React, { ComponentProps, useEffect } from "react";
+import ErrorBoundary from "../../../ErrorBoundary";
import Shell from "../Shell";
import SettingsLayout from "./SettingsLayout";
import { UserPermissionRole } from ".prisma/client";
@@ -23,7 +24,9 @@ export default function AdminLayout({
return (
<SettingsLayout {...rest}>
<div className="mx-auto flex max-w-4xl flex-row divide-y divide-gray-200 md:px-12">
- <div className="flex flex-1 [&>*]:flex-1">{children}</div>
+ <div className="flex flex-1 [&>*]:flex-1">
+ <ErrorBoundary>{children}</ErrorBoundary>
+ </div>
</div>
</SettingsLayout>
);
diff --git a/packages/ui/v2/core/layouts/SettingsLayout.tsx b/packages/ui/v2/core/layouts/SettingsLayout.tsx
index c479895d594..fe1b4fefed4 100644
--- a/packages/ui/v2/core/layouts/SettingsLayout.tsx
+++ b/packages/ui/v2/core/layouts/SettingsLayout.tsx
@@ -5,6 +5,7 @@ import { classNames } from "@calcom/lib";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import Button from "@calcom/ui/v2/core/Button";
+import ErrorBoundary from "../../../ErrorBoundary";
import { Icon } from "../../../Icon";
import { useMeta } from "../Meta";
import Shell from "../Shell";
@@ -52,8 +53,9 @@ const tabs: VerticalTabItemProps[] = [
children: [
//
{ name: "webhooks", href: "/settings/developer/webhooks" },
- { name: "api_keys", href: "/settings/developer/api_keys" },
- { name: "embeds", href: "/settings/developer/embeds" },
+ { name: "api_keys", href: "/settings/developer/api-keys" },
+ // TODO: Add profile level for embeds
+ // { name: "embeds", href: "/v2/settings/developer/embeds" },
],
},
{
@@ -155,7 +157,7 @@ export default function SettingsLayout({
<div className="flex flex-1 [&>*]:flex-1">
<div className="mx-auto max-w-4xl justify-center">
<ShellHeader />
- {children}
+ <ErrorBoundary>{children}</ErrorBoundary>
</div>
</div>
</Shell>
@@ -169,19 +171,26 @@ function ShellHeader() {
const { t, isLocaleReady } = useLocale();
return (
<header className="mx-auto block max-w-4xl justify-between pt-12 sm:flex sm:pt-8">
- <div className="mb-8 w-full border-b border-gray-200 pb-8">
- {meta.title && isLocaleReady ? (
- <h1 className="font-cal mb-1 text-xl font-bold capitalize tracking-wide text-black">
- {t(meta.title)}
- </h1>
- ) : (
- <div className="mb-1 h-6 w-24 animate-pulse rounded-md bg-gray-200" />
- )}
- {meta.description && isLocaleReady ? (
- <p className="text-sm text-gray-600 ltr:mr-4 rtl:ml-4">{t(meta.description)}</p>
- ) : (
- <div className="mb-1 h-6 w-32 animate-pulse rounded-md bg-gray-200" />
+ <div className="mb-8 flex w-full items-center border-b border-gray-200 pb-8">
+ {meta.backButton && (
+ <a href="javascript:history.back()">
+ <Icon.FiArrowLeft className="mr-7" />
+ </a>
)}
+ <div>
+ {meta.title && isLocaleReady ? (
+ <h1 className="font-cal mb-1 text-xl font-bold capitalize tracking-wide text-black">
+ {t(meta.title)}
+ </h1>
+ ) : (
+ <div className="mb-1 h-6 w-24 animate-pulse rounded-md bg-gray-200" />
+ )}
+ {meta.description && isLocaleReady ? (
+ <p className="text-sm text-gray-600 ltr:mr-4 rtl:ml-4">{t(meta.description)}</p>
+ ) : (
+ <div className="mb-1 h-6 w-32 animate-pulse rounded-md bg-gray-200" />
+ )}
+ </div>
</div>
</header>
);
diff --git a/packages/ui/v2/core/skeleton/index.tsx b/packages/ui/v2/core/skeleton/index.tsx
index f0fce379e4c..1a487d7e808 100644
--- a/packages/ui/v2/core/skeleton/index.tsx
+++ b/packages/ui/v2/core/skeleton/index.tsx
@@ -18,7 +18,7 @@ const SkeletonText: React.FC<SkeletonBaseProps> = ({ className = "" }) => {
return (
<span
className={classNames(
- `font-size-0 dark:white-300 animate-pulse rounded-md bg-gray-300 empty:before:inline-block empty:before:content-['']`,
+ `font-size-0 dark:white-300 inline-block animate-pulse rounded-md bg-gray-300 empty:before:inline-block empty:before:content-['']`,
className
)}
/>
diff --git a/packages/ui/v2/modules/List.tsx b/packages/ui/v2/modules/List.tsx
index 94cc0523b59..a928ef1a6c4 100644
--- a/packages/ui/v2/modules/List.tsx
+++ b/packages/ui/v2/modules/List.tsx
@@ -23,7 +23,7 @@ export function ListItem(props: ListItemProps) {
{
...passThroughProps,
className: classNames(
- "items-center rounded-md bg-white min-w-0 flex-1 flex border-neutral-200 p-2 sm:mx-0 sm:p-8 md:border md:p-4 xl:mt-0",
+ "items-center rounded-md bg-white min-w-0 flex-1 flex border-neutral-200 p-4 sm:mx-0 md:border md:p-4 xl:mt-0",
expanded ? "my-2 border" : "border -mb-px last:mb-0",
props.className,
(props.onClick || href) && "hover:bg-neutral-50"
diff --git a/packages/ui/v2/modules/_IMPORTANT_README/_IMPORTANT_README.md b/packages/ui/v2/modules/_IMPORTANT_README/_IMPORTANT_README.md
new file mode 100644
index 00000000000..f9a6f116906
--- /dev/null
+++ b/packages/ui/v2/modules/_IMPORTANT_README/_IMPORTANT_README.md
@@ -0,0 +1,7 @@
+# To all Cal.com contributors
+
+All these components should live in `packages/features`
+
+With love,
+
+zomars 💕