From ce13350d5d7a1706d3030c0bd03290944862a07f Mon Sep 17 00:00:00 2001 From: Nafees Nazik <84864519+G3root@users.noreply.github.com> Date: Wed, 27 Sep 2023 10:09:37 +0530 Subject: [PATCH] fix: form input not being saved after "back" (#11540) Co-authored-by: Hariom Balhara --- apps/web/playwright/booking-pages.e2e.ts | 17 +++++++++++++++++ .../components/BookEventForm/BookEventForm.tsx | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/web/playwright/booking-pages.e2e.ts b/apps/web/playwright/booking-pages.e2e.ts index 9ebd29bb2d..87ac1dcf51 100644 --- a/apps/web/playwright/booking-pages.e2e.ts +++ b/apps/web/playwright/booking-pages.e2e.ts @@ -252,6 +252,23 @@ test.describe("prefill", () => { }); }); + test("Persist the field values when going back and coming back to the booking form", async ({ + page, + users, + }) => { + await page.goto("/pro/30min"); + await selectFirstAvailableTimeSlotNextMonth(page); + await page.fill('[name="name"]', "John Doe"); + await page.fill('[name="email"]', "john@example.com"); + await page.fill('[name="notes"]', "Test notes"); + await page.click('[data-testid="back"]'); + + await selectFirstAvailableTimeSlotNextMonth(page); + await expect(page.locator('[name="name"]')).toHaveValue("John Doe"); + await expect(page.locator('[name="email"]')).toHaveValue("john@example.com"); + await expect(page.locator('[name="notes"]')).toHaveValue("Test notes"); + }); + test("logged out", async ({ page, users }) => { await page.goto("/pro/30min"); diff --git a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx index b22574e3ed..7c12ff9478 100644 --- a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx +++ b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx @@ -461,7 +461,10 @@ function useInitialFormValues({ const session = useSession(); useEffect(() => { (async function () { - if (Object.keys(formValues).length) return formValues; + if (Object.keys(formValues).length) { + setDefaultValues(formValues); + return; + } if (!eventType?.bookingFields) { return {};