* update to show exact err msg with custom event name * updated tests for validateCustomEventName --------- Co-authored-by: Keith Williams <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
5 files changed
+24
-22
No files matched your search
@@ -53,8 +53,12 @@ const CustomEventTypeModalForm: FC<CustomEventTypeModalFormProps> = (props) => {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder={placeHolder_}
|
placeholder={placeHolder_}
|
||||||
{...register("customEventName", {
|
{...register("customEventName", {
|
||||||
validate: (value) =>
|
validate: (value) => {
|
||||||
validateCustomEventName(value, t("invalid_event_name_variables"), event.bookingFields),
|
const validationResult = validateCustomEventName(value, event.bookingFields);
|
||||||
|
return typeof validationResult === "string"
|
||||||
|
? t("invalid_event_name_variables", { item: validationResult })
|
||||||
|
: validationResult;
|
||||||
|
},
|
||||||
})}
|
})}
|
||||||
className="mb-0"
|
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
|
// Make it optional because it's not submitted from all tabs of the page
|
||||||
eventName: z
|
eventName: z
|
||||||
.string()
|
.string()
|
||||||
.refine(
|
.superRefine((val, ctx) => {
|
||||||
(val) =>
|
const validationResult = validateCustomEventName(val, bookingFields);
|
||||||
validateCustomEventName(val, t("invalid_event_name_variables"), bookingFields) === true,
|
if (validationResult !== true) {
|
||||||
{
|
ctx.addIssue({
|
||||||
message: t("invalid_event_name_variables"),
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: t("invalid_event_name_variables", { item: validationResult }),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
length: z.union([z.string().transform((val) => +val), z.number()]).optional(),
|
length: z.union([z.string().transform((val) => +val), z.number()]).optional(),
|
||||||
offsetStart: 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",
|
"cancel_url_info": "The URL to cancel the booking",
|
||||||
"reschedule_url_variable": "Reschedule URL",
|
"reschedule_url_variable": "Reschedule URL",
|
||||||
"reschedule_url_info": "The URL to reschedule the booking",
|
"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",
|
"select_all": "Select All",
|
||||||
"default_conferencing_bulk_title": "Bulk update existing event types",
|
"default_conferencing_bulk_title": "Bulk update existing event types",
|
||||||
"members_default_schedule": "Member's default schedule",
|
"members_default_schedule": "Member's default schedule",
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ describe("event tests", () => {
|
|||||||
|
|
||||||
describe("fn: validateCustomEventName", () => {
|
describe("fn: validateCustomEventName", () => {
|
||||||
it("should be valid when no variables used", () => {
|
it("should be valid when no variables used", () => {
|
||||||
expect(event.validateCustomEventName("foo", "error message")).toBe(true);
|
expect(event.validateCustomEventName("foo")).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
[
|
[
|
||||||
@@ -371,24 +371,24 @@ describe("event tests", () => {
|
|||||||
"USER",
|
"USER",
|
||||||
].forEach((value) => {
|
].forEach((value) => {
|
||||||
it(`should support {${value}} variable`, () => {
|
it(`should support {${value}} variable`, () => {
|
||||||
expect(event.validateCustomEventName(`foo {${value}} bar`, "error message")).toBe(true);
|
expect(event.validateCustomEventName(`foo {${value}} bar`)).toBe(true);
|
||||||
|
|
||||||
expect(event.validateCustomEventName(`{${value}} bar`, "error message")).toBe(true);
|
expect(event.validateCustomEventName(`{${value}} bar`)).toBe(true);
|
||||||
|
|
||||||
expect(event.validateCustomEventName(`foo {${value}}`, "error message")).toBe(true);
|
expect(event.validateCustomEventName(`foo {${value}}`)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should support booking field variables", () => {
|
it("should support booking field variables", () => {
|
||||||
expect(
|
expect(
|
||||||
event.validateCustomEventName("foo{customField}bar", "error message", {
|
event.validateCustomEventName("foo{customField}bar", {
|
||||||
customField: true,
|
customField: true,
|
||||||
})
|
})
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return error when invalid variable used", () => {
|
it("should return variable when invalid variable used", () => {
|
||||||
expect(event.validateCustomEventName("foo{nonsenseField}bar", "error message")).toBe("error message");
|
expect(event.validateCustomEventName("foo{nonsenseField}bar")).toBe("{nonsenseField}");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -100,11 +100,7 @@ export function getEventName(eventNameObj: EventNameObjectType, forAttendeeView
|
|||||||
return dynamicEventName;
|
return dynamicEventName;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const validateCustomEventName = (
|
export const validateCustomEventName = (value: string, bookingFields?: Prisma.JsonObject) => {
|
||||||
value: string,
|
|
||||||
message: string,
|
|
||||||
bookingFields?: Prisma.JsonObject
|
|
||||||
) => {
|
|
||||||
let customInputVariables: string[] = [];
|
let customInputVariables: string[] = [];
|
||||||
if (bookingFields) {
|
if (bookingFields) {
|
||||||
customInputVariables = Object.keys(bookingFields).map((customInput) => {
|
customInputVariables = Object.keys(bookingFields).map((customInput) => {
|
||||||
@@ -131,7 +127,7 @@ export const validateCustomEventName = (
|
|||||||
if (matches?.length) {
|
if (matches?.length) {
|
||||||
for (const item of matches) {
|
for (const item of matches) {
|
||||||
if (!validVariables.includes(item)) {
|
if (!validVariables.includes(item)) {
|
||||||
return message;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user