Embed: Strictly type the codebase and fixes a few bugs found (#7536)
* Add strict types * Make it array * Make api consistent and support calOrigin in floatingPopup and modal * Support calOrigin everywhere and fix branding config issue * Fix styles not being uniformly applied across components * Fix unused code
This commit is contained in:
1 parent
4f590ebbf7
commit
5fceee27fe
21 files changed
+1034
-769
No files matched your search
@@ -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="./floating.tsx"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,25 @@
|
||||
/* First make sure that you have installed the package */
|
||||
|
||||
/* If you are using yarn */
|
||||
// yarn add @calcom/embed-react
|
||||
|
||||
/* If you are using npm */
|
||||
// npm install @calcom/embed-react
|
||||
import { useEffect } from "react";
|
||||
import * as React from "react";
|
||||
import ReactDom from "react-dom";
|
||||
|
||||
import { getCalApi } from "./src/index";
|
||||
|
||||
function App() {
|
||||
useEffect(() => {
|
||||
(async function () {
|
||||
const cal = await getCalApi("http://localhost:3000/embed/embed.js");
|
||||
cal("floatingButton", { calLink: "teampro/abc", calOrigin: "http://localhost:3000" });
|
||||
cal("ui", { styles: { branding: { brandColor: "#000000" } }, hideEventTypeDetails: false });
|
||||
})();
|
||||
}, []);
|
||||
return null;
|
||||
}
|
||||
|
||||
ReactDom.render(<App />, document.getElementById("root"));
|
||||
@@ -2,7 +2,7 @@
|
||||
<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>
|
||||
<script type="module" src="./inline.tsx"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import * as React from "react";
|
||||
import { useEffect } from "react";
|
||||
import { useState } from "react";
|
||||
import ReactDom from "react-dom";
|
||||
|
||||
import Cal, { getCalApi } from "./src/index";
|
||||
@@ -46,7 +48,6 @@ function App() {
|
||||
theme: "dark",
|
||||
}}
|
||||
/>
|
||||
<button data-cal-link="pro">Popup</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -11,7 +11,7 @@ type CalProps = {
|
||||
debug?: boolean;
|
||||
uiDebug?: boolean;
|
||||
};
|
||||
config?: any;
|
||||
config?: Record<string, string>;
|
||||
embedJsUrl?: string;
|
||||
} & React.HTMLAttributes<HTMLDivElement>;
|
||||
|
||||
@@ -24,7 +24,7 @@ const Cal = function Cal(props: CalProps) {
|
||||
const Cal = useEmbed(embedJsUrl);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (!Cal || initializedRef.current) {
|
||||
if (!Cal || initializedRef.current || !ref.current) {
|
||||
return;
|
||||
}
|
||||
initializedRef.current = true;
|
||||
|
||||
@@ -5,9 +5,9 @@ import EmbedSnippet from "@calcom/embed-snippet";
|
||||
|
||||
import Cal from "./Cal";
|
||||
|
||||
export const getCalApi = (): Promise<GlobalCal> =>
|
||||
export const getCalApi = (embedJsUrl?: string): Promise<GlobalCal> =>
|
||||
new Promise(function tryReadingFromWindow(resolve) {
|
||||
EmbedSnippet();
|
||||
EmbedSnippet(embedJsUrl);
|
||||
const api = window.Cal;
|
||||
if (!api) {
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"extends": "@calcom/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"module": "ESNext",
|
||||
"target": "ES2015",
|
||||
"moduleResolution": "Node",
|
||||
"baseUrl": ".",
|
||||
"declaration": true,
|
||||
|
||||
Reference in new issue
Block a user