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.

update the new stats UI

Kiran K776d1d025102
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/page.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/page.tsx
index 275437b22f..f98c4a0ecc 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/page.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/page.tsx
@@ -1,14 +1,14 @@
import { PageContent } from "@/ui/layout/page-content";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { PartnerPayoutSettingsButton } from "./partner-payout-settings-button";
-import { PayoutStatsAndSettings } from "./payout-stats-and-settings";
+import { PayoutStats } from "./payout-stats";
import { PayoutTable } from "./payout-table";
export default function PartnersPayoutsSettings() {
return (
<PageContent title="Payouts" controls={<PartnerPayoutSettingsButton />}>
<PageWidthWrapper className="grid grid-cols-1 gap-4 pb-10">
- <PayoutStatsAndSettings />
+ <PayoutStats />
<PayoutTable />
</PageWidthWrapper>
</PageContent>
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats-and-settings.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats-and-settings.tsx
deleted file mode 100644
index b659e86685..0000000000
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats-and-settings.tsx
+++ /dev/null
@@ -1,85 +0,0 @@
-"use client";
-
-import usePartnerPayoutsCount from "@/lib/swr/use-partner-payouts-count";
-import usePartnerProfile from "@/lib/swr/use-partner-profile";
-import { PayoutsCount } from "@/lib/types";
-import { ConnectPayoutButton } from "@/ui/partners/connect-payout-button";
-import { PayoutMethodsDropdown } from "@/ui/partners/payout-methods-dropdown";
-import { AlertCircleFill } from "@/ui/shared/icons";
-import { PayoutStatus } from "@dub/prisma/client";
-import { Tooltip } from "@dub/ui";
-import NumberFlow from "@number-flow/react";
-
-export function PayoutStatsAndSettings() {
- const { partner } = usePartnerProfile();
- const { payoutsCount } = usePartnerPayoutsCount<PayoutsCount[]>({
- groupBy: "status",
- });
-
- return (
- <div className="grid grid-cols-1 divide-neutral-200 rounded-lg border border-neutral-200 max-sm:divide-y sm:grid-cols-2 sm:divide-x">
- <div className="flex flex-col gap-1.5 p-4">
- <div className="flex justify-between gap-5">
- <div className="p-1">
- <div className="text-sm text-neutral-500">Upcoming payouts</div>
- </div>
- {partner && !partner.payoutsEnabledAt && (
- <ConnectPayoutButton className="h-8 w-fit px-3" />
- )}
- </div>
- <div className="flex items-end justify-between gap-5">
- <div className="mt-2 flex items-center gap-2">
- {partner && !partner.payoutsEnabledAt && (
- <Tooltip
- content="You need to connect your bank account to be able to receive payouts from the programs you are enrolled in."
- side="right"
- >
- <div>
- <AlertCircleFill className="size-5 text-black" />
- </div>
- </Tooltip>
- )}
-
- <NumberFlow
- className="text-2xl text-neutral-800"
- value={
- (payoutsCount?.find((p) => p.status === PayoutStatus.pending)
- ?.amount ?? 0) / 100
- }
- format={{
- style: "currency",
- currency: "USD",
- }}
- />
- </div>
-
- {partner?.payoutsEnabledAt && <PayoutMethodsDropdown />}
- </div>
- </div>
-
- <div className="flex flex-col gap-1.5 p-4">
- <div className="flex justify-between gap-5">
- <div className="p-1">
- <div className="text-sm text-neutral-500">Total payouts</div>
- </div>
- </div>
- <NumberFlow
- className="mt-2 text-2xl text-neutral-800"
- value={
- (payoutsCount
- ?.filter(
- (p) =>
- p.status === PayoutStatus.completed ||
- p.status === PayoutStatus.processing,
- )
- .reduce((acc, p) => acc + p.amount, 0) ?? 0) / 100
- }
- format={{
- style: "currency",
- currency: "USD",
- }}
- />
- </div>
- </div>
- );
-}
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx
new file mode 100644
index 0000000000..f48e0ea7ee
--- /dev/null
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx
@@ -0,0 +1,144 @@
+"use client";
+
+import usePartnerPayoutsCount from "@/lib/swr/use-partner-payouts-count";
+import { PayoutsCount } from "@/lib/types";
+import { PayoutStatus } from "@dub/prisma/client";
+import {
+ InfoTooltip,
+ LoadingCircle,
+ PaperPlane,
+ Success,
+ TriangleWarning,
+} from "@dub/ui";
+import { cn, currencyFormatter } from "@dub/utils";
+import { ReactNode } from "react";
+
+function PayoutStatsCard({
+ label,
+ amount,
+ icon: Icon,
+ iconClassName,
+ tooltip,
+ sublabel,
+ error,
+}: {
+ label: string;
+ amount: number;
+ icon: any;
+ iconClassName?: string;
+ tooltip: string;
+ sublabel?: ReactNode;
+ error?: boolean;
+}) {
+ const isLoading = amount === undefined || error;
+
+ console.log({
+ label,
+ isLoading,
+ amount,
+ error,
+ });
+
+ return (
+ <div className="flex min-w-[200px] flex-col gap-3 p-4">
+ <div className="flex items-center gap-2">
+ <div
+ className={cn(
+ "flex size-6 items-center justify-center rounded-md",
+ iconClassName,
+ )}
+ >
+ <Icon className="size-4" />
+ </div>
+ <span className="text-xs font-medium leading-3 text-neutral-500">
+ {label}
+ </span>
+ <InfoTooltip content={tooltip} side="top" className="size-3.5" />
+ </div>
+
+ <div className="flex items-end gap-2">
+ {!isLoading ? (
+ <span className="text-xl font-medium leading-7 text-neutral-800">
+ {error ? (
+ "-"
+ ) : (
+ <>
+ USD{" "}
+ {amount > 0
+ ? currencyFormatter(amount / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ })
+ : "0.00"}
+ </>
+ )}
+ </span>
+ ) : (
+ <div className="h-7 w-24 animate-pulse rounded bg-neutral-200" />
+ )}
+
+ {/* {sublabel && (
+ <span className="ml-2 text-xs text-neutral-500">{sublabel}</span>
+ )} */}
+ </div>
+ </div>
+ );
+}
+
+export function PayoutStats() {
+ const { payoutsCount, error } = usePartnerPayoutsCount<PayoutsCount[]>({
+ groupBy: "status",
+ });
+
+ const payoutStatusMap = Object.fromEntries(
+ payoutsCount?.map((p) => [p.status, p]) || [],
+ ) as Record<PayoutStatus, PayoutsCount>;
+
+ const payoutStats = [
+ {
+ label: "Pending",
+ amount: payoutStatusMap?.pending?.amount,
+ icon: TriangleWarning,
+ iconClassName: "bg-orange-100 text-orange-500",
+ tooltip:
+ "Payouts that have passed the program’s holding period and are waiting to be processed.",
+ error: !!error,
+ },
+ {
+ label: "Processing",
+ amount: payoutStatusMap?.processing?.amount,
+ icon: LoadingCircle,
+ iconClassName: "bg-blue-100 text-blue-500",
+ tooltip:
+ "Payouts that have been processed by the program and are on their way to your Stripe Express account.",
+ error: !!error,
+ },
+ {
+ label: "Sent",
+ amount: payoutStatusMap?.sent?.amount,
+ icon: PaperPlane,
+ iconClassName: "bg-indigo-100 text-indigo-500",
+ tooltip:
+ "Payouts that have been sent to your Stripe Express account and will be automatically paid out once they reach your minimum withdrawal balance.",
+ sublabel: "Est: 4 business days",
+ error: !!error,
+ },
+ {
+ label: "Complete",
+ amount: payoutStatusMap?.completed?.amount,
+ icon: Success,
+ iconClassName: "bg-green-100 text-green-500",
+ tooltip:
+ "Payouts that have been paid out from Stripe to your connected bank account.",
+ error: !!error,
+ },
+ ];
+
+ return (
+ <div className="grid grid-cols-1 gap-4 divide-y-0 rounded-lg border border-neutral-200 sm:grid-cols-2 lg:grid-cols-4 lg:divide-x">
+ {payoutStats.map((stat) => (
+ <PayoutStatsCard key={stat.label} {...stat} />
+ ))}
+ </div>
+ );
+}