test: Add e2e for prerendering headless router with attribute routing (#22080)
* test: Add e2e for prerender * wip * fix tests * conflict resolution * Fix unit tests and e2e failure * chore: Reorganize
This commit is contained in:
1 parent
750e6315dc
commit
f667417d84
13 files changed
+1935
-273
No files matched your search
@@ -88,7 +88,12 @@ export function getAbsoluteEventTypeRedirectUrl({
|
||||
}
|
||||
}
|
||||
|
||||
const origin = teamSlugInRedirectUrl ? form.teamOrigin : form.userOrigin;
|
||||
// We want origin to be the WEBAPP_URL as in E2E the org domain won't exist. E2E fake request from org domain using doOnOrgDomain
|
||||
const origin = process.env.NEXT_PUBLIC_IS_E2E
|
||||
? WEBAPP_URL
|
||||
: teamSlugInRedirectUrl
|
||||
? form.teamOrigin
|
||||
: form.userOrigin;
|
||||
|
||||
return `${origin}/${eventTypeRedirectUrl}?${allURLSearchParams}`;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { Frame } from "@playwright/test";
|
||||
import { expect } from "@playwright/test";
|
||||
|
||||
export async function expectHostsToBe({ hosts, frame }: { hosts: { email: string }[]; frame: Frame }) {
|
||||
try {
|
||||
await frame.waitForSelector(`[data-testid="booking-host-email"]`, { timeout: 5000 });
|
||||
} catch (error) {
|
||||
console.error("Failed to find booking-host-email element:", error.message);
|
||||
throw new Error(`booking-host-email element not found. `);
|
||||
}
|
||||
|
||||
const hostEmailsOnPage = await frame.locator(`[data-testid="booking-host-email"]`).allTextContents();
|
||||
const expectedEmails = hosts.map((host) => host.email);
|
||||
|
||||
expect(hostEmailsOnPage).toEqual(expect.arrayContaining(expectedEmails));
|
||||
}
|
||||
@@ -3,6 +3,39 @@ import { expect } from "@playwright/test";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
export async function getQueuedFormResponse(queuedFormResponseId: string) {
|
||||
return prisma.app_RoutingForms_QueuedFormResponse.findFirst({
|
||||
where: {
|
||||
id: queuedFormResponseId,
|
||||
},
|
||||
include: {
|
||||
actualResponse: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getAllFormResponses(formId: string) {
|
||||
return prisma.app_RoutingForms_FormResponse.findMany({
|
||||
where: {
|
||||
formId: formId,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getLatestQueuedFormResponse({ formId }: { formId: string }) {
|
||||
return prisma.app_RoutingForms_QueuedFormResponse.findFirst({
|
||||
where: {
|
||||
formId: formId,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export const deleteAllBookingsByEmail = async (email: string) =>
|
||||
await prisma.booking.deleteMany({
|
||||
where: {
|
||||
@@ -115,6 +148,10 @@ export async function bookFirstEvent(username: string, frame: Frame, page: Page)
|
||||
await frame.waitForTimeout(1000);
|
||||
// expect(await page.screenshot()).toMatchSnapshot("availability-page-1.png");
|
||||
// Remove /embed from the end if present.
|
||||
return bookEvent({ frame, page });
|
||||
}
|
||||
|
||||
export async function bookEvent({ frame, page }: { frame: Frame; page: Page }) {
|
||||
const eventSlug = new URL(frame.url()).pathname.replace(/\/embed$/, "");
|
||||
await selectFirstAvailableTimeSlotNextMonth(frame, page);
|
||||
// expect(await page.screenshot()).toMatchSnapshot("booking-page.png");
|
||||
@@ -158,3 +195,40 @@ export async function assertNoRequestIsBlocked(page: Page) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function expectEmbedIFrameToBeVisible({
|
||||
calNamespace,
|
||||
page,
|
||||
}: {
|
||||
calNamespace: string;
|
||||
page: Page;
|
||||
}) {
|
||||
const iframe = page.locator(`[name="cal-embed=${calNamespace}"]`);
|
||||
await expect(iframe).toBeVisible();
|
||||
}
|
||||
|
||||
export async function expectActualFormResponseConnectedToQueuedFormResponse({
|
||||
queuedFormResponse,
|
||||
page,
|
||||
numberOfExpectedSetFieldValues,
|
||||
}: {
|
||||
queuedFormResponse: { id: string };
|
||||
page: Page;
|
||||
}) {
|
||||
const responsePromise = page.waitForResponse("**/queued-response");
|
||||
const response = await responsePromise;
|
||||
expect(response.status()).toBe(200);
|
||||
|
||||
const queuedFormResponseFromDb = await getQueuedFormResponse(queuedFormResponse.id);
|
||||
|
||||
expect(queuedFormResponseFromDb?.actualResponse?.id).toBeDefined();
|
||||
const responseFromDb = queuedFormResponseFromDb?.actualResponse?.response;
|
||||
expect(responseFromDb).toBeDefined();
|
||||
const valuesFromResponse = Object.values(responseFromDb).map((item) => item.value);
|
||||
const valuesSetInResponse = valuesFromResponse.filter((value) => !!value);
|
||||
// We are unable to verify the exact response values because we don't directly have the form field identifiers in responseFromDB and would require correlating that with the actual Form from DB
|
||||
// So, for now we just verify the number of values set
|
||||
// There are 5 values that are submitted when CTA is clicked.
|
||||
// TODO: We should be able to verify the exact response values by correlating the form field identifiers with the actual Form from DB
|
||||
expect(valuesSetInResponse.length).toBe(numberOfExpectedSetFieldValues);
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
import type { Page } from "@playwright/test";
|
||||
import { expect } from "@playwright/test";
|
||||
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { test } from "@calcom/web/playwright/lib/fixtures";
|
||||
import type { Fixtures } from "@calcom/web/playwright/lib/fixtures";
|
||||
import { doOnOrgDomain } from "@calcom/web/playwright/lib/testUtils";
|
||||
|
||||
import { expectHostsToBe } from "../lib/pages/bookingSuccessPage";
|
||||
import {
|
||||
getEmbedIframe,
|
||||
bookEvent,
|
||||
expectEmbedIFrameToBeVisible,
|
||||
getAllFormResponses,
|
||||
expectActualFormResponseConnectedToQueuedFormResponse,
|
||||
getLatestQueuedFormResponse,
|
||||
} from "../lib/testUtils";
|
||||
|
||||
// in parallel mode sometimes handleNewBooking endpoint throws "No available users found" error, this never happens in serial mode.
|
||||
test.describe.configure({ mode: "serial" });
|
||||
|
||||
async function fillRoutingRequiredAttributes(
|
||||
page: Page,
|
||||
{ skills, location, email }: { skills: string; location: string; email: string }
|
||||
) {
|
||||
await page.fill("#cal-booking-place-routingFormFullPrerender-input-email", email);
|
||||
await page.selectOption("#cal-booking-place-routingFormFullPrerender-select-skills", skills);
|
||||
await page.selectOption("#cal-booking-place-routingFormFullPrerender-select-location", location);
|
||||
|
||||
return {
|
||||
skills,
|
||||
location,
|
||||
email,
|
||||
};
|
||||
}
|
||||
|
||||
async function fillRestOfTheFormAndSubmit(page: Page) {
|
||||
const name = "John Doe";
|
||||
await page.fill("#cal-booking-place-routingFormFullPrerender-input-name", name);
|
||||
await page.click("#cta-routingFormFullPrerender");
|
||||
|
||||
return {
|
||||
name,
|
||||
};
|
||||
}
|
||||
|
||||
//TODO: Change these tests to use a user/eventType per embed type atleast. This is so that we can test different themes,layouts configured in App or per EventType
|
||||
test.describe("Prerender Headless Router", () => {
|
||||
test.afterEach(async ({ users }) => {
|
||||
await users.deleteAll();
|
||||
});
|
||||
|
||||
test("should prerender when routing-required fields are filled and route to Javascript team as Javascript skills is selected and then doing the actual booking should show the routed team members as hosts", async ({
|
||||
page,
|
||||
embeds,
|
||||
users,
|
||||
}) => {
|
||||
const userFixture = await users.create(
|
||||
{ username: "routing-forms" },
|
||||
{
|
||||
hasTeam: true,
|
||||
isOrg: true,
|
||||
hasSubteam: true,
|
||||
schedulingType: SchedulingType.ROUND_ROBIN,
|
||||
seedRoutingFormWithAttributeRouting: true,
|
||||
seedRoutingForms: true,
|
||||
}
|
||||
);
|
||||
|
||||
const orgMembership = await userFixture.getOrgMembership();
|
||||
const teamMembership = await userFixture.getFirstTeamMembership();
|
||||
const routingForm = userFixture.routingForms[0];
|
||||
|
||||
const calNamespace = "routingFormFullPrerender";
|
||||
await embeds.gotoPlayground({
|
||||
calNamespace,
|
||||
url: `/embed/routing-playground.html?only=ns:${calNamespace}¶m.formId=${routingForm.id}&calOrigin=${WEBAPP_URL}&cal.embed.logging=1`,
|
||||
});
|
||||
|
||||
await doOnOrgDomain({ orgSlug: orgMembership.team.slug, page }, async ({ page }) => {
|
||||
const { skills, location, email } = await fillRoutingRequiredAttributes(page, {
|
||||
skills: "JavaScript",
|
||||
location: "London",
|
||||
email: "[email protected]", // This is the email that will be used to book the event
|
||||
});
|
||||
|
||||
const expectedRoutedTeamMembers = [teamMembership.user];
|
||||
// Routes to the team booking page with params cal.routingFormResponseId, cal.routedTeamMemberIds
|
||||
// Sample URL: http://app.cal.local:3000/team/team-0-1751270109394/team-javascript/embed?cal.teamId=103&cal.orgId=104&Rating=5&embed=routingFormFullPrerender&debug=true&only=ns%3AroutingFormFullPrerender¶m.formId=bed2a37b-8bf7-4eb9-9b9e-4adf33bd9470&calOrigin=http%3A%2F%2Fapp.cal.remote%3A3000&cal.embed.logging=1&cal.embed.pageType=team.event.booking.slots&cal.action=eventTypeRedirectUrl&cal.queuedFormResponseId=cmcit0aos0006j5o4qctc2oyy&cal.embed.connectVersion=0&form=bed2a37b-8bf7-4eb9-9b9e-4adf33bd9470&skills=JavaScript&Location=London&name=John+Doe&Email=undefined&Manager=John+Doe&embedType=modal&guest=undefined&cal.routingFormResponseId=14&month=2025-07&date=2025-07-02&slot=2025-07-02T08%3A00%3A00.000Z
|
||||
const { prerenderedIframe, queuedFormResponseId } = await expectPrerenderedRoutedTeamBookingPage({
|
||||
page,
|
||||
calNamespace,
|
||||
calLink: `/team/${teamMembership.team.slug}/team-javascript`,
|
||||
embeds,
|
||||
routedTeamMemberIds: expectedRoutedTeamMembers.map((user) => user.id),
|
||||
routingForm,
|
||||
});
|
||||
|
||||
const { name } = await fillRestOfTheFormAndSubmit(page);
|
||||
await Promise.all([
|
||||
expectEmbedIFrameToBeVisible({ calNamespace, page }),
|
||||
expectActualFormResponseConnectedToQueuedFormResponse({
|
||||
queuedFormResponse: { id: queuedFormResponseId },
|
||||
numberOfExpectedSetFieldValues: 5,
|
||||
page,
|
||||
}),
|
||||
]);
|
||||
await bookEvent({ frame: prerenderedIframe, page });
|
||||
await expectHostsToBe({
|
||||
hosts: expectedRoutedTeamMembers.map((user) => ({ email: user.email })),
|
||||
frame: prerenderedIframe,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async function expectPrerenderedRoutedTeamBookingPage({
|
||||
page,
|
||||
calNamespace,
|
||||
calLink,
|
||||
embeds,
|
||||
routingForm,
|
||||
routedTeamMemberIds,
|
||||
}: {
|
||||
page: Page;
|
||||
calNamespace: string;
|
||||
calLink: string;
|
||||
embeds: Fixtures["embeds"];
|
||||
routingForm: {
|
||||
id: string;
|
||||
};
|
||||
routedTeamMemberIds: string[];
|
||||
}) {
|
||||
const prerenderedIframe = await getEmbedIframe({ calNamespace, page, pathname: calLink });
|
||||
|
||||
if (!prerenderedIframe) {
|
||||
throw new Error("Prerendered iframe not found");
|
||||
}
|
||||
|
||||
// As Routing Form is unique to the test, we can expect responses to be provided by the test itself.
|
||||
// So, the only response should be the one that is provided by the test itself.
|
||||
const queuedResponse = await getLatestQueuedFormResponse({ formId: routingForm.id });
|
||||
|
||||
const routingFormResponses = await getAllFormResponses(routingForm.id);
|
||||
|
||||
if (!queuedResponse) {
|
||||
throw new Error("Couldn't find the queued response");
|
||||
}
|
||||
|
||||
if (routingFormResponses.length > 0) {
|
||||
throw new Error(
|
||||
`Routing form response shouldn't have been recorded. Found one with id: ${routingFormResponses[0].id}`
|
||||
);
|
||||
}
|
||||
|
||||
await expect(prerenderedIframe).toBeEmbedCalLink(
|
||||
calNamespace,
|
||||
embeds.getActionFiredDetails,
|
||||
{
|
||||
pathname: calLink,
|
||||
searchParams: {
|
||||
"cal.queuedFormResponseId": queuedResponse.id,
|
||||
"cal.routedTeamMemberIds": routedTeamMemberIds.join(","),
|
||||
},
|
||||
},
|
||||
true
|
||||
);
|
||||
return { prerenderedIframe, queuedFormResponseId: queuedResponse.id };
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
const newSearchParams = new URLSearchParams(location.search);
|
||||
let paramsChanged = false;
|
||||
if (!newSearchParams.has("only")) {
|
||||
newSearchParams.set("only", "ns:routingFormPrerender");
|
||||
newSearchParams.set("only", "ns:routingFormFullPrerender");
|
||||
paramsChanged = true;
|
||||
}
|
||||
|
||||
@@ -116,56 +116,15 @@
|
||||
const email = form.querySelector("input[name='email']").value;
|
||||
const skills = form.querySelector("select[name='skills']").value;
|
||||
if (name && email) {
|
||||
document.getElementById("cal-booking-place-routingFormWithoutPrerender-submit").setAttribute("data-cal-link", `router?form=${seededFormAcmeId}&email=${email}&name=${name}&Location=London&Department=Engineering&Manager=John Doe&Rating=5&skills=${skills}&Email=${email}`);
|
||||
document.getElementById("cal-booking-place-routingFormWithoutPrerender-submit").setAttribute("data-cal-link", `router?form=${seededFormAcmeId}&email=${email}&name=${name}&Location=London&Department=Engineering&Rating=5&skills=${skills}&Email=${email}`);
|
||||
}
|
||||
requestAnimationFrame(updateSubmitButtonLink);
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
<div id="cal-booking-place-routingFormPrerender">
|
||||
<div id="cal-booking-routingFormFullPrerender">
|
||||
<hr/>
|
||||
<a href="?only=ns:routingFormPrerender">Routing Form Prerender Team Booking Page - Demo</a>
|
||||
<p>1. As soon as you start typing in the form, the form will prerender the booking page(where redirect is supposed to happen)</p>
|
||||
<p>2. Clicking on submit will open the prerendered/being prerendered iframe in the modal, sending fresh request for headless router, followed by fetching the slots</p>
|
||||
<p>3. Changing the form response and clicking submit, will re-submit the response and reopen the modal with the updated data(update slots call, updated prefill fields)</p>
|
||||
<p>4. Clicking submit again without changing the form response will just re-show the hidden modal(as long as slotsStaleTimeMs threshold is not breached). But, in case of an error it iframe always tries to rerender. Trying adding an invalid email to see the error</p>
|
||||
<form id="cal-booking-place-routingFormPrerender-form">
|
||||
<input type="text" name="name" placeholder="John Doe" />
|
||||
<input type="email" name="email" placeholder="[email protected]" />
|
||||
<select name="skills" placeholder="JavaScript, Node.js">
|
||||
<option value="JavaScript">JavaScript</option>
|
||||
<option value="Sales">Sales</option>
|
||||
</select>
|
||||
</form>
|
||||
<button id="cal-booking-place-routingFormPrerender-submit" data-cal-namespace="routingFormPrerender" data-cal-config='{"cal.embed.pageType":"team.event.booking.slots", "guests":["[email protected]", "[email protected]"]}'>Submit</button>
|
||||
<script>
|
||||
document.getElementById("cal-booking-place-routingFormPrerender-form").addEventListener("input", function prerender(e) {
|
||||
if (prerender.initiated) return;
|
||||
prerender.initiated = true;
|
||||
console.log("Playground: prerender initiated");
|
||||
Cal.ns.routingFormPrerender("prerender", {
|
||||
calLink: "team/insights-team/team-javascript",
|
||||
type: "modal",
|
||||
pageType: "user.event.booking.slots",
|
||||
});
|
||||
});
|
||||
|
||||
requestAnimationFrame(function updateSubmitButtonLink() {
|
||||
const seededFormAcmeId = "948ae412-d995-4865-885a-48302588de03";
|
||||
const form = document.getElementById("cal-booking-place-routingFormPrerender-form");
|
||||
const name = form.querySelector("input[name='name']").value;
|
||||
const email = form.querySelector("input[name='email']").value;
|
||||
const skills = form.querySelector("select[name='skills']").value;
|
||||
if (name && email) {
|
||||
document.getElementById("cal-booking-place-routingFormPrerender-submit").setAttribute("data-cal-link", `router?form=${seededFormAcmeId}&email=${email}&name=${name}&Location=London&Department=Engineering&Manager=John Doe&Rating=5&skills=${skills}&Email=${email}`);
|
||||
}
|
||||
requestAnimationFrame(updateSubmitButtonLink);
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
<div id="cal-booking-routing-full-prerender">
|
||||
<hr/>
|
||||
<a href="?only=ns:routing-full-prerender&debug=1&[email protected]">Routing Form - Prerender Headless Router itself queuing the form response</a>
|
||||
<a href="?only=ns:routingFormFullPrerender&debug=1&[email protected]">Routing Form - Prerender Headless Router itself queuing the form response</a>
|
||||
<p>1. As page is loading, we prerender the headless router for the email passed as param.email</p>
|
||||
<p>2. Whenever email changes and onblur happens, the prerender is triggered for the new email and previous prerendered modal is removed</p>
|
||||
<p>3. The prerender of the headless router queues the form response and doesn't really record it. When the actual booking is made, the form response is recorded from the queue</p>
|
||||
@@ -174,36 +133,73 @@
|
||||
<p>6. slotsStaleTimeMs is set to 10 seconds(default is 1 minute) and iframeForceReloadThresholdMs is set to 30 seconds(default is 15 minutes) and they are considered from the time when the prerender/modal call was made</p>
|
||||
<p>7. To avoid reaching the iframeForceReloadThresholdMs, user could prerender the router again and again judiciously</p>
|
||||
</p>
|
||||
<script>
|
||||
window.buildRouterUrl = ({email, formId}) => {
|
||||
return `router?form=${formId}&email=${email}`;
|
||||
}
|
||||
</script>
|
||||
<div class="inline-embed-container">
|
||||
<div id="cal-booking-place-routing-full-prerender">
|
||||
<div class="place"></div>
|
||||
<label for="cal-booking-place-routing-full-prerender-input-email">Email</label>
|
||||
<script>
|
||||
document.write(`<input style="width: 400px" type="email" id="cal-booking-place-routing-full-prerender-input-email" value="${window.params.email ?? ''}" />`)
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<h3><script>
|
||||
document.write(`<button id="cta-routing-full-prerender" data-cal-namespace="routingFormFullPrerender" data-cal-origin="${window.calOrigin}" data-cal-link="${window.buildRouterUrl({email:document.getElementById('cal-booking-place-routing-full-prerender-input-email').value, formId:window.params.formId})}" data-cal-config='{"cal.embed.pageType":"team.event.booking.slots"}'>Demo</button>`)
|
||||
</script></h3>
|
||||
<script>
|
||||
(()=>{
|
||||
if (window.only !== "ns:routing-full-prerender") {
|
||||
<script>
|
||||
(()=>{
|
||||
if (window.only !== "ns:routingFormFullPrerender") {
|
||||
return;
|
||||
}
|
||||
Cal("init", "routingFormFullPrerender", {
|
||||
debug: true,
|
||||
calOrigin: window.calOrigin,
|
||||
});
|
||||
const prerender = ({email, formId}) => {
|
||||
window.routingFormFullPrerender = {
|
||||
buildRouterUrl: ({skills, location, name, email, formId}) => {
|
||||
return `router?form=${formId}&skills=${skills}&Location=${location}&name=${name}&Email=${email}&Rating=5`;
|
||||
},
|
||||
onFormSubmit: (e) => {
|
||||
e.preventDefault();
|
||||
const skills = document.getElementById('cal-booking-place-routingFormFullPrerender-select-skills').value;
|
||||
const location = document.getElementById('cal-booking-place-routingFormFullPrerender-select-location').value;
|
||||
const name = document.getElementById('cal-booking-place-routingFormFullPrerender-input-name').value;
|
||||
const email = document.getElementById('cal-booking-place-routingFormFullPrerender-input-email').value;
|
||||
const routerUrl = window.routingFormFullPrerender.buildRouterUrl({skills, location, name, email, formId: window.params.formId});
|
||||
Cal.ns.routingFormFullPrerender("modal", {
|
||||
calLink: routerUrl,
|
||||
calOrigin: window.calOrigin,
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<div id="cal-booking-place-routingFormFullPrerender">
|
||||
<div class="place"></div>
|
||||
<form id="cal-booking-place-routingFormFullPrerender-form" onsubmit="window.routingFormFullPrerender.onFormSubmit(event)">
|
||||
<label for="cal-booking-place-routingFormFullPrerender-input-name">Name</label>
|
||||
<input required style="width: 400px" type="text" id="cal-booking-place-routingFormFullPrerender-input-name" placeholder="John Doe" />
|
||||
<label for="cal-booking-place-routingFormFullPrerender-input-email">Email</label>
|
||||
<input required style="width: 400px" type="email" id="cal-booking-place-routingFormFullPrerender-input-email" placeholder="[email protected]" />
|
||||
<label for="cal-booking-place-routingFormFullPrerender-select-skills">Skills</label>
|
||||
<select required style="width: 400px" id="cal-booking-place-routingFormFullPrerender-select-skills">
|
||||
<option value="">Select a skill</option>
|
||||
<option value="JavaScript">JavaScript</option>
|
||||
<option value="React">React</option>
|
||||
<option value="Node.js">Node.js</option>
|
||||
<option value="Python">Python</option>
|
||||
<option value="Sales">Sales</option>
|
||||
</select>
|
||||
|
||||
<label for="cal-booking-place-routingFormFullPrerender-select-location">Location</label>
|
||||
<select required style="width: 400px" id="cal-booking-place-routingFormFullPrerender-select-location">
|
||||
<option value="">Select a location</option>
|
||||
<option value="New York">New York</option>
|
||||
<option value="London">London</option>
|
||||
<option value="Tokyo">Tokyo</option>
|
||||
<option value="Berlin">Berlin</option>
|
||||
<option value="Remote">Remote</option>
|
||||
</select>
|
||||
<button type="submit" id="cta-routingFormFullPrerender">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(()=>{
|
||||
const prerender = ({skills, location, email, formId}) => {
|
||||
Cal.ns.routingFormFullPrerender("prerender", {
|
||||
// Email will be automatically passed as query param
|
||||
calLink: window.buildRouterUrl({email, formId}),
|
||||
calLink: window.routingFormFullPrerender.buildRouterUrl({skills, location, email, formId}),
|
||||
type: "modal",
|
||||
pageType: "team.event.booking.slots",
|
||||
options: {
|
||||
@@ -212,26 +208,23 @@
|
||||
},
|
||||
});
|
||||
}
|
||||
document.getElementById('cal-booking-place-routing-full-prerender-input-email').onchange = function onEmailChange(e) {
|
||||
const element = e.target;
|
||||
const email = element.validity.valid ? element.value : null;
|
||||
if (!email) {
|
||||
|
||||
function onSelectChange(e) {
|
||||
const skills = document.getElementById('cal-booking-place-routingFormFullPrerender-select-skills').value;
|
||||
const location = document.getElementById('cal-booking-place-routingFormFullPrerender-select-location').value;
|
||||
const email = document.getElementById('cal-booking-place-routingFormFullPrerender-input-email').value;
|
||||
function areFieldRequiredbyRoutingFormAvailable() {
|
||||
return skills && location;
|
||||
}
|
||||
|
||||
if (!areFieldRequiredbyRoutingFormAvailable()) {
|
||||
return;
|
||||
}
|
||||
function updateCtaLink(email) {
|
||||
const element = document.getElementById('cta-routing-full-prerender');
|
||||
const currentLink = element.getAttribute('data-cal-link');
|
||||
const currentLinkObject = new URL(currentLink, 'https://example.com');
|
||||
currentLinkObject.searchParams.set('email', email);
|
||||
element.setAttribute('data-cal-link', currentLinkObject.pathname + currentLinkObject.search);
|
||||
}
|
||||
updateCtaLink(email);
|
||||
prerender({email, formId:window.params.formId});
|
||||
|
||||
prerender({skills, location, email, formId: window.params.formId});
|
||||
}
|
||||
if (!window.params.email || !window.params.formId) {
|
||||
alert('Pass param.email and param.formId query params')
|
||||
}
|
||||
prerender({email:window.params.email, formId:window.params.formId});
|
||||
document.getElementById('cal-booking-place-routingFormFullPrerender-select-skills').onchange = onSelectChange;
|
||||
document.getElementById('cal-booking-place-routingFormFullPrerender-select-location').onchange = onSelectChange;
|
||||
})();
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -19,6 +19,7 @@ import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomain
|
||||
import { isAuthorizedToViewFormOnOrgDomain } from "@calcom/features/routing-forms/lib/isAuthorizedToViewForm";
|
||||
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import { RoutingFormRepository } from "@calcom/lib/server/repository/routingForm";
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
@@ -179,6 +180,9 @@ const _getRoutedUrl = async (context: Pick<GetServerSidePropsContext, "query" |
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
log.error("Error handling the response", safeStringify(e));
|
||||
throw new Error("Error handling the response");
|
||||
}
|
||||
|
||||
// TODO: To be done using sentry tracing
|
||||
|
||||
Reference in new issue
Block a user