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

* migrate useCreateEventType hook to web

* fix

* fix

* fix import
This commit is contained in:
Benny Joo authored and GitHub committed 2026-02-05 15:06:05 +05:30
1 parent cf55b5b462
commit 249065851b
8 files changed
+46 -34

No files matched your search

@@ -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";
@@ -0,0 +1,52 @@
import { useState } from "react";
import type { z } from "zod";
import { createEventTypeInput } from "@calcom/features/eventtypes/lib/types";
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 { trpc } from "@calcom/trpc/react";
import { useCreateEventTypeForm } from "@calcom/atoms/hooks/event-types/private/useCreateEventTypeForm";
export const useCreateEventType = (
onSuccessMutation: (eventType: EventType) => void,
onErrorMutation: (message: string) => void
) => {
const utils = trpc.useUtils();
const { t } = useLocale();
const { form, isManagedEventType } = useCreateEventTypeForm();
const [searchTerm, setSearchTerm] = useState("");
const debouncedSearchTerm = useDebounce(searchTerm, 500);
const createMutation = trpc.viewer.eventTypesHeavy.create.useMutation({
onSuccess: async ({ eventType }) => {
onSuccessMutation(eventType);
await utils.viewer.eventTypes.getEventTypesFromGroup.fetchInfinite({
group: { teamId: eventType.teamId, parentId: eventType.parentId },
searchQuery: debouncedSearchTerm,
limit: 10,
});
form.reset();
},
onError: (err) => {
let error = err.message;
if (err instanceof HttpError) {
error = `${err.statusCode}: ${err.message}`;
}
if (err.data?.code === "BAD_REQUEST") {
error = `${err.data.code}: ${t("error_event_type_url_duplicate")}`;
}
if (err.data?.code === "UNAUTHORIZED") {
error = `${err.data.code}: ${t("error_event_type_unauthorized_create")}`;
}
onErrorMutation(error);
},
});
return { form, createMutation, isManagedEventType };
};
@@ -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";