Skip to content

Commit ef4be48

Browse files
authored
fix: configure correct error message for duplicate event type slug (calcom#24928)
* fix/duplicate-event-type-to-existing slug * use existing pattern to to verify the conflict on slug
1 parent 5c9ad93 commit ef4be48

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

apps/web/public/static/locales/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@
457457
"bookerlayout_error_unknown_layout": "The layout you selected is not a valid layout.",
458458
"bookerlayout_override_global_settings": "You can manage this for all your event types in Settings -> <0>Appearance</0> or <1>Override</1> for this event only.",
459459
"unexpected_error_try_again": "An unexpected error occurred. Try again.",
460+
"duplicate_event_slug_conflict": "An event type with this URL already exists. Please try a different URL.",
460461
"sunday_time_error": "Invalid time on Sunday",
461462
"monday_time_error": "Invalid time on Monday",
462463
"tuesday_time_error": "Invalid time on Tuesday",

packages/features/eventtypes/components/DuplicateDialog.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ const DuplicateDialog = () => {
9393
if (err instanceof HttpError) {
9494
const message = `${err.statusCode}: ${err.message}`;
9595
showToast(message, "error");
96+
return;
97+
}
98+
99+
if (err.data?.code === "CONFLICT") {
100+
const message = t("duplicate_event_slug_conflict");
101+
showToast(message, "error");
102+
return;
96103
}
97104

98105
if (err.data?.code === "INTERNAL_SERVER_ERROR" || err.data?.code === "BAD_REQUEST") {

packages/trpc/server/routers/viewer/eventTypes/heavy/duplicate.handler.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
9595
workflows,
9696
hashedLink,
9797
destinationCalendar,
98-
98+
9999
id: _id,
100-
100+
101101
webhooks: _webhooks,
102-
102+
103103
schedule: _schedule,
104104
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
105105
// @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
@@ -227,9 +227,16 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
227227
};
228228
} catch (error) {
229229
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") {
230-
// unique constraint violation
230+
231+
if (Array.isArray(error.meta?.target) && error.meta?.target.includes("slug")) {
232+
throw new TRPCError({
233+
code: "CONFLICT",
234+
message: "duplicate_event_slug_conflict",
235+
});
236+
}
237+
231238
throw new TRPCError({
232-
code: "BAD_REQUEST",
239+
code: "CONFLICT",
233240
message: "Unique constraint violation while creating a duplicate event.",
234241
});
235242
}

0 commit comments

Comments
 (0)