Improvement: Add React to Embed Snippet Generator (#3018)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
8f86e0b164
commit
a9e519f643
5 files changed
+426
-167
No files matched your search
@@ -3,17 +3,15 @@ import { useEffect, useRef } from "react";
|
||||
|
||||
import useEmbed from "./useEmbed";
|
||||
|
||||
export default function Cal({
|
||||
calLink,
|
||||
calOrigin,
|
||||
config,
|
||||
embedJsUrl,
|
||||
}: {
|
||||
type CalProps = {
|
||||
calOrigin?: string;
|
||||
calLink: string;
|
||||
config?: any;
|
||||
embedJsUrl?: string;
|
||||
}) {
|
||||
} & React.HTMLAttributes<HTMLDivElement>;
|
||||
|
||||
const Cal = function Cal(props: CalProps) {
|
||||
const { calLink, calOrigin, config, embedJsUrl, ...restProps } = props;
|
||||
if (!calLink) {
|
||||
throw new Error("calLink is required");
|
||||
}
|
||||
@@ -39,8 +37,9 @@ export default function Cal({
|
||||
}, [Cal, calLink, config, calOrigin]);
|
||||
|
||||
if (!Cal) {
|
||||
return <div>Loading {calLink}</div>;
|
||||
return <div {...restProps}>Loading {calLink} </div>;
|
||||
}
|
||||
|
||||
return <div ref={ref}></div>;
|
||||
}
|
||||
return <div ref={ref} {...restProps}></div>;
|
||||
};
|
||||
export default Cal;
|
||||
@@ -1,9 +1,11 @@
|
||||
import { CalWindow } from "@calcom/embed-core";
|
||||
import EmbedSnippet from "@calcom/embed-snippet";
|
||||
|
||||
import Cal from "./Cal";
|
||||
|
||||
export const getCalApi = (): Promise<CalWindow["Cal"]> =>
|
||||
new Promise(function tryReadingFromWindow(resolve) {
|
||||
EmbedSnippet();
|
||||
const api = (window as CalWindow).Cal;
|
||||
if (!api) {
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -37,6 +37,7 @@ function App() {
|
||||
<Cal
|
||||
calOrigin="http://localhost:3000"
|
||||
embedJsUrl="//localhost:3000/embed/embed.js"
|
||||
style={{ width: "100%", height: "100%", overflow: "scroll" }}
|
||||
calLink="pro"
|
||||
config={{
|
||||
name: "John Doe",
|
||||
|
||||
Reference in new issue
Block a user