diff --git a/apps/web/components/eventtype/RecurringEventController.tsx b/apps/web/components/eventtype/RecurringEventController.tsx deleted file mode 100644 index 1522d9f388..0000000000 --- a/apps/web/components/eventtype/RecurringEventController.tsx +++ /dev/null @@ -1,145 +0,0 @@ -import type { FormValues } from "pages/event-types/[type]"; -import { useState } from "react"; -import { UseFormReturn } from "react-hook-form"; - -import { useLocale } from "@calcom/lib/hooks/useLocale"; -import { Frequency } from "@calcom/prisma/zod-utils"; -import type { RecurringEvent } from "@calcom/types/Calendar"; -import { Alert } from "@calcom/ui/Alert"; - -import Select from "@components/ui/form/Select"; - -type RecurringEventControllerProps = { - recurringEvent: RecurringEvent | null; - formMethods: UseFormReturn; - paymentEnabled: boolean; - onRecurringEventDefined: (value: boolean) => void; -}; - -/** - * @deprecated - * use component from `/apps/web/components/v2/eventtype/RecurringEventController` instead - **/ -export default function RecurringEventController({ - recurringEvent, - formMethods, - paymentEnabled, - onRecurringEventDefined, -}: RecurringEventControllerProps) { - const { t } = useLocale(); - const [recurringEventState, setRecurringEventState] = useState(recurringEvent); - - /* Just yearly-0, monthly-1 and weekly-2 */ - const recurringEventFreqOptions = Object.entries(Frequency) - .filter(([key, value]) => isNaN(Number(key)) && Number(value) < 3) - .map(([key, value]) => ({ - label: t(`${key.toString().toLowerCase()}`, { count: recurringEventState?.interval }), - value: value.toString(), - })); - - return ( -
-
- {t("recurring_event")} -
-
- {paymentEnabled ? ( - - ) : ( - <> -
-
- { - onRecurringEventDefined(event?.target.checked); - if (!event?.target.checked) { - formMethods.setValue("recurringEvent", null); - setRecurringEventState(null); - } else { - const newVal = recurringEvent || { - interval: 1, - count: 12, - freq: Frequency.WEEKLY, - }; - formMethods.setValue("recurringEvent", newVal); - setRecurringEventState(newVal); - } - }} - type="checkbox" - className="text-primary-600 h-4 w-4 rounded border-gray-300" - defaultChecked={recurringEventState !== null} - data-testid="recurring-event-check" - id="recurringEvent" - /> -
-
- -
-
- {recurringEventState && ( -
-
-

{t("repeats_every")}

- { - const newVal = { - ...recurringEventState, - interval: parseInt(event?.target.value), - }; - formMethods.setValue("recurringEvent", newVal); - setRecurringEventState(newVal); - }} - /> - { - const newVal = { - ...recurringEventState, - count: parseInt(event?.target.value), - }; - formMethods.setValue("recurringEvent", newVal); - setRecurringEventState(newVal); - }} - /> -

- {t("occurrence", { - count: recurringEventState.count, - })} -

-
-
- )} - - )} -
-
- ); -} diff --git a/apps/web/components/v2/eventtype/RecurringEventController.tsx b/apps/web/components/v2/eventtype/RecurringEventController.tsx index 03a1f51e0a..4ff446aa87 100644 --- a/apps/web/components/v2/eventtype/RecurringEventController.tsx +++ b/apps/web/components/v2/eventtype/RecurringEventController.tsx @@ -1,4 +1,4 @@ -import type { FormValues } from "pages/event-types/[type]"; +import type { FormValues } from "pages/v2/event-types/[type]"; import { useState } from "react"; import { useFormContext } from "react-hook-form"; diff --git a/apps/web/components/webhook/WebhookDialogForm.tsx b/apps/web/components/webhook/WebhookDialogForm.tsx deleted file mode 100644 index 6a803f94c4..0000000000 --- a/apps/web/components/webhook/WebhookDialogForm.tsx +++ /dev/null @@ -1,245 +0,0 @@ -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"; -import Button from "@calcom/ui/Button"; -import { DialogFooter } from "@calcom/ui/Dialog"; -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 { 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; - app?: string; - handleClose: () => void; - webhooks: Webhook[]; -}) { - const { t } = useLocale(); - const utils = trpc.useContext(); - const appId = props.app; - const webhooks = props.webhooks; - - const triggers = !appId - ? WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP["core"] - : WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP[appId as keyof typeof WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP]; - const { - defaultValues = { - id: "", - eventTriggers: triggers, - subscriberUrl: "", - active: true, - payloadTemplate: null, - secret: null, - } as Omit, - } = props; - - const [useCustomPayloadTemplate, setUseCustomPayloadTemplate] = useState(!!defaultValues.payloadTemplate); - const [changeSecret, setChangeSecret] = useState(false); - const [newSecret, setNewSecret] = useState(""); - const hasSecretKey = !!defaultValues.secret; - const currentSecret = defaultValues.secret; - - const subscriberUrlReserved = (subscriberUrl: string, id: string): boolean => { - return !!webhooks.find((webhook) => webhook.subscriberUrl === subscriberUrl && webhook.id !== id); - }; - - const form = useForm({ - defaultValues, - }); - - const handleInput = (event: React.FormEvent) => { - setNewSecret(event.currentTarget.value); - }; - - useEffect(() => { - if (changeSecret) { - form.unregister("secret", { keepDefaultValue: false }); - } - }, [changeSecret]); - - return ( -
{ - if (subscriberUrlReserved(event.subscriberUrl, event.id)) { - showToast(t("webhook_subscriber_url_reserved"), "error"); - return; - } - const e = changeSecret - ? { ...event, eventTypeId: props.eventTypeId, appId } - : { ...event, secret: currentSecret, eventTypeId: props.eventTypeId, appId }; - if (!useCustomPayloadTemplate && event.payloadTemplate) { - event.payloadTemplate = null; - } - if (event.id) { - await utils.client.mutation("viewer.webhook.edit", e); - await utils.invalidateQueries(["viewer.webhook.list"]); - showToast(t("webhook_updated_successfully"), "success"); - } else { - await utils.client.mutation("viewer.webhook.create", e); - await utils.invalidateQueries(["viewer.webhook.list"]); - showToast(t("webhook_created_successfully"), "success"); - } - props.handleClose(); - }} - className="space-y-4"> -
- -
-
- - ( - { - form.setValue("active", isChecked); - }} - /> - )} - /> - -
-
- { - form.setValue("subscriberUrl", e.target.value); - if (hasTemplateIntegration({ url: e.target.value })) { - setUseCustomPayloadTemplate(true); - form.setValue("payloadTemplate", customTemplate({ url: e.target.value })); - } - }} - /> -
-
- {t("event_triggers")} - - {triggers.map((key) => ( - ( - { - const value = field.value; - const newValue = isChecked ? [...value, key] : value.filter((v) => v !== key); - - form.setValue("eventTriggers", newValue, { - shouldDirty: true, - }); - }} - /> - )} - /> - ))} - -
-
- {!!hasSecretKey && !changeSecret && ( - <> - {t("secret")} -
- {t("forgotten_secret_description")} -
- - - )} - {!!hasSecretKey && changeSecret && ( - <> - - - - )} - {!hasSecretKey && ( - - )} -
-
- {t("payload_template")} -
- - -
- {useCustomPayloadTemplate && ( -