diff --git a/apps/web/components/Embed.tsx b/apps/web/components/Embed.tsx index 94c23ee087..2c92492da9 100644 --- a/apps/web/components/Embed.tsx +++ b/apps/web/components/Embed.tsx @@ -2,7 +2,7 @@ import { ArrowLeftIcon, ChevronRightIcon, CodeIcon, EyeIcon, SunIcon } from "@he import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@radix-ui/react-collapsible"; import classNames from "classnames"; import { useRouter } from "next/router"; -import { forwardRef, MutableRefObject, useRef, useState } from "react"; +import { createRef, forwardRef, MutableRefObject, RefObject, useRef, useState } from "react"; import { components, ControlProps } from "react-select"; import { useLocale } from "@calcom/lib/hooks/useLocale"; @@ -628,7 +628,14 @@ const EmbedTypeCodeAndPreviewDialogContent = ({ const { t } = useLocale(); const router = useRouter(); const iframeRef = useRef(null); - const embedCodeRef = useRef(null); + const embedCodeRefs: Record> = {}; + tabs + .filter((tab) => tab.type === "code") + .forEach((codeTab) => { + embedCodeRefs[codeTab.name] = createRef(); + }); + + const refOfEmbedCodesRefs = useRef(embedCodeRefs); const embed = embeds.find((embed) => embed.type === embedType); const { data: eventType, isLoading } = trpc.useQuery([ @@ -1056,7 +1063,7 @@ const EmbedTypeCodeAndPreviewDialogContent = ({ embedType={embedType} calLink={calLink} previewState={previewState} - ref={embedCodeRef}> + ref={refOfEmbedCodesRefs.current[tab.name]}> ) : ( { - if (!embedCodeRef.current) { + const currentTabCodeEl = refOfEmbedCodesRefs.current[tab.name].current; + if (!currentTabCodeEl) { return; } - navigator.clipboard.writeText(embedCodeRef.current.value); + navigator.clipboard.writeText(currentTabCodeEl.value); showToast(t("code_copied"), "success"); }}> {t("copy_code")}