The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
EmbedWidgetActivity, EmbedWidgetSales, etc.
Steven Tey1ea12f179e1a
diff --git a/apps/web/app/app.dub.co/embed/activity.tsx b/apps/web/app/app.dub.co/embed/activity.tsxindex 2e848c1336..e276f836ec 100644--- a/apps/web/app/app.dub.co/embed/activity.tsx+++ b/apps/web/app/app.dub.co/embed/activity.tsx@@ -1,30 +1,41 @@-import { currencyFormatter, nFormatter } from "@dub/utils";+import { InfoTooltip } from "@dub/ui";+import { nFormatter } from "@dub/utils";-export function Activity({+export function EmbedWidgetActivity({clicks,leads,- earnings,+ sales,}: {clicks: number;leads: number;- earnings: number;+ sales: number;}) {return (- <div className="mt-3 grid grid-cols-3 gap-2">+ <div className="col-span-2 grid h-full grid-cols-3 divide-x divide-neutral-200 rounded-lg border border-neutral-200 bg-white">{[- { label: "Clicks", value: clicks },- { label: "Signups", value: leads },- { label: "Total earned", value: earnings },- ].map(({ label, value }) => (- <div className="flex flex-col gap-1.5 rounded-lg bg-neutral-100 p-2">- <span className="text-xs text-neutral-500">{label}</span>- <span className="text-sm font-semibold text-neutral-600">- {label === "Total earned"- ? currencyFormatter(value / 100, {- minimumFractionDigits: 2,- maximumFractionDigits: 2,- })- : nFormatter(value)}+ {+ label: "Clicks",+ value: clicks,+ description: "Total number of unique clicks your link has received",+ },+ {+ label: "Leads",+ value: leads,+ description: "Total number of signups that came from your link",+ },+ {+ label: "Sales",+ value: sales,+ description: "Total number of leads that converted to a paid account",+ },+ ].map(({ label, value, description }) => (+ <div className="flex flex-col justify-between p-4">+ <span className="flex items-center gap-1 text-sm text-neutral-500">+ {label}+ <InfoTooltip content={description} />+ </span>+ <span className="font-semibold text-neutral-600">+ {nFormatter(value, { full: true })}</span></div>))}diff --git a/apps/web/app/app.dub.co/embed/inline/page-client.tsx b/apps/web/app/app.dub.co/embed/inline/page-client.tsxindex b399f57418..4e8752e9d0 100644--- a/apps/web/app/app.dub.co/embed/inline/page-client.tsx+++ b/apps/web/app/app.dub.co/embed/inline/page-client.tsx@@ -1,45 +1,35 @@"use client";-import { PartnerSaleResponse } from "@/lib/types";-import { HeroBackground } from "@/ui/partners/hero-background";import { ProgramCommissionDescription } from "@/ui/partners/program-commission-description";import { Link, Program } from "@dub/prisma/client";import {Button,- buttonVariants,Check,Copy,MoneyBill2,+ ToggleGroup,useCopyToClipboard,- Wordmark,} from "@dub/ui";-import { cn, fetcher, getPrettyUrl } from "@dub/utils";-import { CSSProperties } from "react";-import useSWR from "swr";-import { Activity } from "../activity";-import { SalesList } from "../sales-list";+import { cn, getPrettyUrl } from "@dub/utils";+import { CSSProperties, useState } from "react";+import { EmbedWidgetActivity } from "../activity";+import { EmbedWidgetPayouts } from "../payouts";+import { EmbedWidgetSales } from "../sales";import { LinkToken } from "../token";export function EmbedInlinePageClient({program,link,- earnings,hasPartnerProfile,}: {program: Program;link: Link;- earnings: number;hasPartnerProfile: boolean;}) {const [copied, copyToClipboard] = useCopyToClipboard();- const { data: sales, isLoading } = useSWR<PartnerSaleResponse[]>(- "/api/embed/sales",- fetcher,- {- keepPreviousData: true,- },- );+ const tabs = ["Quickstart", "Sales", "Leaderboard", "FAQ"];+ const [selectedTab, setSelectedTab] = useState(tabs[0]);return (<div@@ -49,15 +39,12 @@ export function EmbedInlinePageClient({}><div className="p-5">- <div className="relative flex flex-col overflow-hidden rounded-lg border border-neutral-300 bg-gradient-to-r from-neutral-50 p-4 md:p-6">- {program && (- <HeroBackground logo={program?.logo} color={program?.brandColor} />- )}+ <div className="relative flex flex-col overflow-hidden rounded-lg border border-neutral-200 bg-gradient-to-r from-neutral-50 p-4 md:p-6"><span className="flex items-center gap-2 text-sm text-neutral-500"><MoneyBill2 className="size-4" />Refer and earn</span>- <div className="relative mt-24 text-lg text-neutral-900 sm:max-w-[50%]">+ <div className="relative mt-6 text-lg text-neutral-900 sm:max-w-[50%]"><ProgramCommissionDescription program={program} /></div><span className="mb-1.5 mt-6 block text-sm text-neutral-800">@@ -68,7 +55,7 @@ export function EmbedInlinePageClient({type="text"readOnlyvalue={getPrettyUrl(link.shortLink)}- className="xs:w-auto h-10 w-full rounded-md border border-neutral-300 px-3 text-sm focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 lg:min-w-64 xl:min-w-72"+ className="xs:w-auto h-10 w-full rounded-md border border-neutral-200 px-3 text-sm focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 lg:min-w-64 xl:min-w-72"/><Buttonicon={@@ -96,62 +83,30 @@ export function EmbedInlinePageClient({onClick={() => copyToClipboard(link.shortLink)}/></div>- <a- href="https://d.to/conversions"- target="_blank"- className="mt-2 flex items-center justify-center gap-2 rounded-lg border-neutral-100 bg-white px-4 py-1.5 transition-colors hover:border-neutral-200 active:bg-neutral-50 md:absolute md:bottom-3 md:right-3 md:mt-0 md:translate-x-0 md:border md:drop-shadow-sm"- >- <p className="text-sm text-neutral-600">Powered by</p>- <Wordmark className="h-4" />- </a></div>- <div className="mt-5">- <>- <h2 className="text-sm font-semibold text-neutral-900">Activity</h2>- <Activity- clicks={link.clicks}- leads={link.leads}- earnings={earnings}- />- <div className="mt-4">- <h2 className="text-sm font-semibold text-neutral-900">- Recent sales- </h2>- <SalesList- sales={sales}- isLoading={isLoading}- hasPartnerProfile={hasPartnerProfile}- />- {!isLoading &&- sales &&- sales.length > 0 &&- (hasPartnerProfile ? (- <a- href="https://partners.dub.co/settings/payouts"- target="_blank"- className={cn(- buttonVariants({ variant: "primary" }),- "mt-3 flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm",- )}- >- Withdraw earnings- </a>- ) : (- <a- href="https://partners.dub.co/register"- target="_blank"- className={cn(- buttonVariants({ variant: "primary" }),- "mt-3 flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm",- )}- >- Create partner account- </a>- ))}- </div>- </>- <LinkToken />+ <div className="mt-4 grid h-32 grid-cols-3 gap-2">+ <EmbedWidgetActivity+ clicks={link.clicks}+ leads={link.leads}+ sales={link.sales}+ />+ <EmbedWidgetPayouts />+ </div>+ <div className="mt-4">+ <ToggleGroup+ options={tabs.map((tab) => ({+ label: tab,+ value: tab,+ }))}+ selected={selectedTab}+ selectAction={(option) => {+ setSelectedTab(option);+ }}+ className="w-full rounded-lg"+ />+ <EmbedWidgetSales hasPartnerProfile={hasPartnerProfile} /></div>+ <LinkToken /></div></div>);diff --git a/apps/web/app/app.dub.co/embed/inline/page.tsx b/apps/web/app/app.dub.co/embed/inline/page.tsxindex 4f12f6876d..f1c87a2a00 100644--- a/apps/web/app/app.dub.co/embed/inline/page.tsx+++ b/apps/web/app/app.dub.co/embed/inline/page.tsx@@ -15,7 +15,6 @@ export default async function EmbedInlinePage({<EmbedInlinePageClientprogram={program}link={link}- earnings={earnings}hasPartnerProfile={hasPartnerProfile}/>);diff --git a/apps/web/app/app.dub.co/embed/payouts.tsx b/apps/web/app/app.dub.co/embed/payouts.tsxnew file mode 100644index 0000000000..5fba91789f--- /dev/null+++ b/apps/web/app/app.dub.co/embed/payouts.tsx@@ -0,0 +1,36 @@+import { InfoTooltip } from "@dub/ui";+import { currencyFormatter } from "@dub/utils";++export function EmbedWidgetPayouts() {+ return (+ <div className="flex flex-col justify-between rounded-lg border border-neutral-200 bg-white p-4">+ <div className="flex items-center gap-1">+ <p className="text-sm text-neutral-500">Payouts</p>+ <InfoTooltip content="Payouts are processed at the start of each month. Your earnings are automatically transferred to your bank account." />+ </div>+ <div className="grid gap-1">+ {[+ {+ label: "Upcoming",+ value: 1830,+ },+ {+ label: "Total",+ value: 18112,+ },+ ].map(({ label, value }) => (+ <div className="flex justify-between text-sm">+ <span className="font-medium text-neutral-600">{label}</span>+ <span className="font-semibold text-neutral-600">+ {currencyFormatter(value / 100, {+ style: "currency",+ currency: "USD",+ maximumFractionDigits: 2,+ })}+ </span>+ </div>+ ))}+ </div>+ </div>+ );+}diff --git a/apps/web/app/app.dub.co/embed/sales-list.tsx b/apps/web/app/app.dub.co/embed/sales.tsxsimilarity index 89%rename from apps/web/app/app.dub.co/embed/sales-list.tsxrename to apps/web/app/app.dub.co/embed/sales.tsxindex 182fc129f6..8decec0cc9 100644--- a/apps/web/app/app.dub.co/embed/sales-list.tsx+++ b/apps/web/app/app.dub.co/embed/sales.tsx@@ -1,16 +1,20 @@import { PartnerSaleResponse } from "@/lib/types";import { Gift, LoadingSpinner } from "@dub/ui";-import { cn, currencyFormatter } from "@dub/utils";+import { cn, currencyFormatter, fetcher } from "@dub/utils";+import useSWR from "swr";-export function SalesList({- sales,- isLoading,+export function EmbedWidgetSales({hasPartnerProfile,}: {- sales: PartnerSaleResponse[] | undefined;- isLoading: boolean;hasPartnerProfile: boolean;}) {+ const { data: sales, isLoading } = useSWR<PartnerSaleResponse[]>(+ "/api/embed/sales",+ fetcher,+ {+ keepPreviousData: true,+ },+ );return sales ? (sales.length ? (<div className="mt-2.5 rounded-md border border-neutral-200">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.tsxindex 86a64fc9ab..b787f3eadd 100644--- a/apps/web/app/app.dub.co/embed/widget/page-client.tsx+++ b/apps/web/app/app.dub.co/embed/widget/page-client.tsx@@ -1,6 +1,5 @@"use client";-import { PartnerSaleResponse } from "@/lib/types";import { Link, Program } from "@dub/prisma/client";import {AnimatedSizeContainer,@@ -19,12 +18,11 @@ import {QRCode,Twitter,} from "@dub/ui/icons";-import { cn, fetcher, getPrettyUrl } from "@dub/utils";+import { cn, getPrettyUrl } from "@dub/utils";import { motion } from "framer-motion";import { CSSProperties, useState } from "react";-import useSWR from "swr";-import { Activity } from "../activity";-import { SalesList } from "../sales-list";+import { EmbedWidgetActivity } from "../activity";+import { EmbedWidgetSales } from "../sales";import { LinkToken } from "../token";import { useIframeVisibility } from "../use-iframe-visibility";@@ -48,14 +46,6 @@ export function EmbedWidgetPageClient({const isIframeVisible = useIframeVisibility();- const { data: sales, isLoading } = useSWR<PartnerSaleResponse[]>(- isIframeVisible && "/api/embed/sales",- fetcher,- {- keepPreviousData: true,- },- );-return (<divclassName="flex min-h-screen flex-col"@@ -207,7 +197,7 @@ export function EmbedWidgetPageClient({{selectedTab === "rewards" && (<><h2 className="text-sm font-semibold text-neutral-900">- Activity+ EmbedWidgetActivity</h2><motion.divinitial={{ height: 150, opacity: 0 }}@@ -218,46 +208,39 @@ export function EmbedWidgetPageClient({}}className="overflow-clip">- <Activity+ <EmbedWidgetActivityclicks={link.clicks}leads={link.leads}- earnings={earnings}+ sales={link.sales}/><div className="mt-4"><h2 className="text-sm font-semibold text-neutral-900">Recent sales</h2>- <SalesList- sales={sales}- isLoading={isLoading}- hasPartnerProfile={hasPartnerProfile}- />- {!isLoading &&- sales &&- sales.length > 0 &&- (hasPartnerProfile ? (- <a- href="https://partners.dub.co/settings/payouts"- target="_blank"- className={cn(- buttonVariants({ variant: "primary" }),- "mt-3 flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm",- )}- >- Withdraw earnings- </a>- ) : (- <a- href="https://partners.dub.co/register"- target="_blank"- className={cn(- buttonVariants({ variant: "primary" }),- "mt-3 flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm",- )}- >- Create partner account- </a>- ))}+ <EmbedWidgetSales hasPartnerProfile={hasPartnerProfile} />+ {hasPartnerProfile ? (+ <a+ href="https://partners.dub.co/settings/payouts"+ target="_blank"+ className={cn(+ buttonVariants({ variant: "primary" }),+ "mt-3 flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm",+ )}+ >+ Withdraw earnings+ </a>+ ) : (+ <a+ href="https://partners.dub.co/register"+ target="_blank"+ className={cn(+ buttonVariants({ variant: "primary" }),+ "mt-3 flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm",+ )}+ >+ Create partner account+ </a>+ )}</div></motion.div></>diff --git a/apps/web/ui/partners/program-commission-description.tsx b/apps/web/ui/partners/program-commission-description.tsxindex 70d8330000..4d59fe0be0 100644--- a/apps/web/ui/partners/program-commission-description.tsx+++ b/apps/web/ui/partners/program-commission-description.tsx@@ -49,7 +49,12 @@ export function ProgramCommissionDescription({</>) : ("."- )}+ )}{" "}+ Referred users get{" "}+ <strong className={cn("font-semibold", amountClassName)}>+ 20% off for 3 months+ </strong>+ .</>);}