diff --git a/apps/web/components/Embed.tsx b/apps/web/components/Embed.tsx index 5e2944cb7e..f906aed757 100644 --- a/apps/web/components/Embed.tsx +++ b/apps/web/components/Embed.tsx @@ -22,6 +22,7 @@ import { useNonEmptyScheduleDays } from "@calcom/features/schedules"; import { useSlotsForDate } from "@calcom/features/schedules/lib/use-schedule/useSlotsForDate"; import { APP_NAME, CAL_URL, EMBED_LIB_URL, IS_SELF_HOSTED, WEBAPP_URL } from "@calcom/lib/constants"; import { weekdayToWeekIndex } from "@calcom/lib/date-fns"; +import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { BookerLayouts } from "@calcom/prisma/zod-utils"; import type { RouterOutputs } from "@calcom/trpc/react"; @@ -54,8 +55,14 @@ const enum Theme { dark = "dark", } -const EMBED_CAL_ORIGIN = WEBAPP_URL; -const EMBED_CAL_JS_URL = `${WEBAPP_URL}/embed/embed.js`; +// Preview HTML and embed lib doesn't need org context. They are static per instance +const EMBED_PREVIEW_HTML_URL = `${WEBAPP_URL}/embed/preview.html`; +const embedLibUrl = EMBED_LIB_URL; + +const useEmbedCalOrigin = () => { + const bookerUrl = useBookerUrl(); + return bookerUrl; +}; type PreviewState = { inline: { @@ -195,16 +202,18 @@ const getEmbedUIInstructionString = ({ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any -const Codes: Record string>> = { +const Codes = { react: { inline: ({ calLink, uiInstructionCode, previewState, + embedCalOrigin, }: { calLink: string; uiInstructionCode: string; previewState: PreviewState; + embedCalOrigin: string; }) => { const width = getDimension(previewState.inline.width); const height = getDimension(previewState.inline.height); @@ -224,8 +233,8 @@ export default function MyApp() { ${previewState.layout ? "config={{layout: '" + previewState.layout + "'}}" : ""}${ IS_SELF_HOSTED ? ` - calOrigin="${EMBED_CAL_ORIGIN}" - calJsUrl="${EMBED_CAL_JS_URL}"` + calOrigin="${embedCalOrigin}" + calJsUrl="${embedLibUrl}"` : "" } />; @@ -244,7 +253,7 @@ import { useEffect } from "react"; export default function App() { useEffect(()=>{ (async function () { - const cal = await getCalApi(${IS_SELF_HOSTED ? `"${EMBED_CAL_JS_URL}"` : ""}); + const cal = await getCalApi(${IS_SELF_HOSTED ? `"${embedLibUrl}"` : ""}); cal("floatingButton", ${floatingButtonArg}); ${uiInstructionCode} })(); @@ -255,10 +264,12 @@ export default function App() { calLink, uiInstructionCode, previewState, + embedCalOrigin, }: { calLink: string; uiInstructionCode: string; previewState: PreviewState; + embedCalOrigin: string; }) => { return code` import { getCalApi } from "@calcom/embed-react"; @@ -266,12 +277,12 @@ import { useEffect } from "react"; export default function App() { useEffect(()=>{ (async function () { - const cal = await getCalApi(${IS_SELF_HOSTED ? `"${EMBED_CAL_JS_URL}"` : ""}); + const cal = await getCalApi(${IS_SELF_HOSTED ? `"${embedLibUrl}"` : ""}); ${uiInstructionCode} })(); }, []) return