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.

widget ui

Kiran K1d3c1799369c
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page-client.tsx
index b0cb43eacd..83b297d2de 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page-client.tsx
@@ -1,7 +1,7 @@
"use client";
import useWorkspace from "@/lib/swr/use-workspace";
-import { ReferralsEmbed } from "@/ui/embed/referrals-embed";
+import { RewardDashboard } from "@/ui/embed/referrals-embed";
import { LoadingSpinner } from "@dub/ui";
import { redirect } from "next/navigation";
import { useCallback, useEffect, useState } from "react";
@@ -37,7 +37,7 @@ export default function ReferralsPageClient() {
}
return publicToken ? (
- <ReferralsEmbed
+ <RewardDashboard
publicToken={publicToken}
onTokenExpired={() => createPublicToken()}
/>
diff --git a/apps/web/app/app.dub.co/embed/page-client.tsx b/apps/web/app/app.dub.co/embed/dashboard/page-client.tsx
similarity index 88%
rename from apps/web/app/app.dub.co/embed/page-client.tsx
rename to apps/web/app/app.dub.co/embed/dashboard/page-client.tsx
index 13b300d6a7..99c22e3830 100644
--- a/apps/web/app/app.dub.co/embed/page-client.tsx
+++ b/apps/web/app/app.dub.co/embed/dashboard/page-client.tsx
@@ -16,18 +16,15 @@ import {
Wordmark,
} from "@dub/ui";
import { Copy, MoneyBill2 } from "@dub/ui/src/icons";
-import { fetcher, getPrettyUrl } from "@dub/utils";
-import { ProgramEnrollment, ProgramInvite } from "@prisma/client";
+import { getPrettyUrl } from "@dub/utils";
import { notFound } from "next/navigation";
import { useContext } from "react";
-import useSWR from "swr";
-import { RequestPartnerInviteForm } from "./request-partner-invite-form";
import { SaleTable } from "./sale-table";
import useReferralAnalytics from "./use-referral-analytics";
import { useReferralLink } from "./use-referral-link";
import { useReferralProgram } from "./use-referral-program";
-export function ReferralsEmbedPageClient() {
+export function RewardDashboardPageClient() {
const { program } = useReferralProgram();
const { searchParamsObj } = useRouterStuff();
const [copied, copyToClipboard] = useCopyToClipboard();
@@ -49,18 +46,6 @@ export function ReferralsEmbedPageClient() {
token?: string;
};
- const { data, isLoading } = useSWR<{
- programEnrollment: ProgramEnrollment;
- programInvite: ProgramInvite;
- }>(`/api/referrals/invite`, fetcher);
-
- const { data: salesCount } = useSWR<{ count: number }>(
- "/api/referrals/sales/count",
- fetcher,
- );
-
- const hasEnrolled = data?.programEnrollment;
- const hasInvited = data?.programInvite;
const color = program?.brandColor || "#8B5CF6";
if (!token) {
@@ -152,11 +137,6 @@ export function ReferralsEmbedPageClient() {
</ProgramOverviewContext.Provider>
</div>
- {/* TODO: UI needs tweaking */}
- {/* {!isLoading && !hasEnrolled && !hasInvited && salesCount?.count && (
- <RequestPartnerInviteForm />
- )} */}
-
<div className="flex items-center justify-center">
<a
href="https://d.to/conversions"
diff --git a/apps/web/app/app.dub.co/embed/dashboard/page.tsx b/apps/web/app/app.dub.co/embed/dashboard/page.tsx
new file mode 100644
index 0000000000..795b21a739
--- /dev/null
+++ b/apps/web/app/app.dub.co/embed/dashboard/page.tsx
@@ -0,0 +1,5 @@
+import { RewardDashboardPageClient } from "./page-client";
+
+export default async function RewardDashboardPage() {
+ return <RewardDashboardPageClient />;
+}
diff --git a/apps/web/app/app.dub.co/embed/request-partner-invite-form.tsx b/apps/web/app/app.dub.co/embed/dashboard/request-partner-invite-form.tsx
similarity index 100%
rename from apps/web/app/app.dub.co/embed/request-partner-invite-form.tsx
rename to apps/web/app/app.dub.co/embed/dashboard/request-partner-invite-form.tsx
diff --git a/apps/web/app/app.dub.co/embed/sale-table.tsx b/apps/web/app/app.dub.co/embed/dashboard/sale-table.tsx
similarity index 100%
rename from apps/web/app/app.dub.co/embed/sale-table.tsx
rename to apps/web/app/app.dub.co/embed/dashboard/sale-table.tsx
diff --git a/apps/web/app/app.dub.co/embed/use-referral-analytics.ts b/apps/web/app/app.dub.co/embed/dashboard/use-referral-analytics.ts
similarity index 100%
rename from apps/web/app/app.dub.co/embed/use-referral-analytics.ts
rename to apps/web/app/app.dub.co/embed/dashboard/use-referral-analytics.ts
diff --git a/apps/web/app/app.dub.co/embed/use-referral-link.ts b/apps/web/app/app.dub.co/embed/dashboard/use-referral-link.ts
similarity index 100%
rename from apps/web/app/app.dub.co/embed/use-referral-link.ts
rename to apps/web/app/app.dub.co/embed/dashboard/use-referral-link.ts
diff --git a/apps/web/app/app.dub.co/embed/use-referral-program.ts b/apps/web/app/app.dub.co/embed/dashboard/use-referral-program.ts
similarity index 100%
rename from apps/web/app/app.dub.co/embed/use-referral-program.ts
rename to apps/web/app/app.dub.co/embed/dashboard/use-referral-program.ts
diff --git a/apps/web/app/app.dub.co/embed/page.tsx b/apps/web/app/app.dub.co/embed/page.tsx
deleted file mode 100644
index c920f89d35..0000000000
--- a/apps/web/app/app.dub.co/embed/page.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { ReferralsEmbedPageClient } from "./page-client";
-
-export default async function ReferralsEmbedPage() {
- return <ReferralsEmbedPageClient />;
-}
diff --git a/apps/web/app/app.dub.co/embed/widget/page-client.tsx b/apps/web/app/app.dub.co/embed/widget/page-client.tsx
new file mode 100644
index 0000000000..90532b74b1
--- /dev/null
+++ b/apps/web/app/app.dub.co/embed/widget/page-client.tsx
@@ -0,0 +1,131 @@
+"use client";
+
+import {
+ Button,
+ Check2,
+ Copy,
+ MoneyBill2,
+ ToggleGroup,
+ useCopyToClipboard,
+} from "@dub/ui";
+import { currencyFormatter, getPrettyUrl } from "@dub/utils";
+import { useState } from "react";
+import { useReferralLink } from "../dashboard/use-referral-link";
+import { useReferralProgram } from "../dashboard/use-referral-program";
+
+type Tab = "invite" | "rewards";
+
+export function EmbedWidgetPageClient() {
+ const [copied, copyToClipboard] = useCopyToClipboard();
+ const [selectedTab, setSelectedTab] = useState<Tab>("invite");
+
+ const { link, isLoading: isLoadingLink } = useReferralLink();
+ const { program, isLoading: isLoadingProgram } = useReferralProgram();
+
+ return (
+ <div>
+ <div className="flex flex-col gap-2 rounded-lg rounded-b-none bg-black p-4">
+ <MoneyBill2 className="flex size-14 rounded-full bg-gray-800 p-2 text-white" />
+ <h2 className="mt-4 text-lg font-medium text-white">
+ Refer a friend and earn
+ </h2>
+
+ <p className="text-sm text-gray-300">
+ Earn additional credits and cash when you refer a friend and they sign
+ up for {program?.name}
+ </p>
+ </div>
+
+ <div className="mt-4 p-4">
+ <ToggleGroup
+ options={[
+ { value: "invite", label: "Invite" },
+ { value: "rewards", label: "Rewards" },
+ ]}
+ selected={selectedTab}
+ selectAction={(option: Tab) => setSelectedTab(option)}
+ className="grid grid-cols-2 bg-gray-100"
+ optionClassName="w-full h-10"
+ indicatorClassName="rounded-md bg-white border-none shadow-sm"
+ />
+
+ <div className="mt-4">
+ {selectedTab === "invite" && (
+ <>
+ <div className="flex flex-col gap-2">
+ {!isLoadingLink && link ? (
+ <input
+ type="text"
+ readOnly
+ value={getPrettyUrl(link.shortLink)}
+ className="xs:w-auto h-10 w-full rounded-md border border-neutral-300 px-3 text-sm focus:border-gray-500 focus:outline-none focus:ring-gray-500 lg:min-w-64 xl:min-w-72"
+ />
+ ) : (
+ <div className="h-10 animate-pulse rounded-md bg-neutral-200" />
+ )}
+ <Button
+ icon={
+ copied ? (
+ <Check2 className="size-4" />
+ ) : (
+ <Copy className="size-4" />
+ )
+ }
+ text={copied ? "Copied link" : "Copy link"}
+ onClick={() => copyToClipboard(getPrettyUrl(link?.shortLink))}
+ disabled={isLoadingLink}
+ />
+ </div>
+ </>
+ )}
+
+ {selectedTab === "rewards" && (
+ <>
+ <h2 className="text-lg font-bold">Activity</h2>
+ {isLoadingLink || !link ? (
+ <div className="mt-4 grid grid-cols-3 gap-4">
+ <div className="flex animate-pulse flex-col gap-2 rounded-lg bg-gray-200 p-3 shadow-sm">
+ <span className="h-4 w-1/2 rounded bg-gray-300"></span>
+ <span className="h-6 w-3/4 rounded bg-gray-300"></span>
+ </div>
+ <div className="flex animate-pulse flex-col gap-2 rounded-lg bg-gray-200 p-3 shadow-sm">
+ <span className="h-4 w-1/2 rounded bg-gray-300"></span>
+ <span className="h-6 w-3/4 rounded bg-gray-300"></span>
+ </div>
+ <div className="flex animate-pulse flex-col gap-2 rounded-lg bg-gray-200 p-3 shadow-sm">
+ <span className="h-4 w-1/2 rounded bg-gray-300"></span>
+ <span className="h-6 w-3/4 rounded bg-gray-300"></span>
+ </div>
+ </div>
+ ) : (
+ <div className="mt-4 grid grid-cols-3 gap-4">
+ <div className="flex flex-col gap-2 rounded-lg bg-gray-100 p-3 shadow-sm">
+ <span className="text-sm text-gray-600">Clicks</span>
+ <span className="text-lg font-medium text-gray-500">
+ {link.clicks}
+ </span>
+ </div>
+ <div className="flex flex-col gap-2 rounded-lg bg-gray-100 p-3 shadow-sm">
+ <span className="text-sm text-gray-600">Signups</span>
+ <span className="text-lg font-medium text-gray-500">
+ {link.leads}
+ </span>
+ </div>
+ <div className="flex flex-col gap-2 rounded-lg bg-gray-100 p-3 shadow-sm">
+ <span className="text-sm text-gray-600">Total earned</span>
+ <span className="text-lg font-medium text-gray-500">
+ {currencyFormatter(link.saleAmount / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ })}
+ </span>
+ </div>
+ </div>
+ )}
+ </>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/app.dub.co/embed/widget/page.tsx b/apps/web/app/app.dub.co/embed/widget/page.tsx
new file mode 100644
index 0000000000..c62d4b5722
--- /dev/null
+++ b/apps/web/app/app.dub.co/embed/widget/page.tsx
@@ -0,0 +1,5 @@
+import { EmbedWidgetPageClient } from "./page-client";
+
+export default async function EmbedWidgetPage() {
+ return <EmbedWidgetPageClient />;
+}
diff --git a/apps/web/next.config.js b/apps/web/next.config.js
index 4512003839..97071443a6 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.js
@@ -95,7 +95,7 @@ module.exports = withAxiom({
],
},
{
- source: "/embed",
+ source: "/embed/:path*",
headers: [
{
key: "X-Frame-Options",
diff --git a/apps/web/public/embed.js b/apps/web/public/embed.js
index 4fe2f822e7..e8565c18ab 100644
--- a/apps/web/public/embed.js
+++ b/apps/web/public/embed.js
@@ -6,16 +6,30 @@
linkToken: null,
};
+ const buttonStyles = {
+ position: "fixed",
+ bottom: "20px",
+ right: "20px",
+ zIndex: "9999",
+ };
+
+ const containerStyles = {
+ width: "450px",
+ height: "600px",
+ boxShadow: "0 0 20px rgba(0,0,0,0.1)",
+ borderRadius: "10px",
+ overflow: "hidden",
+ position: "fixed",
+ bottom: "80px",
+ right: "20px",
+ zIndex: "9998",
+ };
+
// Add a floating button to the page
function createFloatingButton() {
const button = document.createElement("div");
button.id = "floating-widget-button";
-
- // Add styles for positioning and appearance
- button.style.position = "fixed";
- button.style.bottom = "20px";
- button.style.right = "20px";
- button.style.zIndex = "9999";
+ Object.assign(button.style, buttonStyles);
button.innerHTML = `
<button>
@@ -23,8 +37,15 @@
</button>
`;
- // Load widget on click
button.addEventListener("click", () => {
+ const existingContainer = document.getElementById("dub-widget-container");
+
+ if (existingContainer) {
+ // If the container exists, remove it (close the widget)
+ document.body.removeChild(existingContainer);
+ return;
+ }
+
if (!Dub.options.linkToken) {
console.error("Link token is required");
return;
@@ -33,20 +54,11 @@
// Create iframe container
const container = document.createElement("div");
container.id = "dub-widget-container";
- container.style.position = "fixed";
- container.style.bottom = "80px";
- container.style.right = "20px";
- container.style.width = "400px";
- container.style.height = "600px";
- container.style.zIndex = "9998";
- container.style.boxShadow = "0 0 20px rgba(0,0,0,0.1)";
- container.style.borderRadius = "10px";
- container.style.overflow = "hidden";
- container.style.padding = "10px";
+ Object.assign(container.style, containerStyles);
// Create iframe
const iframe = document.createElement("iframe");
- iframe.src = `http://localhost:8888/embed?token=${Dub.options.linkToken}`;
+ iframe.src = `http://localhost:8888/embed/widget?token=${Dub.options.linkToken}`;
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.style.border = "none";
diff --git a/apps/web/ui/embed/referrals-embed.tsx b/apps/web/ui/embed/referrals-embed.tsx
index 84959001f6..3e7ce38763 100644
--- a/apps/web/ui/embed/referrals-embed.tsx
+++ b/apps/web/ui/embed/referrals-embed.tsx
@@ -1,19 +1,19 @@
import { APP_DOMAIN } from "@dub/utils";
import { useEffect } from "react";
-interface ReferralsEmbedProps {
+interface RewardDashboardProps {
publicToken: string;
onTokenExpired?: () => void;
}
-export const ReferralsEmbed = ({
+export const RewardDashboard = ({
publicToken,
onTokenExpired,
-}: ReferralsEmbedProps) => {
+}: RewardDashboardProps) => {
useEffect(() => {
const handleMessage = (event: MessageEvent) => {
// Verify the message is from our embed page
- if (event.origin !== APP_DOMAIN) {
+ if (event.origin !== APP_DOMAIN) {
return;
}
@@ -29,7 +29,7 @@ export const ReferralsEmbed = ({
return (
<iframe
- src={`${APP_DOMAIN}/embed?token=${publicToken}`}
+ src={`${APP_DOMAIN}/embed/dashboard?token=${publicToken}`}
style={{
width: "100%",
height: "100vh",
diff --git a/packages/widgets/src/embed.js b/packages/widgets/src/embed.js
index 6459729572..31c5c6bc25 100644
--- a/packages/widgets/src/embed.js
+++ b/packages/widgets/src/embed.js
@@ -1,26 +1 @@
-(function () {
- // Add a floating button to the page
- function createFloatingButton() {
- const button = document.createElement("div");
- button.id = "floating-widget-button";
- button.innerHTML = `
- <button>
- <span>💬</span>
- </button>
- `;
-
- document.body.appendChild(button);
- }
-
- // Initialize when DOM is ready
- function init() {
- setTimeout(createFloatingButton, 100);
- console.log("Initialized");
- }
-
- if (document.readyState === "loading") {
- document.addEventListener("DOMContentLoaded", init);
- } else {
- init();
- }
-})();
\ No newline at end of file
+// Move the embed.js to here
\ No newline at end of file