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.

WIP overview page

Tim Wilsonc5cfc6268720
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/overview-chart.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/overview-chart.tsx
new file mode 100644
index 0000000000..e1df57af06
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/overview-chart.tsx
@@ -0,0 +1,84 @@
+import Areas from "@/ui/charts/areas";
+import { ChartContext } from "@/ui/charts/chart-context";
+import TimeSeriesChart from "@/ui/charts/time-series-chart";
+import XAxis from "@/ui/charts/x-axis";
+import YAxis from "@/ui/charts/y-axis";
+import { currencyFormatter } from "@dub/utils";
+import { LinearGradient } from "@visx/gradient";
+import { subDays } from "date-fns";
+import { useId, useMemo } from "react";
+
+const mockData = () =>
+ [...Array(30)].map((_, i) => ({
+ date: subDays(new Date(), 30 - i),
+ values: {
+ earnings: Math.round(Math.random() * 100_00),
+ },
+ }));
+
+export function OverviewChart() {
+ const id = useId();
+
+ // TODO: [payouts] use actual data
+ const total = 1234_00;
+ const data = useMemo(() => mockData(), []);
+
+ const dataError = null;
+ const totalError = null;
+
+ const dataLoading = !data && !dataError;
+ const totalLoading = false;
+
+ return (
+ <div>
+ <div className="flex flex-col gap-1 p-2">
+ <span className="text-sm text-neutral-500">Revenue</span>
+ <span className="text-3xl text-neutral-800">
+ {currencyFormatter(total / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ })}
+ </span>
+ </div>
+ <div className="relative mt-4 h-72 md:h-96">
+ <TimeSeriesChart
+ data={data}
+ series={[
+ {
+ id: "earnings",
+ valueAccessor: (d) => d.values.earnings / 100,
+ colorClassName: "text-[#8B5CF6]",
+ isActive: true,
+ },
+ ]}
+ >
+ <ChartContext.Consumer>
+ {(context) => (
+ <LinearGradient
+ id={`${id}-color-gradient`}
+ from="#8B5CF6"
+ to="#4C1D95"
+ x1={0}
+ x2={context?.width ?? 1}
+ gradientUnits="userSpaceOnUse"
+ />
+ )}
+ </ChartContext.Consumer>
+
+ <XAxis />
+ <YAxis showGridLines />
+ <Areas
+ seriesStyles={[
+ {
+ id: "earnings",
+ areaFill: `url(#${id}-color-gradient)`,
+ lineStroke: `url(#${id}-color-gradient)`,
+ lineClassName: "text-violet-500",
+ },
+ ]}
+ />
+ </TimeSeriesChart>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/page-client.tsx
index 38286b8dcc..1e0cddba3e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/page-client.tsx
@@ -2,10 +2,11 @@
import useProgram from "@/lib/swr/use-program";
import { ProgramProps } from "@/lib/types";
-import { Button, buttonVariants } from "@dub/ui";
+import { buttonVariants } from "@dub/ui";
import { cn } from "@dub/utils";
import Link from "next/link";
import { redirect, useParams } from "next/navigation";
+import { OverviewChart } from "./overview-chart";
export default function ProgramOverviewPageClient() {
const { slug, programId } = useParams();
@@ -18,59 +19,33 @@ export default function ProgramOverviewPageClient() {
return (
<div className="space-y-10">
<div className="rounded-lg border border-neutral-200 bg-gray-50 p-3">
- <div className="grid md:grid-cols-[2fr_1fr]"></div>
- </div>
- <div className="flex flex-col divide-y divide-neutral-200 rounded-md border border-neutral-200 bg-[#f9f9f9]">
- <div className="flex items-center justify-between px-4 py-4">
- <div className="flex flex-col gap-1">
- <span className="text-xs font-medium text-neutral-500">
- Sign up page
- </span>
- <span className="text-sm font-medium leading-none text-neutral-900">
- partner.dub.co/{program?.slug}
- </span>
- </div>
-
- <div className="flex items-center justify-between gap-5 divide-x divide-neutral-200">
- <div className="flex flex-col gap-1 text-right">
- <span className="text-xs font-medium text-neutral-500">
- Commission
- </span>
- <span className="text-sm font-medium leading-none text-neutral-900">
- {program.commissionAmount}
- {program.commissionType === "percentage" ? "%" : "$"}
- </span>
- </div>
-
- <div className="flex flex-col gap-1 pl-5 text-right">
- <span className="text-xs font-medium text-neutral-500">
- Cookie length
- </span>
- <span className="text-sm font-medium leading-none text-neutral-900">
- {program.cookieLength} days
- </span>
+ <div className="grid gap-6 md:grid-cols-[minmax(0,5fr)_minmax(0,3fr)] md:gap-10">
+ <OverviewChart />
+ <div className="flex flex-col rounded-lg bg-neutral-800 p-5">
+ <div className="flex items-center justify-between">
+ <h3 className="text-base font-semibold text-neutral-50">
+ Program
+ </h3>
+ <Link
+ href={`/${slug}/programs/${programId}/settings`}
+ className={cn(
+ buttonVariants({ variant: "secondary" }),
+ "flex h-7 items-center rounded-md border px-2 text-sm",
+ )}
+ >
+ Edit Program
+ </Link>
</div>
-
- <div className="flex flex-col gap-1 pl-5 text-right">
- <span className="text-xs font-medium text-neutral-500">
- Min payout
- </span>
- <span className="text-sm font-medium leading-none text-neutral-900">
- ${program.minimumPayout}
- </span>
+ <div className="mt-6 flex grow flex-col justify-end">
+ <p
+ className="text-xl text-white"
+ dangerouslySetInnerHTML={{
+ __html: commissionDescription(program),
+ }}
+ />
</div>
</div>
</div>
-
- <div className="flex flex-wrap items-center justify-center px-4 py-4">
- <div
- className="flex-1 text-sm leading-none text-neutral-900"
- dangerouslySetInnerHTML={{
- __html: commissionDescription(program),
- }}
- />
- <Button className="h-8 w-fit" text="Edit program" />
- </div>
</div>
<div className="flex flex-col gap-10 sm:flex-row">
<div className="basis-1/2">
@@ -117,31 +92,31 @@ export default function ProgramOverviewPageClient() {
}
const commissionDescription = (program: ProgramProps) => {
- const texts = ["Earn"];
+ const texts = ["Earn "];
if (program.commissionType === "flat") {
texts.push(
- `<span class="font-semibold text-blue-600">${program.commissionAmount}</span>`,
+ `<span class="font-medium text-blue-400">${program.commissionAmount}</span>`,
);
} else {
texts.push(
- `<span class="font-semibold text-blue-600">${program.commissionAmount}%</span>`,
+ `<span class="font-medium text-blue-400">${program.commissionAmount}%</span>`,
);
}
- texts.push("for each conversion");
+ texts.push(" for each conversion");
if (program.recurringCommission) {
if (program.isLifetimeRecurring) {
texts.push(
- "and again for all future renewals throughout <span class='font-semibold'>the customer's lifetime</span>",
+ ", and again for all future renewals throughout <span class='font-medium'>the customer's lifetime</span>",
);
} else {
texts.push(
- `and again for all renewals during the first <span class='font-semibold'>${program.recurringDuration} months</span>`,
+ `, and again for all renewals during the first <span class='font-medium'>${program.recurringDuration} months</span>`,
);
}
}
- return `${texts.join(" ")}.`;
+ return `${texts.join("")}.`;
};