From 23f5e0393b23521d7893a19cee889d76fa9d479f Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Mon, 30 Oct 2023 20:48:07 +0530 Subject: [PATCH] fix: improve error message --- .../components/eventtype/EventSetupTab.tsx | 67 ++++++++----------- apps/web/pages/event-types/[type]/index.tsx | 40 +++++++++++ 2 files changed, 68 insertions(+), 39 deletions(-) diff --git a/apps/web/components/eventtype/EventSetupTab.tsx b/apps/web/components/eventtype/EventSetupTab.tsx index 754f060868..67e8fde94b 100644 --- a/apps/web/components/eventtype/EventSetupTab.tsx +++ b/apps/web/components/eventtype/EventSetupTab.tsx @@ -30,8 +30,7 @@ import { Button, showToast, } from "@calcom/ui"; -import { Plus, X, Check } from "@calcom/ui/components/icon"; -import { CornerDownRight } from "@calcom/ui/components/icon"; +import { Plus, X, Check, CornerDownRight } from "@calcom/ui/components/icon"; import CheckboxField from "@components/ui/form/CheckboxField"; import type { SingleValueLocationOption } from "@components/ui/form/LocationSelect"; @@ -200,23 +199,15 @@ export const EventSetupTab = ( defaultValue={defaultValue} render={({ field: { onChange, value } }) => { return ( - <> - - - + ); }} /> @@ -231,21 +222,13 @@ export const EventSetupTab = ( defaultValue={defaultValue} render={({ field: { onChange, value } }) => { return ( - <> - - - + ); }} /> @@ -320,11 +303,11 @@ export const EventSetupTab = ( {eventLocationType?.organizerInputType && (
-
-
- -
-
+
+
+
+ +
+
{ teamName: z.string().optional(), }) .passthrough() + .superRefine((val, ctx) => { + if (val?.link) { + const link = val.link; + const eventLocationType = getEventLocationType(val.type); + if ( + eventLocationType && + !eventLocationType.default && + eventLocationType.linkType === "static" && + eventLocationType.urlRegExp + ) { + const valid = z + .string() + .regex(new RegExp(eventLocationType.urlRegExp)) + .safeParse(link).success; + + if (!valid) { + const sampleUrl = eventLocationType.organizerInputPlaceholder; + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: [eventLocationType.defaultValueVariable], + message: `Invalid URL for ${eventLocationType.label}. ${ + sampleUrl ? `Sample URL: ${sampleUrl}` : "" + }`, + }); + } + return; + } + + const valid = z.string().url().optional().safeParse(val).success; + if (!valid) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: [eventLocationType.defaultValueVariable], + message: `Invalid URL`, + }); + } + } + return; + }) ) .optional(), })