Skip to content

Scheduling infrastructure for absolutely everyone.

refactor: A improvement fix related to optional phone validation (#22305)

Vansh Gilhotra3228d8d86978
diff --git a/packages/features/bookings/lib/getBookingResponsesSchema.ts b/packages/features/bookings/lib/getBookingResponsesSchema.ts
index d33ecf566c2..d3e61a883dd 100644
--- a/packages/features/bookings/lib/getBookingResponsesSchema.ts
+++ b/packages/features/bookings/lib/getBookingResponsesSchema.ts
@@ -276,8 +276,14 @@ function preprocess<T extends z.ZodType>({
}
if (bookingField.type === "phone") {
- if (!bookingField.hidden && !(await phoneSchema.safeParseAsync(value)).success) {
- ctx.addIssue({ code: z.ZodIssueCode.custom, message: m("invalid_number") });
+ // Determine if the phone field needs validation
+ const needsValidation = isRequired || (value && value.trim() !== "");
+
+ // Validate phone number if the field is not hidden and requires validation
+ if (!bookingField.hidden && needsValidation) {
+ if (!(await phoneSchema.safeParseAsync(value)).success) {
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: m("invalid_number") });
+ }
}
continue;
}