Embedded Routing Forms - Part1 (#3530)

* Support dark theme in routing form

* Fix Embed detection

* Add routing form embed example

* Better rendering support in dark mode for react-select

* Fix more theme issues

* Added test for Routing Form Embed

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Hariom Balharaandkodiakhq[bot] authored and GitHub committed 2022-07-28 10:50:25 +00:00
1 parent e871781079
commit 1be5510c5e
15 files changed
+447 -135

No files matched your search

+6
View File
@@ -36,6 +36,12 @@ Make `dist/embed.umd.js` servable on URL <http://cal.com/embed.js>
- Hot reload doesn't work with CSS files in the way we use vite.
## Steps to make a page compatiable with Embed
- Define `main` class on the element that has the entire content of the page with no auto margins
- Adding `main` class allows iframe height to adjust according to it, making sure that the content within `main` is visible without scroll as long as device dimensions permits it.
- It also becomes the area beyond which if user clicks, modal-box would close.
## Known Bugs and Upcoming Improvements
- Unsupported Browsers and versions. Documenting them and gracefully handling that.
+59 -7
View File
@@ -10,9 +10,9 @@
const url = new URL(document.URL);
// Only run the example specified by only=, avoids distraction and faster to test.
const only = url.searchParams.get("only");
const namespace = only ? only.replace("ns:",""): null
if (namespace) {
location.hash="#cal-booking-place-" + namespace + "-iframe"
const elementIdentifier = only ? only.replace("ns:",""): null
if (elementIdentifier) {
location.hash="#cal-booking-place-" + elementIdentifier + "-iframe"
}
})()
</script>
@@ -89,6 +89,8 @@
<button data-cal-namespace="popupTeamLinkDarkTheme" data-cal-config='{"theme":"dark"}' data-cal-link="team/seeded-team/collective-seeded-team-event">Book with Test Team[Dark Theme]</button>
<button data-cal-namespace="popupTeamLinksList" data-cal-link="team/seeded-team/">See Team Links [Auto Theme]</button>
<button data-cal-namespace="popupPaidEvent" data-cal-link="pro/paid">Book Paid Event [Auto Theme]</button>
<button data-cal-namespace="routingFormAuto" data-cal-link="forms/948ae412-d995-4865-875a-48302588de03">Book through Routing Form [Auto Theme]</button>
<button data-cal-namespace="routingFormDark" data-cal-config='{"theme":"dark"}' data-cal-link="forms/948ae412-d995-4865-875a-48302588de03">Book through Routing Form [Dark Theme]</button>
<div>
<h2>Embed for Pages behind authentication</h2>
<button data-cal-namespace="upcomingBookings" data-cal-config='{"theme":"dark"}' data-cal-link="bookings/upcoming">Show Upcoming Bookings</button>
@@ -189,6 +191,22 @@
</div>
</div>
</div>
<div class="debug" id="cal-booking-place-inline-routing-form">
<h2>Inline Routing Form</h2>
<div>
<i><a href="?only=inline-routing-form">Test in Zen Mode</a></i>
</div>
<i class="last-action">
<i>You would see last Booking page action in my place</i>
</i>
<div style="display:flex;align-items: center;">
<h2 style="width: 30%">
On the right side you can book a team meeting =>
</h2>
<div style="width: 70%" class="place">
</div>
</div>
</div>
<script>
const callback = function (e) {
@@ -380,6 +398,28 @@
calLink: "free",
});
}
if (!only || only === "inline-routing-form") {
Cal('init', 'inline-routing-form', {
debug: 1,
origin: "http://localhost:3000",
})
Cal.ns['inline-routing-form'](
[
"inline",
{
elementOrSelector: "#cal-booking-place-inline-routing-form .place",
calLink: "forms/9a7e8801-2f34-45ae-aa79-51859766a860",
config: {
iframeAttrs: {
id: "cal-booking-place-inline-routing-form-iframe"
},
}
},
],
);
}
Cal('init', 'popupDarkTheme', {
debug: 1,
origin: "http://localhost:3000",
@@ -416,11 +456,23 @@
debug: 1,
origin: "http://localhost:3000",
});
if (!only || only == "ns:floatingButton") {
Cal.ns.floatingButton("floatingButton", {
calLink: "pro"
Cal('init', 'routingFormAuto', {
debug: 1,
origin: "http://localhost:3000",
})
}
Cal('init', 'routingFormDark', {
debug: 1,
origin: "http://localhost:3000",
})
if (!only || only == "ns:floatingButton") {
Cal.ns.floatingButton("floatingButton", {
calLink: "pro"
})
}
</script>
<script></script>
</body>
@@ -71,6 +71,7 @@ export type ExpectedUrlDetails = {
};
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace PlaywrightTest {
//FIXME: how to restrict it to Frame only
interface Matchers<R> {
@@ -78,7 +79,7 @@ declare global {
calNamespace: string,
getActionFiredDetails: Function,
expectedUrlDetails?: ExpectedUrlDetails
): R;
): Promise<R>;
}
}
}
@@ -20,7 +20,7 @@ test("should open embed iframe on click - Configured with light theme", async ({
embedIframe = await getEmbedIframe({ page, pathname: "/free" });
expect(embedIframe).toBeEmbedCalLink(calNamespace, getActionFiredDetails, {
await expect(embedIframe).toBeEmbedCalLink(calNamespace, getActionFiredDetails, {
pathname: "/free",
});
expect(await page.screenshot()).toMatchSnapshot("event-types-list.png");
@@ -39,3 +39,28 @@ todo("Floating Button Test with Dark Theme");
todo("Floating Button Test with Light Theme");
todo("Add snapshot test for embed iframe");
test("should open Routing Forms embed on click", async ({
page,
addEmbedListeners,
getActionFiredDetails,
}) => {
await deleteAllBookingsByEmail("[email protected]");
const calNamespace = "routingFormAuto";
await addEmbedListeners(calNamespace);
await page.goto("/?only=prerender-test");
let embedIframe = await getEmbedIframe({ page, pathname: "/forms/948ae412-d995-4865-875a-48302588de03" });
expect(embedIframe).toBeFalsy();
await page.click(
`[data-cal-namespace=${calNamespace}][data-cal-link="forms/948ae412-d995-4865-875a-48302588de03"]`
);
embedIframe = await getEmbedIframe({ page, pathname: "/forms/948ae412-d995-4865-875a-48302588de03" });
if (!embedIframe) {
throw new Error("Routing Form embed iframe not found");
}
await expect(embedIframe).toBeEmbedCalLink(calNamespace, getActionFiredDetails, {
pathname: "/forms/948ae412-d995-4865-875a-48302588de03",
});
await expect(embedIframe.locator("text=Seeded Form - Pro")).toBeVisible();
});
@@ -16,6 +16,8 @@ declare global {
CalComPageStatus: string;
CalComPlan: string;
isEmbed: () => boolean;
getEmbedNamespace: () => string | null;
getEmbedTheme: () => "dark" | "light" | null;
}
}
@@ -197,8 +199,7 @@ function getNamespace() {
return embedStore.namespace;
}
if (isBrowser) {
const url = new URL(document.URL);
const namespace = url.searchParams.get("embed");
const namespace = window.getEmbedNamespace();
embedStore.namespace = namespace;
return namespace;
}
@@ -219,7 +220,7 @@ export const useIsEmbed = () => {
// We can't simply return isEmbed() from this method.
// isEmbed() returns different values on server and browser, which messes up the hydration.
// TODO: We can avoid using document.URL and instead use Router.
const [_isEmbed, setIsEmbed] = useState<boolean | null>(null);
const [isEmbed, setIsEmbed] = useState<boolean | null>(null);
useEffect(() => {
const namespace = getNamespace();
const _isValidNamespace = isValidNamespace(namespace);
@@ -230,7 +231,7 @@ export const useIsEmbed = () => {
}
setIsEmbed(window.isEmbed());
}, []);
return _isEmbed;
return isEmbed;
};
export const useEmbedType = () => {
@@ -369,7 +370,7 @@ function keepParentInformedAboutDimensionChanges() {
if (isBrowser) {
const url = new URL(document.URL);
embedStore.theme = (url.searchParams.get("theme") || "auto") as UiConfig["theme"];
embedStore.theme = (window.getEmbedTheme() || "auto") as UiConfig["theme"];
if (url.searchParams.get("prerender") !== "true" && window.isEmbed()) {
log("Initializing embed-iframe");
// HACK