Skip to content

Scheduling infrastructure for absolutely everyone.

refactor: Break useCreateEventType hook into web-specific and platform-specific ones (#27522)

Benny Joo249065851b95
diff --git a/apps/web/modules/event-types/components/CreateEventTypeDialog.tsx b/apps/web/modules/event-types/components/CreateEventTypeDialog.tsx
index 9af51bf556d..f95f93ea1c1 100644
--- a/apps/web/modules/event-types/components/CreateEventTypeDialog.tsx
+++ b/apps/web/modules/event-types/components/CreateEventTypeDialog.tsx
@@ -5,7 +5,7 @@ import { z } from "zod";
import { Dialog } from "@calcom/features/components/controlled-dialog";
import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";
import CreateEventTypeForm from "@calcom/features/eventtypes/components/CreateEventTypeForm";
-import { useCreateEventType } from "@calcom/features/eventtypes/hooks/useCreateEventType";
+import { useCreateEventType } from "~/event-types/hooks/useCreateEventType";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useTypedQuery } from "@calcom/lib/hooks/useTypedQuery";
import type { EventType } from "@calcom/prisma/client";
diff --git a/packages/features/eventtypes/hooks/useCreateEventType.ts b/apps/web/modules/event-types/hooks/useCreateEventType.ts
similarity index 63%
rename from packages/features/eventtypes/hooks/useCreateEventType.ts
rename to apps/web/modules/event-types/hooks/useCreateEventType.ts
index 2203b14191f..ba77953bb4e 100644
--- a/packages/features/eventtypes/hooks/useCreateEventType.ts
+++ b/apps/web/modules/event-types/hooks/useCreateEventType.ts
@@ -1,6 +1,4 @@
-import { zodResolver } from "@hookform/resolvers/zod";
-import { useEffect, useState } from "react";
-import { useForm } from "react-hook-form";
+import { useState } from "react";
import type { z } from "zod";
import { createEventTypeInput } from "@calcom/features/eventtypes/lib/types";
@@ -8,33 +6,8 @@ import { useDebounce } from "@calcom/lib/hooks/useDebounce";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { HttpError } from "@calcom/lib/http-error";
import type { EventType } from "@calcom/prisma/client";
-import { SchedulingType } from "@calcom/prisma/enums";
-import { unlockedManagedEventTypeProps } from "@calcom/prisma/zod-utils";
import { trpc } from "@calcom/trpc/react";
-
-export type CreateEventTypeFormValues = z.infer<typeof createEventTypeInput>;
-
-export const useCreateEventTypeForm = () => {
- const form = useForm<CreateEventTypeFormValues>({
- defaultValues: {
- length: 15,
- },
- resolver: zodResolver(createEventTypeInput),
- });
-
- const schedulingTypeWatch = form.watch("schedulingType");
- const isManagedEventType = schedulingTypeWatch === SchedulingType.MANAGED;
-
- useEffect(() => {
- if (isManagedEventType) {
- form.setValue("metadata.managedEventConfig.unlockedFields", unlockedManagedEventTypeProps);
- } else {
- form.setValue("metadata", null);
- }
- }, [schedulingTypeWatch]);
-
- return { form, isManagedEventType };
-};
+import { useCreateEventTypeForm } from "@calcom/atoms/hooks/event-types/private/useCreateEventTypeForm";
export const useCreateEventType = (
onSuccessMutation: (eventType: EventType) => void,
diff --git a/apps/web/modules/settings/teams/[id]/event-types-view.tsx b/apps/web/modules/settings/teams/[id]/event-types-view.tsx
index 7fba0c2c409..a5a56234acf 100644
--- a/apps/web/modules/settings/teams/[id]/event-types-view.tsx
+++ b/apps/web/modules/settings/teams/[id]/event-types-view.tsx
@@ -3,7 +3,7 @@
import { useRouter } from "next/navigation";
import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";
-import { useCreateEventType } from "@calcom/features/eventtypes/hooks/useCreateEventType";
+import { useCreateEventType } from "~/event-types/hooks/useCreateEventType";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
diff --git a/packages/features/ee/teams/components/TeamEventTypeForm.tsx b/packages/features/ee/teams/components/TeamEventTypeForm.tsx
index 38247e0df51..5499f1f6d65 100644
--- a/packages/features/ee/teams/components/TeamEventTypeForm.tsx
+++ b/packages/features/ee/teams/components/TeamEventTypeForm.tsx
@@ -2,7 +2,6 @@ import type { ReactNode } from "react";
import type { UseFormReturn } from "react-hook-form";
import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
-import type { CreateEventTypeFormValues } from "@calcom/features/eventtypes/hooks/useCreateEventType";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import slugify from "@calcom/lib/slugify";
import { SchedulingType } from "@calcom/prisma/enums";
@@ -12,6 +11,10 @@ import { Form } from "@calcom/ui/components/form";
import { TextField } from "@calcom/ui/components/form";
import { RadioAreaGroup as RadioArea } from "@calcom/ui/components/radio";
import { Tooltip } from "@calcom/ui/components/tooltip";
+import type { z } from "zod";
+import { createEventTypeInput } from "@calcom/features/eventtypes/lib/types";
+
+type CreateEventTypeFormValues = z.infer<typeof createEventTypeInput>;
type props = {
permissions: {
diff --git a/packages/features/eventtypes/components/CreateEventTypeForm.tsx b/packages/features/eventtypes/components/CreateEventTypeForm.tsx
index 102013470e2..3691163ce73 100644
--- a/packages/features/eventtypes/components/CreateEventTypeForm.tsx
+++ b/packages/features/eventtypes/components/CreateEventTypeForm.tsx
@@ -3,7 +3,6 @@ import { useState } from "react";
import type { UseFormReturn } from "react-hook-form";
import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
-import type { CreateEventTypeFormValues } from "@calcom/features/eventtypes/hooks/useCreateEventType";
import { MAX_EVENT_DURATION_MINUTES, MIN_EVENT_DURATION_MINUTES } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { md } from "@calcom/lib/markdownIt";
@@ -14,6 +13,10 @@ import { Form } from "@calcom/ui/components/form";
import { TextAreaField } from "@calcom/ui/components/form";
import { TextField } from "@calcom/ui/components/form";
import { Tooltip } from "@calcom/ui/components/tooltip";
+import type { z } from "zod";
+import { createEventTypeInput } from "@calcom/features/eventtypes/lib/types";
+
+type CreateEventTypeFormValues = z.infer<typeof createEventTypeInput>;
export default function CreateEventTypeForm({
form,
diff --git a/packages/platform/atoms/event-types/wrappers/CreateEventTypePlatformWrapper.tsx b/packages/platform/atoms/event-types/wrappers/CreateEventTypePlatformWrapper.tsx
index 9ff8e428279..29d735238a4 100644
--- a/packages/platform/atoms/event-types/wrappers/CreateEventTypePlatformWrapper.tsx
+++ b/packages/platform/atoms/event-types/wrappers/CreateEventTypePlatformWrapper.tsx
@@ -1,12 +1,12 @@
import { AtomsWrapper } from "@/components/atoms-wrapper";
import CreateEventTypeForm from "@calcom/features/eventtypes/components/CreateEventTypeForm";
-import { useCreateEventTypeForm } from "@calcom/features/eventtypes/hooks/useCreateEventType";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import type { EventType } from "@calcom/prisma/client";
import { Button } from "@calcom/ui/components/button";
import { TeamEventTypeForm } from "@calcom/features/ee/teams/components/TeamEventTypeForm";
+import { useCreateEventTypeForm } from "../../hooks/event-types/private/useCreateEventTypeForm";
import { useCreateEventType } from "../../hooks/event-types/private/useCreateEventType";
import { useCreateTeamEventType } from "../../hooks/event-types/private/useCreateTeamEventType";
import { useTeams } from "../../hooks/teams/useTeams";
diff --git a/packages/platform/atoms/hooks/event-types/private/useCreateEventTypeForm.ts b/packages/platform/atoms/hooks/event-types/private/useCreateEventTypeForm.ts
new file mode 100644
index 00000000000..b96d60b773c
--- /dev/null
+++ b/packages/platform/atoms/hooks/event-types/private/useCreateEventTypeForm.ts
@@ -0,0 +1,32 @@
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useEffect } from "react";
+import { useForm } from "react-hook-form";
+import type { z } from "zod";
+
+import { createEventTypeInput } from "@calcom/features/eventtypes/lib/types";
+import { SchedulingType } from "@calcom/prisma/enums";
+import { unlockedManagedEventTypeProps } from "@calcom/prisma/zod-utils";
+
+export type CreateEventTypeFormValues = z.infer<typeof createEventTypeInput>;
+
+export const useCreateEventTypeForm = () => {
+ const form = useForm<CreateEventTypeFormValues>({
+ defaultValues: {
+ length: 15,
+ },
+ resolver: zodResolver(createEventTypeInput),
+ });
+
+ const schedulingTypeWatch = form.watch("schedulingType");
+ const isManagedEventType = schedulingTypeWatch === SchedulingType.MANAGED;
+
+ useEffect(() => {
+ if (isManagedEventType) {
+ form.setValue("metadata.managedEventConfig.unlockedFields", unlockedManagedEventTypeProps);
+ } else {
+ form.setValue("metadata", null);
+ }
+ }, [schedulingTypeWatch]);
+
+ return { form, isManagedEventType };
+};
\ No newline at end of file
diff --git a/packages/platform/atoms/package.json b/packages/platform/atoms/package.json
index 6dbd8dba716..8055cfa4ff5 100644
--- a/packages/platform/atoms/package.json
+++ b/packages/platform/atoms/package.json
@@ -69,6 +69,7 @@
"./hooks/useIsPlatform": "./hooks/useIsPlatform.ts",
"./hooks/useIsPlatformBookerEmbed": "./hooks/useIsPlatformBookerEmbed.ts",
"./hooks/event-types/private/useEventTypeById": "./hooks/event-types/private/useEventTypeById.ts",
+ "./hooks/event-types/private/useCreateEventTypeForm": "./hooks/event-types/private/useCreateEventTypeForm.ts",
"./event-types/hooks/useEventTypeForm": "./event-types/hooks/useEventTypeForm.ts",
"./event-types/hooks/useHandleRouteChange": "./event-types/hooks/useHandleRouteChange.ts",
"./event-types/hooks/useTabsNavigations": "./event-types/hooks/useTabsNavigations.tsx",