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.

move ProgramCard and ProgramInviteCard into their own components

Steven Teyec5c736c7488
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/page-client.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/page-client.tsx
index d49bbe4ada..1188190026 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/page-client.tsx
@@ -1,24 +1,14 @@
"use client";
-import { acceptProgramInviteAction } from "@/lib/actions/partners/accept-program-invite";
-import usePartnerAnalytics from "@/lib/swr/use-partner-analytics";
import { ProgramInviteProps, ProgramProps } from "@/lib/types";
-import { ProgramCommissionDescription } from "@/ui/partners/program-commission-description";
+import { ProgramCard, ProgramCardSkeleton } from "@/ui/partners/program-card";
+import { ProgramInviteCard } from "@/ui/partners/program-invite-card";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
-import { MiniAreaChart } from "@dub/blocks";
-import { BlurImage, Button, MaxWidthWrapper } from "@dub/ui";
+import { MaxWidthWrapper } from "@dub/ui";
import { CircleDollar, GridIcon } from "@dub/ui/src/icons";
-import {
- currencyFormatter,
- DICEBEAR_AVATAR_URL,
- fetcher,
- nFormatter,
-} from "@dub/utils";
-import { useAction } from "next-safe-action/hooks";
-import Link from "next/link";
+import { fetcher } from "@dub/utils";
import { useParams } from "next/navigation";
-import { useMemo } from "react";
-import useSWR, { mutate } from "swr";
+import useSWR from "swr";
export function PartnersDashboardPageClient() {
const { partnerId } = useParams() as {
@@ -56,10 +46,18 @@ export function PartnersDashboardPageClient() {
Failed to load programs
</div>
) : (
- <ProgramsListSkeleton />
+ <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
+ {Array.from({ length: 3 }).map((_, idx) => (
+ <ProgramCardSkeleton key={idx} />
+ ))}
+ </div>
)
) : programs.length > 0 ? (
- <ProgramsList programs={programs} />
+ <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
+ {programs.map((program) => (
+ <ProgramCard key={program.id} program={program} />
+ ))}
+ </div>
) : (
<AnimatedEmptyState
title="No programs found"
@@ -79,158 +77,3 @@ export function PartnersDashboardPageClient() {
</MaxWidthWrapper>
);
}
-
-function ProgramInviteCard({ invite }: { invite: ProgramInviteProps }) {
- const { partnerId } = useParams() as { partnerId: string };
-
- const { executeAsync, isExecuting } = useAction(acceptProgramInviteAction, {
- onSuccess: () => {
- mutate(
- (key) =>
- typeof key === "string" &&
- key.startsWith(`/api/partners/${partnerId}/programs`),
- undefined,
- { revalidate: true },
- );
- },
- });
-
- return (
- <div className="flex items-center justify-between rounded-md border border-neutral-300 bg-white p-4">
- <div className="flex items-center gap-4">
- <BlurImage
- width={96}
- height={96}
- src={
- invite.program.logo ||
- `${DICEBEAR_AVATAR_URL}${invite.program.name}`
- }
- alt={invite.program.name}
- className="size-6 rounded-full"
- />
- <div className="flex flex-col gap-0.5">
- <span className="text-base font-medium text-neutral-900">
- {invite.program.name}
- </span>
- <span className="text-sm text-neutral-600">
- <ProgramCommissionDescription program={invite.program} />
- </span>
- </div>
- </div>
- <Button
- text="Accept invite"
- className="h-9 w-fit"
- loading={isExecuting}
- onClick={() =>
- executeAsync({
- partnerId,
- programInviteId: invite.id,
- })
- }
- />
- </div>
- );
-}
-
-function ProgramsList({ programs }: { programs: ProgramProps[] }) {
- return (
- <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
- {programs.map((program) => (
- <ProgramCard key={program.id} program={program} />
- ))}
- </div>
- );
-}
-
-function ProgramCard({ program }: { program: ProgramProps }) {
- const { partnerId } = useParams() as {
- partnerId?: string;
- };
-
- const { data: analytics } = usePartnerAnalytics({
- programId: program.id,
- });
- const { data: timeseries } = usePartnerAnalytics({
- programId: program.id,
- groupBy: "timeseries",
- interval: "30d",
- });
-
- const chartData = useMemo(
- () =>
- timeseries?.map((d) => ({
- date: new Date(d.start),
- value: d.earnings,
- })),
- [timeseries],
- );
-
- return (
- <Link
- href={`/${partnerId}/${program.id}`}
- className="hover:drop-shadow-card-hover block rounded-md border border-neutral-300 bg-white p-4 transition-[filter]"
- >
- <div className="flex items-center gap-4">
- <div className="flex size-10 items-center justify-center rounded-full border border-gray-200 bg-gradient-to-t from-gray-100">
- <BlurImage
- width={96}
- height={96}
- src={program.logo || `${DICEBEAR_AVATAR_URL}${program.name}`}
- alt={program.name}
- className="size-6 rounded-full"
- />
- </div>
- <div className="flex flex-col gap-0.5">
- <span className="text-base font-medium text-neutral-900">
- {program.name}
- </span>
- {analytics ? (
- <span className="text-sm leading-none text-neutral-600">
- {nFormatter(analytics?.sales)} sales
- </span>
- ) : (
- <div className="h-3.5 w-20 animate-pulse rounded-md bg-neutral-200" />
- )}
- </div>
- </div>
- <div className="mt-6 grid grid-cols-[min-content,minmax(0,1fr)] gap-4 rounded-md border border-neutral-100 bg-neutral-50 p-5">
- <div>
- <div className="whitespace-nowrap text-sm text-neutral-500">
- Earnings
- </div>
- {analytics ? (
- <div className="mt-1 text-2xl font-medium leading-none text-neutral-800">
- {currencyFormatter(analytics?.earnings / 100 || 0)}
- </div>
- ) : (
- <div className="mt-1 h-6 w-20 animate-pulse rounded-md bg-neutral-200" />
- )}
- </div>
- {chartData && (
- <div className="relative h-full">
- <MiniAreaChart data={chartData} />
- </div>
- )}
- </div>
- </Link>
- );
-}
-
-function ProgramsListSkeleton() {
- return (
- <div className="grid animate-pulse gap-4 md:grid-cols-2 lg:grid-cols-3">
- {[...Array(2)].map((_, idx) => (
- <div key={idx} className="rounded-md border border-neutral-300 p-4">
- <div className="flex items-center gap-4">
- <div className="size-12 rounded-full bg-neutral-200" />
- <div className="flex flex-col gap-0.5">
- <div className="h-6 w-24 min-w-0 rounded-md bg-neutral-200" />
- <div className="h-3.5 w-20 animate-pulse rounded-md bg-neutral-200" />
- </div>
- </div>
- <div className="mt-6 grid h-[90px] animate-pulse rounded-md bg-neutral-100" />
- </div>
- ))}
- </div>
- );
-}
diff --git a/apps/web/ui/partners/program-card.tsx b/apps/web/ui/partners/program-card.tsx
new file mode 100644
index 0000000000..13944f7b65
--- /dev/null
+++ b/apps/web/ui/partners/program-card.tsx
@@ -0,0 +1,97 @@
+import usePartnerAnalytics from "@/lib/swr/use-partner-analytics";
+import { ProgramProps } from "@/lib/types";
+import { MiniAreaChart } from "@dub/blocks";
+import { BlurImage } from "@dub/ui";
+import { currencyFormatter, DICEBEAR_AVATAR_URL, nFormatter } from "@dub/utils";
+import Link from "next/link";
+import { useParams } from "next/navigation";
+import { useMemo } from "react";
+
+export function ProgramCard({ program }: { program: ProgramProps }) {
+ const { partnerId } = useParams() as {
+ partnerId?: string;
+ };
+
+ const { data: analytics } = usePartnerAnalytics({
+ programId: program.id,
+ });
+ const { data: timeseries } = usePartnerAnalytics({
+ programId: program.id,
+ groupBy: "timeseries",
+ interval: "30d",
+ });
+
+ const chartData = useMemo(
+ () =>
+ timeseries?.map((d) => ({
+ date: new Date(d.start),
+ value: d.earnings,
+ })),
+ [timeseries],
+ );
+
+ return (
+ <Link
+ href={`/${partnerId}/${program.id}`}
+ className="hover:drop-shadow-card-hover block rounded-md border border-neutral-300 bg-white p-4 transition-[filter]"
+ >
+ <div className="flex items-center gap-4">
+ <div className="flex size-10 items-center justify-center rounded-full border border-gray-200 bg-gradient-to-t from-gray-100">
+ <BlurImage
+ width={96}
+ height={96}
+ src={program.logo || `${DICEBEAR_AVATAR_URL}${program.name}`}
+ alt={program.name}
+ className="size-6 rounded-full"
+ />
+ </div>
+ <div className="flex flex-col gap-0.5">
+ <span className="text-base font-medium text-neutral-900">
+ {program.name}
+ </span>
+ {analytics ? (
+ <span className="text-sm leading-none text-neutral-600">
+ {nFormatter(analytics?.sales)} sales
+ </span>
+ ) : (
+ <div className="h-3.5 w-20 animate-pulse rounded-md bg-neutral-200" />
+ )}
+ </div>
+ </div>
+ <div className="mt-6 grid grid-cols-[min-content,minmax(0,1fr)] gap-4 rounded-md border border-neutral-100 bg-neutral-50 p-5">
+ <div>
+ <div className="whitespace-nowrap text-sm text-neutral-500">
+ Earnings
+ </div>
+ {analytics ? (
+ <div className="mt-1 text-2xl font-medium leading-none text-neutral-800">
+ {currencyFormatter(analytics?.earnings / 100 || 0)}
+ </div>
+ ) : (
+ <div className="mt-1 h-6 w-20 animate-pulse rounded-md bg-neutral-200" />
+ )}
+ </div>
+ {chartData && (
+ <div className="relative h-full">
+ <MiniAreaChart data={chartData} />
+ </div>
+ )}
+ </div>
+ </Link>
+ );
+}
+
+export function ProgramCardSkeleton() {
+ return (
+ <div className="rounded-md border border-neutral-300 p-4">
+ <div className="flex items-center gap-4">
+ <div className="size-12 rounded-full bg-neutral-200" />
+ <div className="flex flex-col gap-0.5">
+ <div className="h-6 w-24 min-w-0 rounded-md bg-neutral-200" />
+ <div className="h-3.5 w-20 animate-pulse rounded-md bg-neutral-200" />
+ </div>
+ </div>
+ <div className="mt-6 grid h-[90px] animate-pulse rounded-md bg-neutral-100" />
+ </div>
+ );
+}
diff --git a/apps/web/ui/partners/program-invite-card.tsx b/apps/web/ui/partners/program-invite-card.tsx
new file mode 100644
index 0000000000..80ba88b4d1
--- /dev/null
+++ b/apps/web/ui/partners/program-invite-card.tsx
@@ -0,0 +1,60 @@
+import { acceptProgramInviteAction } from "@/lib/actions/partners/accept-program-invite";
+import { ProgramInviteProps } from "@/lib/types";
+import { ProgramCommissionDescription } from "@/ui/partners/program-commission-description";
+import { BlurImage, Button } from "@dub/ui";
+import { DICEBEAR_AVATAR_URL } from "@dub/utils";
+import { useAction } from "next-safe-action/hooks";
+import { useParams } from "next/navigation";
+import { mutate } from "swr";
+
+export function ProgramInviteCard({ invite }: { invite: ProgramInviteProps }) {
+ const { partnerId } = useParams() as { partnerId: string };
+
+ const { executeAsync, isExecuting } = useAction(acceptProgramInviteAction, {
+ onSuccess: () => {
+ mutate(
+ (key) =>
+ typeof key === "string" &&
+ key.startsWith(`/api/partners/${partnerId}/programs`),
+ undefined,
+ { revalidate: true },
+ );
+ },
+ });
+
+ return (
+ <div className="flex items-center justify-between rounded-md border border-neutral-300 bg-white p-4">
+ <div className="flex items-center gap-4">
+ <BlurImage
+ width={96}
+ height={96}
+ src={
+ invite.program.logo ||
+ `${DICEBEAR_AVATAR_URL}${invite.program.name}`
+ }
+ alt={invite.program.name}
+ className="size-6 rounded-full"
+ />
+ <div className="flex flex-col gap-0.5">
+ <span className="text-base font-medium text-neutral-900">
+ {invite.program.name}
+ </span>
+ <span className="text-sm text-neutral-600">
+ <ProgramCommissionDescription program={invite.program} />
+ </span>
+ </div>
+ </div>
+ <Button
+ text="Accept invite"
+ className="h-9 w-fit"
+ loading={isExecuting}
+ onClick={() =>
+ executeAsync({
+ partnerId,
+ programInviteId: invite.id,
+ })
+ }
+ />
+ </div>
+ );
+}