Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Remove dashboard stuff

Tim Wilsonc083eec8cd4f
diff --git a/packages/embeds/core/src/core.ts b/packages/embeds/core/src/core.ts
index 101b591a01..f73e431c2f 100644
--- a/packages/embeds/core/src/core.ts
+++ b/packages/embeds/core/src/core.ts
@@ -1,7 +1,6 @@
import { setAnchoredPosition } from "./anchor";
import {
CLOSE_ICON,
- DASHBOARD_URL,
DUB_CLOSE_BUTTON_ID,
DUB_CONTAINER_ID,
DUB_POPUP_ID,
@@ -110,71 +109,7 @@ const createIframe = (
return iframe;
};
-type RenderDashboardResult = { container: HTMLElement | null };
-
-const renderDashboard = (
- options: Pick<
- DubOptions,
- "token" | "containerStyles" | "onError" | "onTokenExpired"
- >,
-): RenderDashboardResult => {
- console.debug("[Dub] Rendering dashboard.", options);
-
- const { token, containerStyles, onError, onTokenExpired } = options;
-
- const existingContainer = document.getElementById(DUB_CONTAINER_ID);
-
- if (existingContainer) {
- document.body.removeChild(existingContainer);
- return { container: existingContainer };
- }
-
- if (!token) {
- console.error("[Dub] A link token is required to embed the widget.");
- return { container: null };
- }
-
- const container = document.createElement("div");
- container.id = DUB_CONTAINER_ID;
-
- const iframe = createIframe(DASHBOARD_URL, token);
- Object.assign(iframe.style, {
- ...containerStyles,
- });
-
- container.appendChild(iframe);
-
- // Listen the message from the iframe
- window.addEventListener("message", (e) => {
- const { data, event } = e.data as IframeMessage;
-
- console.debug("[Dub] Iframe message", data);
-
- if (event === "ERROR") {
- onError?.(
- new EmbedError({
- code: data?.code ?? "",
- message: data?.message ?? "",
- }),
- );
- }
-
- if (data?.code === "unauthorized") {
- onTokenExpired?.();
- }
- });
-
- document.body.appendChild(container);
-
- return { container };
-};
-
-type RenderWidgetResult = {
- container: HTMLElement | null;
- updatePosition?: () => void;
-};
-
-const renderWidget = (options: DubOptions): RenderWidgetResult => {
+const renderWidget = (options: DubOptions) => {
console.debug("[Dub] Rendering widget.", options);
const {
@@ -326,22 +261,18 @@ export const toggleWidget = (): void => {
export const init = (options: DubOptions) => {
options.trigger = options.trigger ?? "floating-button";
options.placement = options.placement ?? "bottom-right";
- options.type = options.type ?? "widget";
console.debug("[Dub] Initializing.", options);
- const renderResult: RenderDashboardResult | RenderWidgetResult =
- options.type === "dashboard"
- ? renderDashboard(options)
- : renderWidget(options);
+ const { container, updatePosition } = renderWidget(options);
- if (!renderResult.container) {
+ if (!container) {
return { destroy: () => {} };
}
if (options.trigger === "floating-button")
createFloatingButton({
- container: renderResult.container,
+ container: container,
buttonStyles: options.buttonStyles,
placement: options.placement,
onClick: () => {
@@ -350,13 +281,12 @@ export const init = (options: DubOptions) => {
});
return {
- ...renderResult,
destroy: () => {
document
.querySelectorAll(`#${DUB_CONTAINER_ID}`)
.forEach((c) => c.remove());
- if ("updatePosition" in renderResult && renderResult.updatePosition)
- window.removeEventListener("resize", renderResult.updatePosition);
+
+ if (updatePosition) window.removeEventListener("resize", updatePosition);
},
};
};
diff --git a/packages/embeds/core/src/types.ts b/packages/embeds/core/src/types.ts
index 96c85d18e6..9081ca2013 100644
--- a/packages/embeds/core/src/types.ts
+++ b/packages/embeds/core/src/types.ts
@@ -11,9 +11,6 @@ export type DubOptions = {
// The link token
token: string;
- // The type of embed (defaults to widget)
- type?: "dashboard" | "widget";
-
// The trigger for the widget
trigger?: DubWidgetTrigger;
diff --git a/packages/embeds/react/src/dashboard.tsx b/packages/embeds/react/src/dashboard.tsx
deleted file mode 100644
index b3dec12fb8..0000000000
--- a/packages/embeds/react/src/dashboard.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-"use client";
-
-import { destroy, DubOptions, init } from "@dub/embed-core";
-import { useEffect } from "react";
-
-export const DubDashboard = (
- options: Omit<
- DubOptions,
- | "type"
- | "buttonStyle"
- | "trigger"
- | "containerStyles"
- | "popupStyles"
- | "buttonStyles"
- >,
-) => {
- useEffect(() => {
- init({
- ...options,
- type: "dashboard",
- });
-
- return () => destroy();
- }, [options]);
-
- return null;
-};
diff --git a/packages/embeds/react/src/example/dashboard.tsx b/packages/embeds/react/src/example/dashboard.tsx
deleted file mode 100644
index 7d03d6213b..0000000000
--- a/packages/embeds/react/src/example/dashboard.tsx
+++ /dev/null
@@ -1,10 +0,0 @@
-import ReactDom from "react-dom";
-import { DubDashboard } from "../dashboard";
-
-const Dashboard = () => {
- return (
- <DubDashboard token="dub_embed_GHdbSOZBg5iyiuiOIsj0ZbQlAkstoQSrpc4s" />
- );
-};
-
-ReactDom.render(<Dashboard />, document.getElementById("root"));
diff --git a/packages/embeds/react/src/index.ts b/packages/embeds/react/src/index.ts
index 67633b6453..97866ce19b 100644
--- a/packages/embeds/react/src/index.ts
+++ b/packages/embeds/react/src/index.ts
@@ -1,2 +1 @@
-export * from "./dashboard";
export * from "./widget";
diff --git a/packages/embeds/react/src/widget.tsx b/packages/embeds/react/src/widget.tsx
index d0f9074d1c..fe4d5ae46c 100644
--- a/packages/embeds/react/src/widget.tsx
+++ b/packages/embeds/react/src/widget.tsx
@@ -13,13 +13,12 @@ import {
} from "react";
export const DubWidget = memo(
- ({ children, ...options }: PropsWithChildren<Omit<DubOptions, "type">>) => {
+ ({ children, ...options }: PropsWithChildren<DubOptions>) => {
const id = useId();
useEffect(() => {
const { destroy } = init({
...options,
- type: "widget",
anchorId: children && options.placement !== "center" ? id : undefined,
});