diff --git a/apps/web/components/eventtype/EventTypeSingleLayout.tsx b/apps/web/components/eventtype/EventTypeSingleLayout.tsx index ba369f9c80..f802055a01 100644 --- a/apps/web/components/eventtype/EventTypeSingleLayout.tsx +++ b/apps/web/components/eventtype/EventTypeSingleLayout.tsx @@ -322,6 +322,7 @@ function EventTypeSingleLayout({ StartIcon={Code} color="secondary" variant="icon" + namespace={eventType.slug} tooltip={t("embed")} tooltipSide="bottom" tooltipOffset={4} diff --git a/apps/web/pages/event-types/index.tsx b/apps/web/pages/event-types/index.tsx index a83b3d2e2e..312b3d1d89 100644 --- a/apps/web/pages/event-types/index.tsx +++ b/apps/web/pages/event-types/index.tsx @@ -507,6 +507,7 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL {!isManagedEventType && ( ; const Cal = function Cal(props: CalProps) { - const { calLink, calOrigin, config, initConfig = {}, embedJsUrl, ...restProps } = props; + const { calLink, calOrigin, namespace = "", config, initConfig = {}, embedJsUrl, ...restProps } = props; if (!calLink) { throw new Error("calLink is required"); } @@ -31,16 +32,28 @@ const Cal = function Cal(props: CalProps) { } initializedRef.current = true; const element = ref.current; - Cal("init", { - ...initConfig, - origin: calOrigin, - }); - Cal("inline", { - elementOrSelector: element, - calLink, - config, - }); - }, [Cal, calLink, config, calOrigin, initConfig]); + if (namespace) { + Cal("init", namespace, { + ...initConfig, + origin: calOrigin, + }); + Cal.ns[namespace]("inline", { + elementOrSelector: element, + calLink, + config, + }); + } else { + Cal("init", { + ...initConfig, + origin: calOrigin, + }); + Cal("inline", { + elementOrSelector: element, + calLink, + config, + }); + } + }, [Cal, calLink, config, namespace, calOrigin, initConfig]); if (!Cal) { return null; diff --git a/packages/features/embed/Embed.tsx b/packages/features/embed/Embed.tsx index 50e023ba76..fcaa08a4b6 100644 --- a/packages/features/embed/Embed.tsx +++ b/packages/features/embed/Embed.tsx @@ -498,12 +498,14 @@ const EmbedTypeCodeAndPreviewDialogContent = ({ embedType, embedUrl, tabs, + namespace, eventTypeHideOptionDisabled, types, }: { embedType: EmbedType; embedUrl: string; tabs: EmbedTabs; + namespace: string; eventTypeHideOptionDisabled: boolean; types: EmbedTypes; }) => { @@ -1009,6 +1011,7 @@ const EmbedTypeCodeAndPreviewDialogContent = ({
{tab.type === "code" ? ( ) : ( { const searchParams = useCompatSearchParams(); - const embedUrl = searchParams?.get("embedUrl") as string; + const embedUrl = (searchParams?.get("embedUrl") || "") as string; + const namespace = (searchParams?.get("namespace") || "") as string; return ( {!searchParams?.get("embedType") ? ( @@ -1106,6 +1111,7 @@ export const EmbedDialog = ({ = { embedUrl: string; + namespace: string; children?: React.ReactNode; className?: string; as?: T; @@ -1129,6 +1136,7 @@ export const EmbedButton = ({ className = "", as, eventId, + namespace, ...props }: EmbedButtonProps & React.ComponentPropsWithoutRef) => { const { goto } = useRouterHelpers(); @@ -1137,6 +1145,7 @@ export const EmbedButton = ({ goto({ dialog: "embed", eventId: eventId ? eventId.toString() : "", + namespace, embedUrl, }); }; diff --git a/packages/features/embed/lib/EmbedCodes.tsx b/packages/features/embed/lib/EmbedCodes.tsx index 53ca519e94..105544ece7 100644 --- a/packages/features/embed/lib/EmbedCodes.tsx +++ b/packages/features/embed/lib/EmbedCodes.tsx @@ -2,6 +2,7 @@ import { CAL_URL, IS_SELF_HOSTED, WEBAPP_URL } from "@calcom/lib/constants"; import type { PreviewState } from "../types"; import { embedLibUrl } from "./constants"; +import { getApiName } from "./getApiName"; import { getDimension } from "./getDimension"; export const doWeNeedCalOriginProp = (embedCalOrigin: string) => { @@ -18,14 +19,17 @@ export const Codes = { uiInstructionCode, previewState, embedCalOrigin, + namespace, }: { calLink: string; uiInstructionCode: string; previewState: PreviewState; embedCalOrigin: string; + namespace: string; }) => { const width = getDimension(previewState.inline.width); const height = getDimension(previewState.inline.height); + const namespaceProp = `${namespace ? `namespace="${namespace}"` : ""}`; return code` import Cal, { getCalApi } from "@calcom/embed-react"; import { useEffect } from "react"; @@ -36,21 +40,23 @@ export const Codes = { ${uiInstructionCode} })(); }, []) - return ; };`; }, "floating-popup": ({ floatingButtonArg, uiInstructionCode, + namespace, }: { floatingButtonArg: string; uiInstructionCode: string; + namespace: string; }) => { return code` import { getCalApi } from "@calcom/embed-react"; @@ -59,7 +65,7 @@ export const Codes = { useEffect(()=>{ (async function () { const cal = await getCalApi(${IS_SELF_HOSTED ? `"${embedLibUrl}"` : ""}); - cal("floatingButton", ${floatingButtonArg}); + ${getApiName({ namespace, mainApiName: "cal" })}("floatingButton", ${floatingButtonArg}); ${uiInstructionCode} })(); }, []) @@ -70,11 +76,13 @@ export const Codes = { uiInstructionCode, previewState, embedCalOrigin, + namespace, }: { calLink: string; uiInstructionCode: string; previewState: PreviewState; embedCalOrigin: string; + namespace: string; }) => { return code` import { getCalApi } from "@calcom/embed-react"; @@ -86,7 +94,7 @@ export const Codes = { ${uiInstructionCode} })(); }, []) - return