2021-09-09 13:51:06 +00:00
|
|
|
import Document, { DocumentContext, Head, Html, Main, NextScript, DocumentProps } from "next/document";
|
2022-12-08 23:39:15 +00:00
|
|
|
import Script from "next/script";
|
2021-07-07 19:58:18 +00:00
|
|
|
|
2023-01-03 10:09:05 +00:00
|
|
|
import { getDirFromLang } from "@calcom/lib/i18n";
|
|
|
|
|
2021-09-09 13:51:06 +00:00
|
|
|
type Props = Record<string, unknown> & DocumentProps;
|
|
|
|
|
2022-07-28 10:50:25 +00:00
|
|
|
function toRunBeforeReactOnClient() {
|
2022-12-07 20:08:34 +00:00
|
|
|
const calEmbedMode = typeof new URL(document.URL).searchParams.get("embed") === "string";
|
|
|
|
/* Iframe Name */
|
|
|
|
window.name.includes("cal-embed");
|
2022-08-16 04:18:13 +00:00
|
|
|
|
2022-07-28 10:50:25 +00:00
|
|
|
window.isEmbed = () => {
|
2022-10-19 21:25:03 +00:00
|
|
|
// Once an embed mode always an embed mode
|
2022-08-16 04:18:13 +00:00
|
|
|
return calEmbedMode;
|
2022-07-28 10:50:25 +00:00
|
|
|
};
|
2022-08-16 04:18:13 +00:00
|
|
|
|
2022-08-13 11:04:57 +00:00
|
|
|
window.resetEmbedStatus = () => {
|
2022-08-16 04:18:13 +00:00
|
|
|
try {
|
|
|
|
// eslint-disable-next-line @calcom/eslint/avoid-web-storage
|
|
|
|
window.sessionStorage.removeItem("calEmbedMode");
|
|
|
|
} catch (e) {}
|
2022-08-13 11:04:57 +00:00
|
|
|
};
|
2022-07-28 10:50:25 +00:00
|
|
|
|
|
|
|
window.getEmbedTheme = () => {
|
|
|
|
const url = new URL(document.URL);
|
|
|
|
return url.searchParams.get("theme") as "dark" | "light";
|
|
|
|
};
|
|
|
|
|
|
|
|
window.getEmbedNamespace = () => {
|
|
|
|
const url = new URL(document.URL);
|
|
|
|
const namespace = url.searchParams.get("embed");
|
|
|
|
return namespace;
|
|
|
|
};
|
2022-10-14 10:10:54 +00:00
|
|
|
|
|
|
|
window.isPageOptimizedForEmbed = () => {
|
|
|
|
// Those pages are considered optimized, which know at backend that they are rendering for embed.
|
|
|
|
// Such pages can be shown straightaway without a loader for a better embed experience
|
|
|
|
return location.pathname.includes("forms/");
|
|
|
|
};
|
2022-07-28 10:50:25 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 13:51:06 +00:00
|
|
|
class MyDocument extends Document<Props> {
|
|
|
|
static async getInitialProps(ctx: DocumentContext) {
|
2022-10-19 21:25:03 +00:00
|
|
|
const isEmbed = ctx.asPath?.includes("/embed") || ctx.asPath?.includes("embedType=");
|
2021-07-07 19:58:18 +00:00
|
|
|
const initialProps = await Document.getInitialProps(ctx);
|
2022-10-19 21:25:03 +00:00
|
|
|
return { isEmbed, ...initialProps };
|
2021-07-07 19:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2022-07-12 14:18:53 +00:00
|
|
|
const { locale } = this.props.__NEXT_DATA__;
|
2023-01-03 10:09:05 +00:00
|
|
|
const dir = getDirFromLang(locale);
|
2021-07-07 19:58:18 +00:00
|
|
|
return (
|
2022-02-01 22:17:37 +00:00
|
|
|
<Html lang={locale} dir={dir}>
|
2021-08-03 09:32:37 +00:00
|
|
|
<Head>
|
2021-08-03 09:39:06 +00:00
|
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
|
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
|
|
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
|
|
|
|
<link rel="manifest" href="/site.webmanifest" />
|
|
|
|
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#000000" />
|
|
|
|
<meta name="msapplication-TileColor" content="#ff0000" />
|
|
|
|
<meta name="theme-color" content="#ffffff" />
|
2022-07-27 02:24:00 +00:00
|
|
|
<link
|
|
|
|
rel="preload"
|
|
|
|
href="/fonts/Inter-roman.var.woff2"
|
|
|
|
as="font"
|
|
|
|
type="font/woff2"
|
|
|
|
crossOrigin="anonymous"
|
|
|
|
/>
|
|
|
|
<link rel="preload" href="/fonts/cal.ttf" as="font" type="font/ttf" crossOrigin="anonymous" />
|
2022-08-24 20:18:42 +00:00
|
|
|
{/* Define isEmbed here so that it can be shared with App(embed-iframe) as well as the following code to change background and hide body
|
2022-07-28 10:50:25 +00:00
|
|
|
Persist the embed mode in sessionStorage because query param might get lost during browsing.
|
|
|
|
*/}
|
2022-12-08 23:39:15 +00:00
|
|
|
<Script
|
|
|
|
id="run-before-client"
|
|
|
|
strategy="beforeInteractive"
|
2022-07-12 14:18:53 +00:00
|
|
|
dangerouslySetInnerHTML={{
|
2022-07-28 10:50:25 +00:00
|
|
|
__html: `(${toRunBeforeReactOnClient.toString()})()`,
|
2022-07-12 14:18:53 +00:00
|
|
|
}}
|
|
|
|
/>
|
2021-08-03 09:32:37 +00:00
|
|
|
</Head>
|
2022-03-31 08:45:47 +00:00
|
|
|
|
2022-10-19 21:25:03 +00:00
|
|
|
<body
|
2023-01-17 16:36:06 +00:00
|
|
|
className="dark:bg-darkgray-50 desktop-transparent bg-gray-100 antialiased"
|
2022-10-19 21:25:03 +00:00
|
|
|
style={
|
|
|
|
this.props.isEmbed
|
|
|
|
? {
|
|
|
|
background: "transparent",
|
|
|
|
// Keep the embed hidden till parent initializes and
|
|
|
|
// - gives it the appropriate styles if UI instruction is there.
|
|
|
|
// - gives iframe the appropriate height(equal to document height) which can only be known after loading the page once in browser.
|
|
|
|
// - Tells iframe which mode it should be in (dark/light) - if there is a a UI instruction for that
|
|
|
|
visibility: "hidden",
|
|
|
|
}
|
|
|
|
: {}
|
|
|
|
}>
|
2021-07-07 19:58:18 +00:00
|
|
|
<Main />
|
|
|
|
<NextScript />
|
|
|
|
</body>
|
|
|
|
</Html>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MyDocument;
|