Support firstName and lastName query params (#11420)

11426-cal-2487-commercial-upgrade-screen-with-description-of-commercial-license-and-checkout-flow
Hariom Balhara 2023-09-18 21:28:07 +05:30 committed by GitHub
parent 8ba09ce04d
commit c9c634cceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -153,6 +153,25 @@ test.describe("Manage Booking Questions", () => {
});
});
});
await test.step("Verify that we can prefill name field with firstName,lastName query params", async () => {
const searchParams = new URLSearchParams();
searchParams.append("firstName", "John");
searchParams.append("lastName", "Doe");
await doOnFreshPreviewWithSearchParams(searchParams, page, context, async (page) => {
await selectFirstAvailableTimeSlotNextMonth(page);
await expectSystemFieldsToBeThereOnBookingPage({
page,
isFirstAndLastNameVariant: true,
values: {
name: {
firstName: "John",
lastName: "Doe",
},
},
});
});
});
});
});

View File

@ -473,8 +473,16 @@ function useInitialFormValues({
view: rescheduleUid ? "reschedule" : "booking",
});
// Routing Forms don't support Split full name(because no Form Builder in there), so user needs to create two fields in there themselves. If they name these fields, `firstName` and `lastName`, we can prefill the Booking Form with them
// Once we support formBuilder in Routing Forms, we should be able to forward JSON form of name field value to Booking Form and prefill it there without having these two query params separately.
const firstNameQueryParam = searchParams?.get("firstName");
const lastNameQueryParam = searchParams?.get("lastName");
const parsedQuery = await querySchema.parseAsync({
...routerQuery,
name:
searchParams?.get("name") ||
(firstNameQueryParam ? `${firstNameQueryParam} ${lastNameQueryParam}` : null),
// `guest` because we need to support legacy URL with `guest` query param support
// `guests` because the `name` of the corresponding bookingField is `guests`
guests: searchParams?.getAll("guests") || searchParams?.getAll("guest"),