feat: add duplicate functionality for managed event types (#26792)

* feat: add duplicate functionality for managed event types

Co-Authored-By: [email protected] <[email protected]>

* feat: add disclaimer and redirect for managed event type duplication

- Add info alert disclaimer in duplicate modal for managed event types
- Pass schedulingType to duplicate dialog via query params
- Redirect to assignment tab after duplicating managed event types
- Add translation key for managed event type duplicate disclaimer

Co-Authored-By: [email protected] <[email protected]>

* test: add tests for managed event type duplication

Co-Authored-By: [email protected] <[email protected]>

* refactor: replace PrismaMock unit test with Prisma integration test for duplicate handler (#27973)

* refactor: replace PrismaMock unit test with Prisma integration test for duplicate handler

Co-Authored-By: [email protected] <[email protected]>

* fix: re-throw TRPCErrors in duplicate handler catch block and assert specific error codes in tests

Co-Authored-By: [email protected] <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Syed Ali Shahbaz <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-02-18 16:49:23 +04:00
1 parent 8908a66c23
commit eef47ddefd
5 files changed
+322 -24

No files matched your search

@@ -15,6 +15,8 @@ import { md } from "@calcom/lib/markdownIt";
import slugify from "@calcom/lib/slugify";
import turndown from "@calcom/lib/turndownService";
import { trpc } from "@calcom/trpc/react";
import { SchedulingType } from "@calcom/prisma/enums";
import { Alert } from "@calcom/ui/components/alert";
import { Button } from "@calcom/ui/components/button";
import { DialogContent, DialogFooter, DialogClose } from "@calcom/ui/components/dialog";
import { Editor } from "@calcom/ui/components/editor";
@@ -32,6 +34,7 @@ const querySchema = z.object({
pageSlug: z.string(),
teamId: z.coerce.number().optional().nullable(),
parentId: z.coerce.number().optional().nullable(),
schedulingType: z.nativeEnum(SchedulingType).optional().nullable(),
});
const DuplicateDialog = () => {
@@ -42,8 +45,9 @@ const DuplicateDialog = () => {
const router = useRouter();
const [firstRender, setFirstRender] = useState(true);
const {
data: { pageSlug, slug, ...defaultValues },
data: { pageSlug, slug, schedulingType, ...defaultValues },
} = useTypedQuery(querySchema);
const isManagedEventType = schedulingType === SchedulingType.MANAGED;
const [searchTerm, setSearchTerm] = useState("");
const debouncedSearchTerm = useDebounce(searchTerm, 500);
@@ -72,7 +76,11 @@ const DuplicateDialog = () => {
const duplicateMutation = trpc.viewer.eventTypesHeavy.duplicate.useMutation({
onSuccess: async ({ eventType }) => {
await router.replace(`/event-types/${eventType.id}`);
// For managed event types, redirect to the assignment tab so the user can add members
const redirectUrl = isManagedEventType
? `/event-types/${eventType.id}?tabName=team`
: `/event-types/${eventType.id}`;
await router.replace(redirectUrl);
await utils.viewer.eventTypes.getUserEventGroups.invalidate();
revalidateEventTypesList();
@@ -117,7 +125,7 @@ const DuplicateDialog = () => {
return (
<Dialog
name="duplicate"
clearQueryParamsOnClose={["description", "title", "length", "slug", "name", "id", "pageSlug"]}>
clearQueryParamsOnClose={["description", "title", "length", "slug", "name", "id", "pageSlug", "schedulingType"]}>
<DialogContent type="creation" className="overflow-y-auto" title={t("duplicate_event_type")}>
<Form
form={form}
@@ -125,6 +133,12 @@ const DuplicateDialog = () => {
duplicateMutation.mutate(values);
}}>
<div className="-mt-2 stack-y-5">
{isManagedEventType && (
<Alert
severity="info"
message={t("managed_event_type_duplicate_disclaimer")}
/>
)}
<TextField
label={t("title")}
placeholder={t("quick_chat")}
@@ -432,14 +432,15 @@ export const InfiniteEventTypeList = ({
if (value) newSearchParams.set(key, value.toString());
if (value === null) newSearchParams.delete(key);
}
setParamsIfDefined("dialog", "duplicate");
setParamsIfDefined("title", eventType.title);
setParamsIfDefined("description", eventType.description);
setParamsIfDefined("slug", eventType.slug);
setParamsIfDefined("id", eventType.id);
setParamsIfDefined("length", eventType.length);
setParamsIfDefined("pageSlug", group.profile.slug);
router.push(`${pathname}?${newSearchParams.toString()}`);
setParamsIfDefined("dialog", "duplicate");
setParamsIfDefined("title", eventType.title);
setParamsIfDefined("description", eventType.description);
setParamsIfDefined("slug", eventType.slug);
setParamsIfDefined("id", eventType.id);
setParamsIfDefined("length", eventType.length);
setParamsIfDefined("pageSlug", group.profile.slug);
setParamsIfDefined("schedulingType", eventType.schedulingType);
router.push(`${pathname}?${newSearchParams.toString()}`);
};
const deleteMutation = trpc.viewer.eventTypes.delete.useMutation({
@@ -695,18 +696,16 @@ export const InfiniteEventTypeList = ({
</DropdownMenuItem>
)}
{/* readonly is only set when we are on a team - if we are on a user event type null will be the value. */}
{!readOnly && !isManagedEventType && !isChildrenManagedEventType && (
<>
<DropdownMenuItem className="outline-none">
<DropdownItem
type="button"
data-testid={`event-type-duplicate-${type.id}`}
StartIcon="copy"
onClick={() => openDuplicateModal(type, group)}>
{t("duplicate")}
</DropdownItem>
</DropdownMenuItem>
</>
{!readOnly && !isChildrenManagedEventType && (
<DropdownMenuItem className="outline-none">
<DropdownItem
type="button"
data-testid={`event-type-duplicate-${type.id}`}
StartIcon="copy"
onClick={() => openDuplicateModal(type, group)}>
{t("duplicate")}
</DropdownItem>
</DropdownMenuItem>
)}
{!isManagedEventType && (
<DropdownMenuItem className="outline-none">
@@ -812,7 +811,7 @@ export const InfiniteEventTypeList = ({
</DropdownItem>
</DropdownMenuItem>
)}
{!readOnly && !isManagedEventType && !isChildrenManagedEventType && (
{!readOnly && !isChildrenManagedEventType && (
<DropdownMenuItem className="outline-none">
<DropdownItem
onClick={() => openDuplicateModal(type, group)}
@@ -228,6 +228,7 @@
"time_left": "Time left",
"event_type": "Event type",
"duplicate_event_type": "Duplicate event type",
"managed_event_type_duplicate_disclaimer": "User assignments are not copied when duplicating a managed event type. You will need to add team members manually after duplication.",
"enter_meeting": "Enter meeting",
"video_call_provider": "Video call provider",
"meeting_id": "Meeting ID",