[Feature]Booking Embed (#2227)

This commit is contained in:
Hariom Balhara authored and GitHub committed 2022-03-31 09:45:47 +01:00
1 parent 4e9c3be598
commit 4a58da62d6
39 files changed
+1740 -22

No files matched your search

+14
View File
@@ -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>
```
+1
View File
@@ -0,0 +1 @@
/// <reference types="vite/client" />
+10
View File
@@ -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>
+17
View File
@@ -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"
}
}
+33
View File
@@ -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;
}
+24
View File
@@ -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"));
+11
View File
@@ -0,0 +1,11 @@
{
"extends": "@calcom/tsconfig/base.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node",
"baseUrl": ".",
"jsx": "preserve"
},
"include": ["."],
"exclude": ["dist", "build", "node_modules"]
}