diff --git a/apps/web/pages/event-types/[type]/index.tsx b/apps/web/pages/event-types/[type]/index.tsx index 62725e7a71..0c463d032a 100644 --- a/apps/web/pages/event-types/[type]/index.tsx +++ b/apps/web/pages/event-types/[type]/index.tsx @@ -168,18 +168,14 @@ const EventTypePage = (props: EventTypeSetupProps) => { } if (err.data?.code === "UNAUTHORIZED") { - message = `${err.data.code}: You are not able to update this event`; + message = `${err.data.code}: ${t("error_event_type_unauthorized_update")}`; } if (err.data?.code === "PARSE_ERROR" || err.data?.code === "BAD_REQUEST") { - message = `${err.data.code}: ${err.message}`; + message = `${err.data.code}: ${t(err.message)}`; } - if (message) { - showToast(message, "error"); - } else { - showToast(err.message, "error"); - } + showToast(message ? t(message) : t(err.message), "error"); }, }); diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index df649dfdcb..39cb740911 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -339,6 +339,11 @@ "cancelling_event_recurring": "The event is one instance of a recurring event.", "cancelling_all_recurring": "These are all remaining instances in the recurring event.", "error_with_status_code_occured": "An error with status code {{status}} occurred.", + "error_event_type_url_duplicate": "An event type with this URL already exists.", + "error_event_type_unauthorized_create": "You are not able to create this event", + "error_event_type_unauthorized_update": "You are not able to edit this event", + "error_workflow_unauthorized_create": "You are not able to create this workflow", + "error_schedule_unauthorized_create": "You are not able to create this schedule", "booking_already_cancelled": "This booking was already canceled", "booking_already_accepted_rejected": "This booking was already accepted or rejected", "go_back_home": "Go back home", diff --git a/packages/features/ee/workflows/components/EventWorkflowsTab.tsx b/packages/features/ee/workflows/components/EventWorkflowsTab.tsx index 064d5ae93d..89a32c68b9 100644 --- a/packages/features/ee/workflows/components/EventWorkflowsTab.tsx +++ b/packages/features/ee/workflows/components/EventWorkflowsTab.tsx @@ -226,7 +226,7 @@ function EventWorkflowsTab(props: Props) { } if (err.data?.code === "UNAUTHORIZED") { - const message = `${err.data.code}: You are not able to create this workflow`; + const message = `${err.data.code}: ${t("error_workflow_unauthorized_create")}`; showToast(message, "error"); } }, diff --git a/packages/features/ee/workflows/pages/index.tsx b/packages/features/ee/workflows/pages/index.tsx index 24ecea6050..2331e1d52a 100644 --- a/packages/features/ee/workflows/pages/index.tsx +++ b/packages/features/ee/workflows/pages/index.tsx @@ -40,7 +40,7 @@ function WorkflowsPage() { } if (err.data?.code === "UNAUTHORIZED") { - const message = `${err.data.code}: You are not able to create this workflow`; + const message = `${err.data.code}: ${t("error_workflow_unauthorized_create")}`; showToast(message, "error"); } }, diff --git a/packages/features/eventtypes/components/CreateEventTypeDialog.tsx b/packages/features/eventtypes/components/CreateEventTypeDialog.tsx index 13d1f9be63..c687ed9f37 100644 --- a/packages/features/eventtypes/components/CreateEventTypeDialog.tsx +++ b/packages/features/eventtypes/components/CreateEventTypeDialog.tsx @@ -127,12 +127,12 @@ export default function CreateEventTypeDialog({ } if (err.data?.code === "BAD_REQUEST") { - const message = `${err.data.code}: URL already exists.`; + const message = `${err.data.code}: ${t("error_event_type_url_duplicate")}`; showToast(message, "error"); } if (err.data?.code === "UNAUTHORIZED") { - const message = `${err.data.code}: You are not able to create this event`; + const message = `${err.data.code}: ${t("error_event_type_unauthorized_create")}`; showToast(message, "error"); } }, diff --git a/packages/features/eventtypes/components/DuplicateDialog.tsx b/packages/features/eventtypes/components/DuplicateDialog.tsx index 57ec7a9e8f..debed3ff35 100644 --- a/packages/features/eventtypes/components/DuplicateDialog.tsx +++ b/packages/features/eventtypes/components/DuplicateDialog.tsx @@ -65,7 +65,7 @@ const DuplicateDialog = () => { } if (err.data?.code === "UNAUTHORIZED" || err.data?.code === "FORBIDDEN") { - const message = `${err.data.code}: You are not able to create this event`; + const message = `${err.data.code}: ${t("error_event_type_unauthorized_create")}`; showToast(message, "error"); } }, diff --git a/packages/features/schedules/components/NewScheduleButton.tsx b/packages/features/schedules/components/NewScheduleButton.tsx index bd52102758..f223b80235 100644 --- a/packages/features/schedules/components/NewScheduleButton.tsx +++ b/packages/features/schedules/components/NewScheduleButton.tsx @@ -56,7 +56,7 @@ export function NewScheduleButton({ } if (err.data?.code === "UNAUTHORIZED") { - const message = `${err.data.code}: You are not able to create this event`; + const message = `${err.data.code}: ${t("error_schedule_unauthorized_create")}`; showToast(message, "error"); } }, diff --git a/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts b/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts index b86cb4da03..98e8ad2268 100644 --- a/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts +++ b/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts @@ -298,10 +298,27 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => { }); } } - const updatedEventType = await ctx.prisma.eventType.update({ - where: { id }, - data, + + const updatedEventTypeSelect = Prisma.validator()({ + slug: true, + schedulingType: true, }); + let updatedEventType: Prisma.EventTypeGetPayload<{ select: typeof updatedEventTypeSelect }>; + try { + updatedEventType = await ctx.prisma.eventType.update({ + where: { id }, + data, + select: updatedEventTypeSelect, + }); + } catch (e) { + if (e instanceof Prisma.PrismaClientKnownRequestError) { + if (e.code === "P2002") { + // instead of throwing a 500 error, catch the conflict and throw a 400 error. + throw new TRPCError({ message: "error_event_type_url_duplicate", code: "BAD_REQUEST" }); + } + } + throw e; + } // Handling updates to children event types (managed events types) await updateChildrenEventTypes({