fix: #15967 Show better error when wrong variable is used in custom event name (#15974)

* update to show exact err msg with custom event name

* updated tests for validateCustomEventName

---------

Co-authored-by: Keith Williams <keithwillcode@gmail.com>
Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2024-07-29 20:23:53 +03:00
1 parent 9a1a86ed3a
commit 27d331ad2d
5 files changed
+24 -22

No files matched your search

@@ -53,8 +53,12 @@ const CustomEventTypeModalForm: FC<CustomEventTypeModalFormProps> = (props) => {
type="text"
placeholder={placeHolder_}
{...register("customEventName", {
validate: (value) =>
validateCustomEventName(value, t("invalid_event_name_variables"), event.bookingFields),
validate: (value) => {
const validationResult = validateCustomEventName(value, event.bookingFields);
return typeof validationResult === "string"
? t("invalid_event_name_variables", { item: validationResult })
: validationResult;
},
})}
className="mb-0"
/>
@@ -384,13 +384,15 @@ const EventTypePage = (props: EventTypeSetupProps & { allActiveWorkflows?: Workf
// Make it optional because it's not submitted from all tabs of the page
eventName: z
.string()
.refine(
(val) =>
validateCustomEventName(val, t("invalid_event_name_variables"), bookingFields) === true,
{
message: t("invalid_event_name_variables"),
.superRefine((val, ctx) => {
const validationResult = validateCustomEventName(val, bookingFields);
if (validationResult !== true) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: t("invalid_event_name_variables", { item: validationResult }),
});
}
)
})
.optional(),
length: z.union([z.string().transform((val) => +val), z.number()]).optional(),
offsetStart: z.union([z.string().transform((val) => +val), z.number()]).optional(),
@@ -1926,7 +1926,7 @@
"cancel_url_info": "The URL to cancel the booking",
"reschedule_url_variable": "Reschedule URL",
"reschedule_url_info": "The URL to reschedule the booking",
"invalid_event_name_variables": "There is an invalid variable in your event name",
"invalid_event_name_variables": "{{item}} is an invalid variable in your event name",
"select_all": "Select All",
"default_conferencing_bulk_title": "Bulk update existing event types",
"members_default_schedule": "Member's default schedule",