|
| 1 | +import type { Metadata } from "next"; |
| 2 | +import { headers as nextHeaders, cookies as nextCookies } from "next/headers"; |
| 3 | +import Script from "next/script"; |
| 4 | +import React from "react"; |
| 5 | + |
| 6 | +import { getLocale } from "@calcom/features/auth/lib/getLocale"; |
| 7 | +import { IS_PRODUCTION } from "@calcom/lib/constants"; |
| 8 | + |
| 9 | +import "../styles/globals.css"; |
| 10 | + |
| 11 | +export const metadata: Metadata = { |
| 12 | + icons: { |
| 13 | + icon: [ |
| 14 | + { |
| 15 | + sizes: "32x32", |
| 16 | + url: "/api/logo?type=favicon-32", |
| 17 | + }, |
| 18 | + { |
| 19 | + sizes: "16x16", |
| 20 | + url: "/api/logo?type=favicon-16", |
| 21 | + }, |
| 22 | + ], |
| 23 | + apple: { |
| 24 | + sizes: "180x180", |
| 25 | + url: "/api/logo?type=apple-touch-icon", |
| 26 | + }, |
| 27 | + other: [ |
| 28 | + { |
| 29 | + url: "/safari-pinned-tab.svg", |
| 30 | + rel: "mask-icon", |
| 31 | + }, |
| 32 | + ], |
| 33 | + }, |
| 34 | + manifest: "/site.webmanifest", |
| 35 | + themeColor: [ |
| 36 | + { media: "(prefers-color-scheme: light)", color: "#f9fafb" }, |
| 37 | + { media: "(prefers-color-scheme: dark)", color: "#1C1C1C" }, |
| 38 | + ], |
| 39 | + other: { |
| 40 | + "msapplication-TileColor": "#000000", |
| 41 | + }, |
| 42 | +}; |
| 43 | + |
| 44 | +const getInitialProps = async ( |
| 45 | + url: string, |
| 46 | + headers: ReturnType<typeof nextHeaders>, |
| 47 | + cookies: ReturnType<typeof nextCookies> |
| 48 | +) => { |
| 49 | + const { pathname, searchParams } = new URL(url); |
| 50 | + |
| 51 | + const isEmbed = pathname.endsWith("/embed") || (searchParams?.get("embedType") ?? null) !== null; |
| 52 | + const embedColorScheme = searchParams?.get("ui.color-scheme"); |
| 53 | + |
| 54 | + // @ts-expect-error we cannot access ctx.req in app dir, however headers and cookies are only properties needed to extract the locale |
| 55 | + const newLocale = await getLocale({ headers, cookies }); |
| 56 | + let direction = "ltr"; |
| 57 | + |
| 58 | + try { |
| 59 | + const intlLocale = new Intl.Locale(newLocale); |
| 60 | + // @ts-expect-error INFO: Typescript does not know about the Intl.Locale textInfo attribute |
| 61 | + direction = intlLocale.textInfo?.direction; |
| 62 | + } catch (e) { |
| 63 | + console.error(e); |
| 64 | + } |
| 65 | + |
| 66 | + return { isEmbed, embedColorScheme, locale: newLocale, direction }; |
| 67 | +}; |
| 68 | + |
| 69 | +export default async function RootLayout({ children }: { children: React.ReactNode }) { |
| 70 | + const headers = nextHeaders(); |
| 71 | + const cookies = nextCookies(); |
| 72 | + |
| 73 | + const fullUrl = headers.get("x-url") ?? ""; |
| 74 | + const nonce = headers.get("x-csp") ?? ""; |
| 75 | + |
| 76 | + const { locale, direction, isEmbed, embedColorScheme } = await getInitialProps(fullUrl, headers, cookies); |
| 77 | + return ( |
| 78 | + <html |
| 79 | + lang={locale} |
| 80 | + dir={direction} |
| 81 | + style={embedColorScheme ? { colorScheme: embedColorScheme as string } : undefined}> |
| 82 | + <head nonce={nonce}> |
| 83 | + {!IS_PRODUCTION && process.env.VERCEL_ENV === "preview" && ( |
| 84 | + // eslint-disable-next-line @next/next/no-sync-scripts |
| 85 | + <Script |
| 86 | + data-project-id="KjpMrKTnXquJVKfeqmjdTffVPf1a6Unw2LZ58iE4" |
| 87 | + src="https://snippet.meticulous.ai/v1/stagingMeticulousSnippet.js" |
| 88 | + /> |
| 89 | + )} |
| 90 | + </head> |
| 91 | + <body |
| 92 | + className="dark:bg-darkgray-50 desktop-transparent bg-subtle antialiased" |
| 93 | + style={ |
| 94 | + isEmbed |
| 95 | + ? { |
| 96 | + background: "transparent", |
| 97 | + // Keep the embed hidden till parent initializes and |
| 98 | + // - gives it the appropriate styles if UI instruction is there. |
| 99 | + // - gives iframe the appropriate height(equal to document height) which can only be known after loading the page once in browser. |
| 100 | + // - Tells iframe which mode it should be in (dark/light) - if there is a a UI instruction for that |
| 101 | + visibility: "hidden", |
| 102 | + } |
| 103 | + : {} |
| 104 | + }> |
| 105 | + {children} |
| 106 | + </body> |
| 107 | + </html> |
| 108 | + ); |
| 109 | +} |
0 commit comments