Scheduling infrastructure for absolutely everyone.
avoid ref overriding because now we are rendering all tab codes at once (#3079)
Hariom Balharaabe090881ae0
diff --git a/apps/web/components/Embed.tsx b/apps/web/components/Embed.tsxindex 94c23ee0877..2c92492da9a 100644--- a/apps/web/components/Embed.tsx+++ b/apps/web/components/Embed.tsx@@ -2,7 +2,7 @@ import { ArrowLeftIcon, ChevronRightIcon, CodeIcon, EyeIcon, SunIcon } from "@heimport { 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<HTMLIFrameElement>(null);- const embedCodeRef = useRef<HTMLTextAreaElement>(null);+ const embedCodeRefs: Record<typeof tabs[0]["name"], RefObject<HTMLTextAreaElement>> = {};+ 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}></tab.Component>+ ref={refOfEmbedCodesRefs.current[tab.name]}></tab.Component>) : (<tab.ComponentembedType={embedType}@@ -1073,10 +1080,11 @@ const EmbedTypeCodeAndPreviewDialogContent = ({<Buttontype="submit"onClick={() => {- 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")}