From 7d497a621f802dfd623ba3294f043283024b4fbe Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Thu, 7 Mar 2024 22:04:42 +0530 Subject: [PATCH] fix: duplicate event types (#14007) * fix: duplicate event types * test: add test for duplicate event type * fix: type error * chore: pass error message --------- Co-authored-by: Erik --- .../components/eventtype/EventAdvancedTab.tsx | 2 +- apps/web/playwright/event-types.e2e.ts | 4 +++ apps/web/public/static/locales/en/common.json | 3 ++- .../eventtypes/components/DuplicateDialog.tsx | 4 +-- .../viewer/eventTypes/duplicate.handler.ts | 25 ++++++++++++++++--- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/apps/web/components/eventtype/EventAdvancedTab.tsx b/apps/web/components/eventtype/EventAdvancedTab.tsx index 5795d3a426..d47609bdac 100644 --- a/apps/web/components/eventtype/EventAdvancedTab.tsx +++ b/apps/web/components/eventtype/EventAdvancedTab.tsx @@ -217,7 +217,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick - Default {user?.email || ""} + {t("default")} {user?.email || ""} ) } diff --git a/apps/web/playwright/event-types.e2e.ts b/apps/web/playwright/event-types.e2e.ts index 4cf45c0ab1..9bfba641d2 100644 --- a/apps/web/playwright/event-types.e2e.ts +++ b/apps/web/playwright/event-types.e2e.ts @@ -107,6 +107,10 @@ testBothFutureAndLegacyRoutes.describe("Event Types tests", () => { expect(formTitle).toBe(firstTitle); expect(formSlug).toContain(firstSlug); + + const test = await page.getByTestId("continue").click(); + const toast = await page.waitForSelector('[data-testid="toast-success"]'); + expect(toast).toBeTruthy(); }); test("edit first event", async ({ page }) => { diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 97ecac1992..8c80360c75 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -131,6 +131,7 @@ "invitee_timezone": "Invitee Time Zone", "time_left": "Time left", "event_type": "Event Type", + "duplicate_event_type":"Duplicate Event Type", "enter_meeting": "Enter Meeting", "video_call_provider": "Video call provider", "meeting_id": "Meeting ID", @@ -2295,4 +2296,4 @@ "confirm_email_description": "We sent an email to {{email}}. Click the link in the email to verify this address.", "send_event_details_to": "Send event details to", "ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑" -} \ No newline at end of file +} diff --git a/packages/features/eventtypes/components/DuplicateDialog.tsx b/packages/features/eventtypes/components/DuplicateDialog.tsx index 84aa3d2f2f..8fdbe5b071 100644 --- a/packages/features/eventtypes/components/DuplicateDialog.tsx +++ b/packages/features/eventtypes/components/DuplicateDialog.tsx @@ -95,7 +95,7 @@ const DuplicateDialog = () => { - +
{ @@ -161,7 +161,7 @@ const DuplicateDialog = () => { - diff --git a/packages/trpc/server/routers/viewer/eventTypes/duplicate.handler.ts b/packages/trpc/server/routers/viewer/eventTypes/duplicate.handler.ts index bd14bb213a..7710ef215e 100644 --- a/packages/trpc/server/routers/viewer/eventTypes/duplicate.handler.ts +++ b/packages/trpc/server/routers/viewer/eventTypes/duplicate.handler.ts @@ -86,17 +86,18 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/ban-ts-comment // @ts-ignore - descriptionAsSafeHTML is added on the fly using a prisma middleware it shouldn't be used to create event type. Such a property doesn't exist on schema descriptionAsSafeHTML: _descriptionAsSafeHTML, + secondaryEmailId, ...rest } = eventType; - const data: Prisma.EventTypeUncheckedCreateInput = { + const data: Prisma.EventTypeCreateInput = { ...rest, title: newEventTitle, slug: newSlug, description: newDescription, length: newLength, locations: locations ?? undefined, - teamId: team ? team.id : undefined, + team: team ? { connect: { id: team.id } } : undefined, users: users ? { connect: users.map((user) => ({ id: user.id })) } : undefined, recurringEvent: recurringEvent || undefined, bookingLimits: bookingLimits ?? undefined, @@ -105,6 +106,24 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => { bookingFields: eventType.bookingFields === null ? Prisma.DbNull : eventType.bookingFields, }; + // Validate the secondary email + if (!!secondaryEmailId) { + const secondaryEmail = await prisma.secondaryEmail.findUnique({ + where: { + id: secondaryEmailId, + userId: ctx.user.id, + }, + }); + // Make sure the secondary email id belongs to the current user and its a verified one + if (secondaryEmail && secondaryEmail.emailVerified) { + data.secondaryEmail = { + connect: { + id: secondaryEmailId, + }, + }; + } + } + const newEventType = await EventTypeRepository.create(data); // Create custom inputs @@ -156,6 +175,6 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => { eventType: newEventType, }; } catch (error) { - throw new TRPCError({ code: "INTERNAL_SERVER_ERROR" }); + throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: `Error duplicating event type ${error}` }); } };