[Feature]Booking Embed (#2227)
This commit is contained in:
1 parent
4e9c3be598
commit
4a58da62d6
39 files changed
+1740
-22
No files matched your search
@@ -0,0 +1,14 @@
|
||||
# cal-react
|
||||
|
||||
Makes the embed available as a React component.
|
||||
|
||||
To add the embed on a webpage built using React. Follow the steps
|
||||
|
||||
```bash
|
||||
yarn add @calcom/embed-react
|
||||
```
|
||||
|
||||
```jsx
|
||||
import Cal from "@calcom/embed-react"
|
||||
<Cal></Cal>
|
||||
```
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
@@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
|
||||
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
|
||||
<script type="module" src="./test-cal.tsx"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@calcom/embed-react",
|
||||
"version": "0.1.0",
|
||||
"description": "Embed Cal Booking anywhere",
|
||||
"scripts": {
|
||||
"dev": "vite --port=3003 --open",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"type-check": "tsc --pretty --noEmit",
|
||||
"lint": "eslint --ext .ts,.js,.tsx,.jsx ./src"
|
||||
},
|
||||
"main": "src/Cal.tsx",
|
||||
"devDependencies": {
|
||||
"vite": "^2.8.6",
|
||||
"eslint": "^8.10.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
import useEmbed from "./useEmbed";
|
||||
|
||||
export default function Cal({
|
||||
calLink,
|
||||
config,
|
||||
embedJsUrl,
|
||||
}: {
|
||||
calLink: string;
|
||||
config?: any;
|
||||
embedJsUrl?: string;
|
||||
}) {
|
||||
const Cal = useEmbed(embedJsUrl);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (!Cal) {
|
||||
return;
|
||||
}
|
||||
Cal("init");
|
||||
Cal("inline", {
|
||||
elementOrSelector: ref.current,
|
||||
calLink,
|
||||
config,
|
||||
});
|
||||
}, [Cal, calLink, config]);
|
||||
|
||||
if (!Cal) {
|
||||
return <div>Loading {calLink}</div>;
|
||||
}
|
||||
|
||||
return <div ref={ref}></div>;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import EmbedSnippet from "@calcom/embed-snippet";
|
||||
|
||||
export default function useEmbed(embedJsUrl?: string) {
|
||||
const [globalCal, setGlobalCal] = useState<ReturnType<typeof EmbedSnippet>>();
|
||||
useEffect(() => {
|
||||
setGlobalCal(() => {
|
||||
return EmbedSnippet(embedJsUrl);
|
||||
});
|
||||
}, []);
|
||||
return globalCal;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import ReactDom from "react-dom";
|
||||
|
||||
import Cal from "@calcom/embed-react";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<>
|
||||
<h1>
|
||||
There is <code>Cal</code> component below me
|
||||
</h1>
|
||||
<Cal
|
||||
embedJsUrl="//localhost:3002/dist/embed.umd.js"
|
||||
calLink="pro"
|
||||
config={{
|
||||
name: "John Doe",
|
||||
email: "[email protected]",
|
||||
notes: "Test Meeting",
|
||||
guests: ["[email protected]"],
|
||||
theme: "dark",
|
||||
}}></Cal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
ReactDom.render(<App></App>, document.getElementById("root"));
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "@calcom/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"baseUrl": ".",
|
||||
"jsx": "preserve"
|
||||
},
|
||||
"include": ["."],
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
}
|
||||
Reference in new issue
Block a user