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.

Add placeholder demo data

Tim Wilsoncfc4c3e0ad24
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx
index 5027f17a26..ffb42c36b9 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx
@@ -19,46 +19,53 @@ import { z } from "zod";
export function ActivityList({
events,
totalEvents,
+ demo,
}: {
events:
| z.infer<typeof clickEventEnrichedSchema>[]
| z.infer<typeof leadEventEnrichedSchema>[]
| z.infer<typeof saleEventEnrichedSchema>[];
totalEvents: number;
+ demo?: boolean;
}) {
const searchParams = useSearchParams();
const event = (searchParams.get("event") || "clicks") as EventType;
return (
- <EventList
- events={events.map((e) => {
- const Icon = {
- clicks: CursorRays,
- leads: UserCheck,
- sales: InvoiceDollar,
- }[event];
- return {
- icon: <Icon className="size-4.5" />,
- content: {
- clicks: <ClickDescription event={e} />,
- leads: <LeadDescription event={e} />,
- sales: <SaleDescription event={e} />,
- }[event],
- right: (
- <div className="whitespace-nowrap">
- {timeAgo(new Date(e.timestamp), { withAgo: true })}
- </div>
- ),
- };
- })}
- totalEvents={totalEvents}
- emptyState={{
- icon: ChartActivity2,
- title: `${capitalize(event)} Activity`,
- description: `No referral ${event} have been recorded yet.`,
- learnMore: "https://d.to/conversions",
- }}
- />
+ <div className="relative">
+ <EventList
+ events={events.map((e) => {
+ const Icon = {
+ clicks: CursorRays,
+ leads: UserCheck,
+ sales: InvoiceDollar,
+ }[event];
+ return {
+ icon: <Icon className="size-4.5" />,
+ content: {
+ clicks: <ClickDescription event={e} />,
+ leads: <LeadDescription event={e} />,
+ sales: <SaleDescription event={e} />,
+ }[event],
+ right: (
+ <div className="whitespace-nowrap">
+ {timeAgo(new Date(e.timestamp), { withAgo: true })}
+ </div>
+ ),
+ };
+ })}
+ totalEvents={totalEvents}
+ emptyState={{
+ icon: ChartActivity2,
+ title: `${capitalize(event)} Activity`,
+ description: `No referral ${event} have been recorded yet.`,
+ learnMore: "https://d.to/conversions",
+ }}
+ />
+ {demo && (
+ <div className="absolute inset-0 bg-gradient-to-b from-[#fff3] to-white"></div>
+ )}
+ </div>
);
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
index bdac492367..8436a21e52 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
@@ -2,10 +2,15 @@ import { getReferralLink } from "@/lib/actions/get-referral-link";
import { getTotalEvents } from "@/lib/actions/get-total-events";
import { EventType } from "@/lib/analytics/types";
import { dub } from "@/lib/dub";
+import { clickEventEnrichedSchema } from "@/lib/zod/schemas/clicks";
+import { leadEventEnrichedSchema } from "@/lib/zod/schemas/leads";
+import { saleEventEnrichedSchema } from "@/lib/zod/schemas/sales";
import { EventListSkeleton } from "@dub/blocks";
import { Wordmark } from "@dub/ui";
import { Check } from "@dub/ui/src/icons";
+import { subDays } from "date-fns";
import { Suspense } from "react";
+import { z } from "zod";
import { ActivityList } from "./activity-list";
import { EventTabs } from "./event-tabs";
import { HeroBackground } from "./hero-background";
@@ -106,6 +111,46 @@ export default async function ReferralsPage({
);
}
+const placeholderEvents = {
+ clicks: [...Array(8)].map(
+ (_, idx) =>
+ ({
+ timestamp: subDays(new Date(), idx).toISOString(),
+ click_id: "1",
+ link_id: "1",
+ domain: "refer.dub.co",
+ key: "",
+ url: "https://dub.co",
+ country: "US",
+ }) as z.infer<typeof clickEventEnrichedSchema>,
+ ),
+ leads: [...Array(4)].map(
+ (_, idx) =>
+ ({
+ timestamp: subDays(new Date(), idx).toISOString(),
+ click_id: "1",
+ link_id: "1",
+ domain: "refer.dub.co",
+ key: "",
+ url: "https://dub.co",
+ country: "US",
+ }) as z.infer<typeof leadEventEnrichedSchema>,
+ ),
+ sales: [...Array(2)].map(
+ (_, idx) =>
+ ({
+ timestamp: subDays(new Date(), idx).toISOString(),
+ click_id: "1",
+ link_id: "1",
+ domain: "refer.dub.co",
+ key: "",
+ url: "https://dub.co",
+ country: "US",
+ amount: [11, 49][idx % 2],
+ }) as z.infer<typeof saleEventEnrichedSchema>,
+ ),
+};
+
async function ActivityListRSC({
slug,
event,
@@ -117,7 +162,13 @@ async function ActivityListRSC({
}) {
const link = await getReferralLink(slug);
if (!link) {
- return <EventListSkeleton />;
+ return (
+ <ActivityList
+ events={placeholderEvents[event]}
+ totalEvents={placeholderEvents[event].length}
+ demo
+ />
+ );
}
const eventsParams = {
@@ -131,7 +182,7 @@ async function ActivityListRSC({
page,
});
- const totalEvents = await getTotalEvents(link.id);
+ const totalEvents = (await getTotalEvents(link.id)) ?? 0;
return (
<ActivityList events={events as any} totalEvents={totalEvents[event]} />
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
index 847236240f..aa21c5bf8d 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
@@ -24,12 +24,21 @@ export function Stats({ slug }: { slug: string }) {
}
async function StatsInner({ slug }: { slug: string }) {
- const link = await getReferralLink(slug);
- if (!link) {
- return [...Array(2)].map(() => <StatCardSkeleton error />);
- }
-
try {
+ const link = await getReferralLink(slug);
+ if (!link) {
+ return (
+ <>
+ <StatCard label="Clicks" demo>
+ 120
+ </StatCard>
+ <StatCard label="Sales" demo>
+ $60
+ </StatCard>
+ </>
+ );
+ }
+
const { totalClicks, clicks, totalSales, sales } = await loadData(link.id);
return (
diff --git a/packages/blocks/src/stat-card.tsx b/packages/blocks/src/stat-card.tsx
index bf829c901a..ee5a682e80 100644
--- a/packages/blocks/src/stat-card.tsx
+++ b/packages/blocks/src/stat-card.tsx
@@ -1,3 +1,4 @@
+import { cn } from "@dub/utils";
import { PropsWithChildren } from "react";
import { MiniAreaChart, MiniAreaChartProps } from "./mini-area-chart";
@@ -7,16 +8,25 @@ const wrapperClassName =
export function StatCard({
label,
timeseriesData,
+ demo,
children,
}: PropsWithChildren<{
label: string;
- timeseriesData: MiniAreaChartProps["data"];
+ demo?: boolean;
+ timeseriesData?: MiniAreaChartProps["data"];
}>) {
return (
<div className={wrapperClassName}>
<div className="flex flex-col gap-2">
<span className="text-sm text-gray-600">{label}</span>
- <span className="text-2xl font-medium">{children}</span>
+ <span
+ className={cn(
+ "text-2xl font-medium",
+ demo && "text-gray-500 blur-[4px]",
+ )}
+ >
+ {children}
+ </span>
</div>
{timeseriesData && (
<div className="relative h-full min-w-0 max-w-[140px] grow">