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.

improve placeholder data

Steven Tey66cd77a0dd42
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/generate-button.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/generate-button.tsx
index 7aea7409c3..d7c97e2204 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/generate-button.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/generate-button.tsx
@@ -28,7 +28,7 @@ export function GenerateButton() {
return (
<Button
icon={<Hyperlink className="size-4" />}
- text="Generate Referral Link"
+ text="Activate Referral Link"
className="h-9 w-auto rounded-lg"
onClick={() => executeAsync({ workspaceId: workspaceId! })}
loading={isExecuting || hasSucceeded}
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 313e0c3db5..6d5ef15ca1 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
@@ -13,7 +13,7 @@ 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 { nFormatter } from "@dub/utils";
+import { nFormatter, randomValue } from "@dub/utils";
import { subDays } from "date-fns";
import { Suspense } from "react";
import { z } from "zod";
@@ -118,7 +118,7 @@ export default function ReferralsPage({
}
const placeholderEvents = {
- clicks: [...Array(8)].map(
+ clicks: [...Array(10)].map(
(_, idx) =>
({
timestamp: subDays(new Date(), idx).toISOString(),
@@ -127,10 +127,10 @@ const placeholderEvents = {
domain: "refer.dub.co",
key: "",
url: "https://dub.co",
- country: "US",
+ country: randomValue(["US", "GB", "CA", "AU", "DE", "FR", "ES", "IT"]),
}) as z.infer<typeof clickEventEnrichedSchema>,
),
- leads: [...Array(8)].map(
+ leads: [...Array(10)].map(
(_, idx) =>
({
timestamp: subDays(new Date(), idx).toISOString(),
@@ -139,10 +139,10 @@ const placeholderEvents = {
domain: "refer.dub.co",
key: "",
url: "https://dub.co",
- country: "US",
+ country: randomValue(["US", "GB", "CA", "AU", "DE", "FR", "ES", "IT"]),
}) as z.infer<typeof leadEventEnrichedSchema>,
),
- sales: [...Array(8)].map(
+ sales: [...Array(10)].map(
(_, idx) =>
({
timestamp: subDays(new Date(), idx).toISOString(),
@@ -151,7 +151,7 @@ const placeholderEvents = {
domain: "refer.dub.co",
key: "",
url: "https://dub.co",
- country: "US",
+ country: randomValue(["US", "GB", "CA", "AU", "DE", "FR", "ES", "IT"]),
event_name: [
"Subscription creation",
"Subscription paid",
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 9e33234c5d..1a9c91b51f 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
@@ -14,6 +14,8 @@ import {
} from "@dub/blocks";
import { CountingNumbers } from "@dub/ui";
import { User } from "@dub/ui/src/icons";
+import { nFormatter, randomValue } from "@dub/utils";
+import { subDays } from "date-fns";
import {
ClicksTimeseries,
SalesTimeseries,
@@ -43,9 +45,24 @@ async function StatsInner({ slug }: { slug: string }) {
<StatsCard
label="Affiliate Earnings"
demo
- graphic={<MiniAreaChart data={[]} />}
+ graphic={
+ <MiniAreaChart
+ // generate a random bell curve
+ data={[...Array(16)].map((_, idx) => {
+ const x = (idx - 7.5) / 4;
+ const curve1 = 800 * Math.exp(-Math.pow(x + 0.5, 2));
+ const curve2 = 600 * Math.exp(-Math.pow(x - 0.5, 2));
+ return {
+ date: subDays(new Date(), 15 - idx),
+ value: Math.floor(
+ 1500 + curve1 + curve2 + (Math.random() - 0.5) * 200,
+ ),
+ };
+ })}
+ />
+ }
>
- $60
+ ${Math.floor(Math.random() * 50) + 50}
</StatsCard>
<StatsCard
label="Clicks Quota Earned"
@@ -59,7 +76,9 @@ async function StatsInner({ slug }: { slug: string }) {
</Gauge>
}
>
- 2500
+ {nFormatter(randomValue([1000, 1500, 2000, 2500, 3000]), {
+ full: true,
+ })}
</StatsCard>
</>
);
diff --git a/apps/web/lib/actions/generate-referral-link.ts b/apps/web/lib/actions/generate-referral-link.ts
index 926ccf3f8b..71a64b3821 100644
--- a/apps/web/lib/actions/generate-referral-link.ts
+++ b/apps/web/lib/actions/generate-referral-link.ts
@@ -32,8 +32,8 @@ export const generateReferralLink = authActionClient
}),
};
} catch (e) {
- console.error("Failed to generate referral link.", e);
+ console.error("Failed to activate referral link.", e);
}
- throw new Error("Failed to generate referral link.");
+ throw new Error("Failed to activate referral link.");
});
diff --git a/packages/blocks/src/stats-card.tsx b/packages/blocks/src/stats-card.tsx
index f0726c2e0d..517dfe21b7 100644
--- a/packages/blocks/src/stats-card.tsx
+++ b/packages/blocks/src/stats-card.tsx
@@ -1,7 +1,8 @@
+import { cn } from "@dub/utils";
import { PropsWithChildren, ReactNode } from "react";
const wrapperClassName =
- "flex justify-between gap-4 rounded-xl border border-gray-200 bg-white px-5 py-4 text-left";
+ "flex justify-between gap-4 rounded-xl border border-gray-200 bg-white px-5 py-4 text-left overflow-hidden";
export function StatsCard({
label,
@@ -14,19 +15,17 @@ export function StatsCard({
graphic?: ReactNode;
}>) {
return (
- <div className={wrapperClassName}>
+ <div className={cn(wrapperClassName, demo && "relative pr-8")}>
+ {demo && (
+ <span className="absolute -right-px top-2 z-10 rounded-l-full border-r border-gray-200 bg-gradient-to-r from-[#743ad5] to-[#DA2778] px-1.5 py-px text-[10px] text-white">
+ DEMO DATA
+ </span>
+ )}
<div className="flex flex-col gap-2">
<span className="truncate whitespace-nowrap text-sm text-gray-600">
{label}
</span>
- <div className="flex items-center gap-2">
- <span className="text-2xl font-medium">{children}</span>
- {demo && (
- <span className="rounded-full border border-gray-500 px-1 py-px text-[9px] text-gray-500">
- DEMO DATA
- </span>
- )}
- </div>
+ <span className="text-2xl font-medium">{children}</span>
</div>
{graphic && (
<div className="relative flex h-full min-w-0 max-w-[140px] grow items-center justify-end">
diff --git a/packages/utils/src/functions/index.ts b/packages/utils/src/functions/index.ts
index cedfa43b9d..adf640b82a 100644
--- a/packages/utils/src/functions/index.ts
+++ b/packages/utils/src/functions/index.ts
@@ -17,6 +17,7 @@ export * from "./log";
export * from "./nanoid";
export * from "./nformatter";
export * from "./punycode";
+export * from "./random-value";
export * from "./stable-sort";
export * from "./time-ago";
export * from "./trim";
diff --git a/packages/utils/src/functions/random-value.ts b/packages/utils/src/functions/random-value.ts
new file mode 100644
index 0000000000..7ace22e191
--- /dev/null
+++ b/packages/utils/src/functions/random-value.ts
@@ -0,0 +1,3 @@
+export const randomValue = (values: any[]) => {
+ return values[Math.floor(Math.random() * values.length)];
+};