forked from calcom/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: skip confirm step in booker (calcom#18773)
* feat: skip confirm step * better naming * disable on loading * feat: added cloudflare turnstile captcha to booker * Update Booker.tsx * Update AvailableTimeSlots.tsx * made optional to fix type errors * Update Booker.tsx * Update getBookingResponsesSchema.ts * Update Booker.tsx * fixed failing tests * added tests * fix: fixed failing embed tests
- Loading branch information
1 parent
ac8b4a2
commit be1b9d1
Showing
10 changed files
with
251 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -401,6 +401,23 @@ test.describe("prefill", () => { | |
await expect(page.locator('[name="email"]')).toHaveValue(testEmail); | ||
}); | ||
}); | ||
|
||
test("skip confirm step if all fields are prefilled from query params", async ({ page }) => { | ||
await page.goto("/pro/30min"); | ||
const url = new URL(page.url()); | ||
url.searchParams.set("name", testName); | ||
url.searchParams.set("email", testEmail); | ||
url.searchParams.set("guests", "[email protected]"); | ||
url.searchParams.set("guests", "[email protected]"); | ||
url.searchParams.set("notes", "This is an additional note"); | ||
await page.goto(url.toString()); | ||
await selectFirstAvailableTimeSlotNextMonth(page); | ||
|
||
await expect(page.locator('[data-testid="skip-confirm-book-button"]')).toBeVisible(); | ||
await page.click('[data-testid="skip-confirm-book-button"]'); | ||
|
||
await expect(page.locator("[data-testid=success-page]")).toBeVisible(); | ||
}); | ||
}); | ||
|
||
test.describe("Booking on different layouts", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,7 +172,6 @@ test.describe("Manage Booking Questions", () => { | |
prefillUrl.searchParams.append("email", "[email protected]"); | ||
prefillUrl.searchParams.append("guests", "[email protected]"); | ||
prefillUrl.searchParams.append("guests", "[email protected]"); | ||
prefillUrl.searchParams.append("notes", "This is an additional note"); | ||
await page.goto(prefillUrl.toString()); | ||
await bookTimeSlot({ page, skipSubmission: true }); | ||
await expectSystemFieldsToBeThereOnBookingPage({ | ||
|
@@ -185,7 +184,6 @@ test.describe("Manage Booking Questions", () => { | |
}, | ||
email: "[email protected]", | ||
guests: ["[email protected]", "[email protected]"], | ||
notes: "This is an additional note", | ||
}, | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,6 @@ if (only === "all" || only === "ns:default") { | |
}, | ||
name: "John", | ||
email: "[email protected]", | ||
notes: "Test Meeting", | ||
guests: ["[email protected]", "[email protected]"], | ||
theme: "dark", | ||
"flag.coep": "true", | ||
|
@@ -454,7 +453,6 @@ if (only === "all" || only == "ns:floatingButton") { | |
"flag.coep": "true", | ||
name: "John", | ||
email: "[email protected]", | ||
notes: "Test Meeting", | ||
guests: ["[email protected]", "[email protected]"], | ||
...(theme ? { theme } : {}), | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/features/bookings/Booker/components/hooks/useSkipConfirmStep.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
import type { UseBookingFormReturnType } from "@calcom/features/bookings/Booker/components/hooks/useBookingForm"; | ||
import { useBookerStore } from "@calcom/features/bookings/Booker/store"; | ||
import { getBookingResponsesSchemaWithOptionalChecks } from "@calcom/features/bookings/lib/getBookingResponsesSchema"; | ||
import type { BookerEvent } from "@calcom/features/bookings/types"; | ||
|
||
const useSkipConfirmStep = ( | ||
bookingForm: UseBookingFormReturnType["bookingForm"], | ||
bookingFields?: BookerEvent["bookingFields"] | ||
) => { | ||
const bookingFormValues = bookingForm.getValues(); | ||
|
||
const [canSkip, setCanSkip] = useState(false); | ||
const rescheduleUid = useBookerStore((state) => state.rescheduleUid); | ||
|
||
useEffect(() => { | ||
const checkSkipStep = async () => { | ||
if (!bookingFields) { | ||
setCanSkip(false); | ||
return; | ||
} | ||
|
||
try { | ||
const responseSchema = getBookingResponsesSchemaWithOptionalChecks({ | ||
bookingFields, | ||
view: rescheduleUid ? "reschedule" : "booking", | ||
}); | ||
const responseSafeParse = await responseSchema.safeParseAsync(bookingFormValues.responses); | ||
|
||
setCanSkip(responseSafeParse.success); | ||
} catch (error) { | ||
setCanSkip(false); | ||
} | ||
}; | ||
|
||
checkSkipStep(); | ||
}, [bookingFormValues, bookingFields, rescheduleUid]); | ||
|
||
return canSkip; | ||
}; | ||
|
||
export default useSkipConfirmStep; |
Oops, something went wrong.