Scheduling infrastructure for absolutely everyone.
fix: Invalid phone error on prefill with plus(+) sign (#15046)
Hariom Balharabbb86f217450
diff --git a/packages/features/bookings/lib/getBookingResponsesSchema.test.ts b/packages/features/bookings/lib/getBookingResponsesSchema.test.tsindex 5022fea425e..7ccdc6857b7 100644--- a/packages/features/bookings/lib/getBookingResponsesSchema.test.ts+++ b/packages/features/bookings/lib/getBookingResponsesSchema.test.ts@@ -506,7 +506,7 @@ describe("getBookingResponsesSchema", () => {}));});- test(`should succesfull give responses if phone type field value is valid`, async ({}) => {+ test(`should successfully give responses if phone type field value is valid`, async ({}) => {const schema = getBookingResponsesSchema({bookingFields: [{@@ -543,6 +543,60 @@ describe("getBookingResponsesSchema", () => {});});+ test(`should give parsed response if phone type field value starts with a space`, async ({}) => {+ const schema = getBookingResponsesSchema({+ bookingFields: [+ {+ name: "name",+ type: "name",+ required: true,+ },+ {+ name: "email",+ type: "email",+ required: true,+ },+ {+ name: "testPhone",+ type: "phone",+ required: true,+ },+ ] as z.infer<typeof eventTypeBookingFields> & z.BRAND<"HAS_SYSTEM_FIELDS">,+ view: "ALL_VIEWS",+ });+ const parsedResponses = await schema.safeParseAsync({+ email: "[email protected]",+ name: "test",+ // Space can come due to libraries considering + to be space+ testPhone: " 919999999999",+ });+ expect(parsedResponses.success).toBe(true);+ if (!parsedResponses.success) {+ throw new Error("Should not reach here");+ }+ expect(parsedResponses.data).toEqual({+ email: "[email protected]",+ name: "test",+ testPhone: "+919999999999",+ });++ const parsedResponses2 = await schema.safeParseAsync({+ email: "[email protected]",+ name: "test",+ // Space can come due to libraries considering + to be space+ testPhone: " 919999999999",+ });+ expect(parsedResponses2.success).toBe(true);+ if (!parsedResponses2.success) {+ throw new Error("Should not reach here");+ }+ expect(parsedResponses2.data).toEqual({+ email: "[email protected]",+ name: "test",+ testPhone: "+919999999999",+ });+ });+test("should fail parsing if phone field value is empty", async ({}) => {const schema = getBookingResponsesSchema({bookingFields: [diff --git a/packages/features/bookings/lib/getBookingResponsesSchema.ts b/packages/features/bookings/lib/getBookingResponsesSchema.tsindex 4a6d9438b06..31b3c732f09 100644--- a/packages/features/bookings/lib/getBookingResponsesSchema.ts+++ b/packages/features/bookings/lib/getBookingResponsesSchema.ts@@ -90,6 +90,10 @@ function preprocess<T extends z.ZodType>({parsedValue = JSON.parse(value);} catch (e) {}newResponses[field.name] = parsedValue;+ } else if (field.type === "phone") {+ // + in URL could be replaced with space, so we need to replace it back+ // Replace the space(s) in the beginning with + as it is supposed to be provided in the beginning only+ newResponses[field.name] = value.replace(/^ +/, "+");} else {newResponses[field.name] = value;}