Merge pull request #2672 from calcom/main

v1.5.4
This commit is contained in:
Omar López authored and GitHub committed 2022-05-09 14:56:23 -06:00
1 parent 7399d6421e
commit ed808c3be6
244 files changed
+7237 -3128

No files matched your search

+75 -17
View File
@@ -8,6 +8,12 @@ import css from "./embed.css";
import { SdkActionManager } from "./sdk-action-manager";
import allCss from "./tailwind.generated.css";
// HACK: Redefine and don't import WEBAPP_URL as it causes import statement to be present in built file.
// This is happening because we are not able to generate an App and a lib using single Vite Config.
const WEBAPP_URL =
(import.meta.env.NEXT_PUBLIC_WEBAPP_URL_TYPO as string) ||
`https://${import.meta.env.NEXT_PUBLIC_VERCEL_URL}`;
customElements.define("cal-modal-box", ModalBox);
customElements.define("cal-floating-button", FloatingButton);
customElements.define("cal-inline", Inline);
@@ -23,6 +29,11 @@ const globalCal = (window as CalWindow).Cal;
if (!globalCal || !globalCal.q) {
throw new Error("Cal is not defined. This shouldn't happen");
}
// Store Commit Hash to know exactly what version of the code is running
// TODO: Ideally it should be the version as per package.json and then it can be renamed to version.
// But because it is built on local machine right now, it is much more reliable to have the commit hash.
globalCal.fingerprint = import.meta.env.NEXT_PUBLIC_EMBED_FINGER_PRINT as string;
globalCal.__css = allCss;
document.head.appendChild(document.createElement("style")).innerHTML = css;
@@ -30,6 +41,7 @@ function log(...args: any[]) {
console.log(...args);
}
/**
* //TODO: Warn about extra properties not part of schema. Helps in fixing wrong expectations
* A very simple data validator written with intention of keeping payload size low.
* Extend the functionality of it as required by the embed.
* @param data
@@ -251,26 +263,60 @@ export class Cal {
throw new Error("Element not found");
}
const template = document.createElement("template");
template.innerHTML = `<cal-inline style="max-height:inherit;height:inherit;min-height:inherit;display:flex;position:relative;flex-wrap:wrap"></cal-inline>`;
template.innerHTML = `<cal-inline style="max-height:inherit;height:inherit;min-height:inherit;display:flex;position:relative;flex-wrap:wrap;width:100%"></cal-inline>`;
this.inlineEl = template.content.children[0];
(this.inlineEl as unknown as any).__CalAutoScroll = config.__autoScroll;
this.inlineEl.appendChild(iframe);
element.appendChild(template.content);
}
floatingButton({ calLink }: { calLink: string }) {
validate(arguments[0], {
required: true,
props: {
calLink: {
required: true,
type: "string",
},
},
});
const template = document.createElement("template");
template.innerHTML = `<cal-floating-button data-cal-namespace="${this.namespace}" data-cal-link="${calLink}"></cal-floating-button>`;
document.body.appendChild(template.content);
floatingButton({
calLink,
buttonText = "Book my Cal",
hideButtonIcon = false,
attributes,
buttonPosition = "bottom-right",
buttonColor = "rgb(255, 202, 0)",
buttonTextColor = "rgb(20, 30, 47)",
}: {
calLink: string;
buttonText?: string;
attributes?: Record<string, string>;
hideButtonIcon?: boolean;
buttonPosition?: "bottom-left" | "bottom-right";
buttonColor: string;
buttonTextColor: string;
}) {
// validate(arguments[0], {
// required: true,
// props: {
// calLink: {
// required: true,
// type: "string",
// },
// },
// });
let attributesString = "";
let existingEl = null;
if (attributes?.id) {
attributesString += ` id="${attributes.id}"`;
existingEl = document.getElementById(attributes.id);
}
let el = existingEl;
if (!existingEl) {
const template = document.createElement("template");
template.innerHTML = `<cal-floating-button ${attributesString} data-cal-namespace="${this.namespace}" data-cal-link="${calLink}"></cal-floating-button>`;
el = template.content.children[0] as HTMLElement;
document.body.appendChild(template.content);
}
if (buttonText) {
el!.setAttribute("data-button-text", buttonText);
}
el!.setAttribute("data-hide-button-icon", "" + hideButtonIcon);
el!.setAttribute("data-button-position", "" + buttonPosition);
el!.setAttribute("data-button-color", "" + buttonColor);
el!.setAttribute("data-button-text-color", "" + buttonTextColor);
}
modal({ calLink, config = {}, uid }: { calLink: string; config?: Record<string, string>; uid: number }) {
@@ -374,8 +420,8 @@ export class Cal {
constructor(namespace: string, q: InstructionQueue) {
this.__config = {
// Keep cal.com hardcoded till the time embed.js deployment to cal.com/embed.js is automated. This is to prevent accidentally pushing of localhost domain to production
origin: /*import.meta.env.NEXT_PUBLIC_WEBSITE_URL || */ "https://app.cal.com",
// Use WEBAPP_URL till full page reload problem with website URL is solved
origin: WEBAPP_URL,
};
this.namespace = namespace;
this.actionManager = new SdkActionManager(namespace);
@@ -437,8 +483,16 @@ export class Cal {
this.modalBox?.setAttribute("state", "loaded");
this.inlineEl?.setAttribute("loading", "done");
});
this.actionManager.on("linkFailed", (e) => {
this.iframe?.remove();
const iframe = this.iframe;
if (!iframe) {
return;
}
this.inlineEl?.setAttribute("data-error-code", e.detail.data.code);
this.modalBox?.setAttribute("data-error-code", e.detail.data.code);
this.inlineEl?.setAttribute("loading", "failed");
this.modalBox?.setAttribute("state", "failed");
});
}
}
@@ -459,7 +513,11 @@ window.addEventListener("message", (e) => {
if (!parsedAction) {
return;
}
const actionManager = Cal.actionsManagers[parsedAction.ns];
globalCal.__logQueue = globalCal.__logQueue || [];
globalCal.__logQueue.push({ ...parsedAction, data: detail.data });
if (!actionManager) {
throw new Error("Unhandled Action" + parsedAction);
}