Embed Miscellaneous Improvements and Fixes (#2499)
This commit is contained in:
1 parent
53d7e57142
commit
93c75b5fef
83 files changed
+1139
-746
No files matched your search
@@ -0,0 +1,2 @@
|
||||
.turbo
|
||||
dist
|
||||
@@ -2,4 +2,13 @@
|
||||
|
||||
Embed Cal Link as a React Component
|
||||
|
||||
To know how to use it, follow the steps at <https://docs.cal.com/integrations/embed>
|
||||
To know how to use it, follow the steps at <https://docs.cal.com/integrations/embed>
|
||||
|
||||
TODO
|
||||
|
||||
- Playwright tests.
|
||||
- Need to what these tests should be as embed-core already have tests. We probably just need to verify that embed-core API is called appropriately.
|
||||
- It would probably be better if Playwright tests exist at one place for all embeds.
|
||||
- Distribution
|
||||
- It would be better DX to serve the unbuilt version with JSX, instead of built version with React.createElement calls. But because of WebPack loaders not running on node_modules automatically, it doesn't work automatically.
|
||||
- Right now if a typescript project uses the package, VSCode takes the user to .d.ts files instead of the functions definitions. How to solve it ?
|
||||
@@ -3,18 +3,42 @@
|
||||
"version": "1.0.1",
|
||||
"description": "Embed Cal Link as a React Component",
|
||||
"scripts": {
|
||||
"dev": "vite --port=3003 --open",
|
||||
"build": "vite build",
|
||||
"dev": "vite --port=3101 --open",
|
||||
"tsc": "tsc",
|
||||
"build": "vite build && yarn tsc --emitDeclarationOnly --declarationDir dist",
|
||||
"preview": "vite preview",
|
||||
"prepare": "yarn build",
|
||||
"type-check": "tsc --pretty --noEmit",
|
||||
"lint": "eslint --ext .ts,.js,.tsx,.jsx ./src"
|
||||
"lint": "eslint --ext .ts,.js,.tsx,.jsx ./src",
|
||||
"embed-tests": "yarn playwright test --config=./playwright/config/playwright.config.ts",
|
||||
"embed-tests-quick": "QUICK=true yarn embed-tests"
|
||||
},
|
||||
"main": "src/Cal.tsx",
|
||||
"dependencies": {
|
||||
"@calcom/embed-snippet": "^1.0.0"
|
||||
"main": "./dist/Cal.umd.js",
|
||||
"module": "./dist/Cal.es.js",
|
||||
"types": "./dist/src/index.d.ts",
|
||||
"peerDependencies": {
|
||||
"react": "^17.0.0",
|
||||
"react-dom": "^17.0.0"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/Cal.es.js",
|
||||
"require": "./dist/Cal.umd.js"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "^2.8.6",
|
||||
"eslint": "^8.10.0"
|
||||
"@calcom/embed-snippet": "^1.0.0",
|
||||
"@types/react": "^17.0.0",
|
||||
"@types/react-dom": "^17.0.0",
|
||||
"@vitejs/plugin-react": "^1.3.0",
|
||||
"eslint": "^8.10.0",
|
||||
"vite": "^2.9.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"playwright": "^1.21.1",
|
||||
"typescript": "^4.6.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { PlaywrightTestConfig, devices } from "@playwright/test";
|
||||
import path from "path";
|
||||
|
||||
//TODO: Move the common config to embed-playwright-config and let core and react use the base. Along with config there would be base fixtures and expect custom matchers as well.
|
||||
import baseConfig from "@calcom/embed-core/playwright/config/playwright.config";
|
||||
|
||||
const testDir = path.join("../tests");
|
||||
|
||||
const projects = baseConfig.projects?.map((project) => {
|
||||
if (!project.name) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
...project,
|
||||
testDir,
|
||||
};
|
||||
});
|
||||
|
||||
const config: PlaywrightTestConfig = {
|
||||
...baseConfig,
|
||||
webServer: {
|
||||
// Start App Server manually - Can't be handled here. See https://github.com/microsoft/playwright/issues/8206
|
||||
command: "yarn workspace @calcom/embed-react dev",
|
||||
port: 3101,
|
||||
timeout: 60_000,
|
||||
reuseExistingServer: true,
|
||||
},
|
||||
use: {
|
||||
...baseConfig.use,
|
||||
baseURL: "http://localhost:3101",
|
||||
},
|
||||
projects,
|
||||
};
|
||||
export default config;
|
||||
@@ -0,0 +1,18 @@
|
||||
import { expect } from "@playwright/test";
|
||||
|
||||
import { test } from "@calcom/embed-core/playwright/fixtures/fixtures";
|
||||
import { getEmbedIframe } from "@calcom/embed-core/playwright/lib/testUtils";
|
||||
|
||||
test("Inline Usage Snapshot", async ({ page, getActionFiredDetails, addEmbedListeners }) => {
|
||||
//TODO: Do it with page.goto automatically
|
||||
await addEmbedListeners("");
|
||||
await page.goto("/");
|
||||
const embedIframe = await getEmbedIframe({ page, pathname: "/pro" });
|
||||
expect(embedIframe).toBeEmbedCalLink("", getActionFiredDetails, {
|
||||
pathname: "/pro",
|
||||
searchParams: {
|
||||
theme: "dark",
|
||||
},
|
||||
});
|
||||
expect(await page.screenshot()).toMatchSnapshot("react-component-inline.png");
|
||||
});
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 126 KiB |
@@ -13,12 +13,17 @@ export default function Cal({
|
||||
config?: any;
|
||||
embedJsUrl?: string;
|
||||
}) {
|
||||
if (!calLink) {
|
||||
throw new Error("calLink is required");
|
||||
}
|
||||
const initializedRef = useRef(false);
|
||||
const Cal = useEmbed(embedJsUrl);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (!Cal) {
|
||||
if (!Cal || initializedRef.current) {
|
||||
return;
|
||||
}
|
||||
initializedRef.current = true;
|
||||
const element = ref.current;
|
||||
let initConfig = {};
|
||||
if (calOrigin) {
|
||||
@@ -30,9 +35,6 @@ export default function Cal({
|
||||
calLink,
|
||||
config,
|
||||
});
|
||||
return () => {
|
||||
element?.querySelector(".cal-embed")?.remove();
|
||||
};
|
||||
}, [Cal, calLink, config, calOrigin]);
|
||||
|
||||
if (!Cal) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import Cal from "./Cal";
|
||||
|
||||
export default Cal;
|
||||
@@ -1,8 +1,15 @@
|
||||
import { useEffect } from "react";
|
||||
import { useState } from "react";
|
||||
import ReactDom from "react-dom";
|
||||
|
||||
import Cal from "@calcom/embed-react";
|
||||
import Cal from "./src/index";
|
||||
|
||||
function App() {
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
useEffect(() => {
|
||||
// Simulate state change causing config object to change, causing rerender of Cal
|
||||
setTimeout(setLoaded.bind(true), 1000);
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<h1>
|
||||
@@ -10,7 +17,7 @@ function App() {
|
||||
</h1>
|
||||
<Cal
|
||||
calOrigin="http://localhost:3000"
|
||||
embedJsUrl="//localhost:3002/dist/embed.umd.js"
|
||||
embedJsUrl="//localhost:3100/dist/embed.umd.js"
|
||||
calLink="pro"
|
||||
config={{
|
||||
name: "John Doe",
|
||||
|
||||
@@ -4,8 +4,12 @@
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"baseUrl": ".",
|
||||
"jsx": "preserve"
|
||||
"declaration": true,
|
||||
"jsx": "preserve",
|
||||
"paths": {
|
||||
"@lib/*": ["../../../apps/web/lib/*"]
|
||||
},
|
||||
},
|
||||
"include": ["."],
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
"exclude": ["dist", "build", "node_modules", "test-cal.tsx"]
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import react from "@vitejs/plugin-react";
|
||||
import path from "path";
|
||||
import { defineConfig } from "vite";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
build: {
|
||||
lib: {
|
||||
entry: path.resolve(__dirname, "src/index.ts"),
|
||||
name: "Cal",
|
||||
fileName: (format) => `Cal.${format}.js`,
|
||||
},
|
||||
rollupOptions: {
|
||||
// make sure to externalize deps that shouldn't be bundled
|
||||
// into your library
|
||||
external: ["react", "react-dom"],
|
||||
output: {
|
||||
// Provide global variables to use in the UMD build
|
||||
// for externalized deps
|
||||
globals: {
|
||||
react: "React",
|
||||
"react-dom": "ReactDOM",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user