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.

fix YAxix bug, add new admin page

Steven Tey149961624259
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/layout-nav-client.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/layout-nav-client.tsx
index b6bc389f70..b1b6801581 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/layout-nav-client.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/layout-nav-client.tsx
@@ -8,6 +8,7 @@ import {
useMediaQuery,
} from "@dub/ui";
import Link from "next/link";
+import { usePathname } from "next/navigation";
import { useState } from "react";
const tabs = [
@@ -36,19 +37,26 @@ const tabs = [
export function AdminNav() {
const [openPopover, setOpenPopover] = useState(false);
const { isMobile } = useMediaQuery();
+ const pathname = usePathname();
const NavContent = () => (
<div className="flex w-full flex-col gap-1 p-2">
- {tabs.map((tab) => (
- <Link
- href={tab.href}
- key={tab.href}
- className="block w-full rounded-md px-4 py-2 text-left text-sm text-neutral-700 transition-colors hover:bg-neutral-100 active:bg-neutral-200"
- onClick={() => setOpenPopover(false)}
- >
- {tab.label}
- </Link>
- ))}
+ {tabs.map((tab) => {
+ const isActive =
+ pathname === tab.href || pathname?.startsWith(`${tab.href}/`);
+ return (
+ <Link
+ href={tab.href}
+ key={tab.href}
+ className={`block w-full rounded-md px-4 py-2 text-left text-sm text-neutral-700 transition-colors hover:bg-neutral-100 active:bg-neutral-200 ${
+ isActive ? "bg-neutral-100" : ""
+ }`}
+ onClick={() => setOpenPopover(false)}
+ >
+ {tab.label}
+ </Link>
+ );
+ })}
</div>
);
@@ -87,16 +95,25 @@ export function AdminNav() {
</Popover>
</div>
) : (
- <div className="flex items-center gap-12">
- {tabs.map((tab) => (
- <Link
- href={tab.href}
- key={tab.href}
- className="text-sm text-neutral-500"
- >
- {tab.label}
- </Link>
- ))}
+ <div className="flex items-center gap-4">
+ {tabs.map((tab) => {
+ const isActive =
+ pathname === tab.href ||
+ pathname?.startsWith(`${tab.href}/`);
+ return (
+ <Link
+ href={tab.href}
+ key={tab.href}
+ className={`rounded-md px-3 py-1.5 text-sm transition-colors ${
+ isActive
+ ? "bg-neutral-100 text-neutral-900"
+ : "text-neutral-500 hover:text-neutral-700"
+ }`}
+ >
+ {tab.label}
+ </Link>
+ );
+ })}
</div>
)}
</ClientOnly>
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/client.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/client.tsx
index 56fde418c3..e975d0258a 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/client.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/client.tsx
@@ -7,6 +7,7 @@ import { FilterButtonTableRow } from "@/ui/shared/filter-button-table-row";
import SimpleDateRangePicker from "@/ui/shared/simple-date-range-picker";
import { InvoiceStatus } from "@dub/prisma/client";
import {
+ Button,
Filter,
StatusBadge,
Table,
@@ -15,7 +16,7 @@ import {
useTable,
} from "@dub/ui";
import { Areas, TimeSeriesChart, XAxis, YAxis } from "@dub/ui/charts";
-import { CircleDotted, GridIcon } from "@dub/ui/icons";
+import { CircleDotted, GridIcon, Paypal } from "@dub/ui/icons";
import {
cn,
currencyFormatter,
@@ -24,6 +25,7 @@ import {
OG_AVATAR_URL,
} from "@dub/utils";
import NumberFlow from "@number-flow/react";
+import Link from "next/link";
import { Fragment, useCallback, useMemo, useState } from "react";
import useSWR from "swr";
@@ -167,9 +169,6 @@ export default function PayoutsPageClient() {
[queryParams],
);
- const [selectedFilter, setSelectedFilter] = useState<string | null>(null);
- const [search, setSearch] = useState("");
-
const tabs: Tab[] = [
{
id: "payouts",
@@ -323,13 +322,18 @@ export default function PayoutsPageClient() {
activeFilters={activeFilters}
onSelect={onSelect}
onRemove={onRemove}
- onSearchChange={setSearch}
- onSelectedFilterChange={setSelectedFilter}
/>
<SimpleDateRangePicker
defaultInterval="mtd"
className="w-full sm:min-w-[200px] md:w-fit"
/>
+ <Link href="/payouts/paypal">
+ <Button
+ variant="secondary"
+ text="Paypal payouts"
+ icon={<Paypal className="size-4" />}
+ />
+ </Link>
</div>
{activeFilters.length > 0 && (
<div>
@@ -343,7 +347,7 @@ export default function PayoutsPageClient() {
</div>
)}
<div className="flex flex-col divide-y divide-neutral-200 rounded-lg border border-neutral-200 bg-white">
- <div className="scrollbar-hide grid w-full grid-cols-3 divide-x overflow-y-hidden">
+ <div className="scrollbar-hide grid w-full grid-cols-1 divide-y overflow-y-hidden sm:grid-cols-3 sm:divide-x sm:divide-y-0">
{tabs.map(({ id, label, colorClassName }) => {
return (
<button
@@ -361,12 +365,9 @@ export default function PayoutsPageClient() {
)}
>
{/* Active tab indicator */}
- <div
- className={cn(
- "absolute bottom-0 left-0 h-0.5 w-full bg-black transition-transform duration-100",
- selectedTab !== id && "translate-y-[3px]",
- )}
- />
+ {selectedTab === id && (
+ <div className="absolute bottom-0 left-0 h-0.5 w-full bg-black" />
+ )}
<div className="flex items-center gap-2.5 text-sm text-neutral-600">
<div
className={cn(
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/paypal/client.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/paypal/client.tsx
new file mode 100644
index 0000000000..00a42e23a3
--- /dev/null
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/paypal/client.tsx
@@ -0,0 +1,224 @@
+"use client";
+
+import type { PaypalPayoutResponse } from "@/lib/paypal/get-pending-payouts";
+import { PayoutStatusBadges } from "@/ui/partners/payout-status-badges";
+import { Button, StatusBadge, Table, usePagination, useTable } from "@dub/ui";
+import { Globe } from "@dub/ui/icons";
+import {
+ cn,
+ COUNTRIES,
+ currencyFormatter,
+ fetcher,
+ nFormatter,
+ OG_AVATAR_URL,
+} from "@dub/utils";
+import NumberFlow from "@number-flow/react";
+import { ChevronLeft } from "lucide-react";
+import Link from "next/link";
+import { useMemo } from "react";
+import useSWR from "swr";
+
+export default function PaypalPayoutsPageClient() {
+ const { data: payouts = [], isLoading } = useSWR<PaypalPayoutResponse[]>(
+ "/api/admin/payouts/paypal",
+ fetcher,
+ {
+ keepPreviousData: true,
+ },
+ );
+
+ const { pagination, setPagination } = usePagination(100);
+
+ // Client-side pagination
+ const paginatedPayouts = useMemo(() => {
+ const start = (pagination.pageIndex - 1) * pagination.pageSize;
+ const end = start + pagination.pageSize;
+ return payouts.slice(start, end);
+ }, [payouts, pagination.pageIndex, pagination.pageSize]);
+
+ const { table, ...tableProps } = useTable({
+ data: paginatedPayouts,
+ columns: [
+ {
+ id: "partner",
+ header: "Partner",
+ cell: ({ row }) => (
+ <div className="flex items-center gap-1.5">
+ <img
+ src={
+ row.original.partner.image ||
+ `${OG_AVATAR_URL}${row.original.partner.email || ""}`
+ }
+ alt={row.original.partner.email || ""}
+ width={20}
+ height={20}
+ className="size-4 rounded-full"
+ />
+ <span className="text-sm text-neutral-900">
+ {row.original.partner.email || "-"}
+ </span>
+ </div>
+ ),
+ },
+ {
+ id: "country",
+ header: "Country",
+ accessorKey: "partner.country",
+ cell: ({ row }) => {
+ const country = row.original.partner.country;
+ if (!country || country === "Unknown") {
+ return (
+ <div className="flex items-center gap-3">
+ <Globe className="size-4 shrink-0" />
+ <span className="text-sm text-neutral-900">Unknown</span>
+ </div>
+ );
+ }
+ return (
+ <div
+ className="flex items-center gap-3"
+ title={COUNTRIES[country] ?? country}
+ >
+ <img
+ alt={country}
+ src={`https://hatscripts.github.io/circle-flags/flags/${country.toLowerCase()}.svg`}
+ className="size-4 shrink-0"
+ />
+ <span className="truncate text-sm text-neutral-900">
+ {COUNTRIES[country] ?? country}
+ </span>
+ </div>
+ );
+ },
+ },
+ {
+ id: "program",
+ header: "Program",
+ cell: ({ row }) => (
+ <div className="flex items-center gap-1.5">
+ <img
+ src={
+ row.original.program.logo ||
+ `${OG_AVATAR_URL}${row.original.program.name}`
+ }
+ alt={row.original.program.name}
+ width={20}
+ height={20}
+ className="size-4 rounded-full"
+ />
+ <span className="text-sm font-medium">
+ {row.original.program.name}
+ </span>
+ </div>
+ ),
+ },
+ {
+ id: "status",
+ header: "Status",
+ cell: ({ row }) => {
+ const badge = PayoutStatusBadges[row.original.status];
+
+ return badge ? (
+ <StatusBadge icon={badge.icon} variant={badge.variant}>
+ {badge.label}
+ </StatusBadge>
+ ) : (
+ "-"
+ );
+ },
+ },
+ {
+ id: "amount",
+ header: "Amount",
+ accessorKey: "amount",
+ cell: ({ row }) => currencyFormatter(row.original.amount),
+ },
+ ],
+ pagination,
+ onPaginationChange: setPagination,
+ resourceName: (plural) => `payout${plural ? "s" : ""}`,
+ rowCount: payouts.length,
+ loading: isLoading,
+ });
+
+ const stats = useMemo(() => {
+ const allPayouts = payouts;
+ const processingPayouts = payouts.filter((p) => p.status === "processing");
+ const pendingPayouts = payouts.filter((p) => p.status === "pending");
+
+ return [
+ {
+ id: "all",
+ label: "Total payouts",
+ amount: allPayouts.reduce((acc, p) => acc + p.amount, 0),
+ count: allPayouts.length,
+ colorClassName: "bg-blue-500",
+ },
+ {
+ id: "processing",
+ label: "Processing payouts",
+ amount: processingPayouts.reduce((acc, p) => acc + p.amount, 0),
+ count: processingPayouts.length,
+ colorClassName: "bg-purple-500",
+ },
+ {
+ id: "pending",
+ label: "Pending payouts",
+ amount: pendingPayouts.reduce((acc, p) => acc + p.amount, 0),
+ count: pendingPayouts.length,
+ colorClassName: "bg-orange-500",
+ },
+ ];
+ }, [payouts]);
+
+ return (
+ <div className="mx-auto flex w-full max-w-screen-xl flex-col gap-3 p-6">
+ <div className="flex items-center justify-start">
+ <Link href="/payouts">
+ <Button
+ variant="secondary"
+ text="Back to all payouts"
+ icon={<ChevronLeft className="size-4" />}
+ />
+ </Link>
+ </div>
+ <div className="grid grid-cols-1 divide-y divide-neutral-200 rounded-lg border border-neutral-200 bg-white sm:grid-cols-3 sm:flex-row sm:divide-x sm:divide-y-0">
+ {stats.map(({ id, label, amount, count, colorClassName }) => (
+ <div key={id} className="flex-none px-4 py-3 sm:px-8 sm:py-6">
+ <div className="flex items-center gap-2.5 text-sm text-neutral-600">
+ <div
+ className={cn(
+ "h-2 w-2 rounded-sm shadow-[inset_0_0_0_1px_#00000019]",
+ colorClassName,
+ )}
+ />
+ <span>{label}</span>
+ </div>
+ <div className="mt-1 flex h-12 items-center">
+ {!isLoading ? (
+ <div className="flex items-baseline gap-2">
+ <NumberFlow
+ value={amount / 100}
+ className="text-xl font-medium sm:text-3xl"
+ format={{
+ style: "currency",
+ currency: "USD",
+ }}
+ />
+ <span className="text-sm text-neutral-500">
+ ({nFormatter(count, { full: true })})
+ </span>
+ </div>
+ ) : (
+ <div className="h-10 w-24 animate-pulse rounded-md bg-neutral-200" />
+ )}
+ </div>
+ </div>
+ ))}
+ </div>
+ <div className="w-full">
+ <Table {...tableProps} table={table} />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/paypal/page.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/paypal/page.tsx
new file mode 100644
index 0000000000..0975a860bc
--- /dev/null
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/paypal/page.tsx
@@ -0,0 +1,10 @@
+import { Suspense } from "react";
+import PaypalPayoutsPageClient from "./client";
+
+export default async function PaypalPayoutsPage() {
+ return (
+ <Suspense>
+ <PaypalPayoutsPageClient />
+ </Suspense>
+ );
+}
diff --git a/apps/web/app/(ee)/api/admin/payouts/paypal/route.ts b/apps/web/app/(ee)/api/admin/payouts/paypal/route.ts
new file mode 100644
index 0000000000..721a591099
--- /dev/null
+++ b/apps/web/app/(ee)/api/admin/payouts/paypal/route.ts
@@ -0,0 +1,8 @@
+import { withAdmin } from "@/lib/auth/admin";
+import { getPendingPaypalPayouts } from "@/lib/paypal/get-pending-payouts";
+import { NextResponse } from "next/server";
+
+export const GET = withAdmin(async () => {
+ const pendingPaypalPayouts = await getPendingPaypalPayouts();
+ return NextResponse.json(pendingPaypalPayouts);
+});
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/overview-chart.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/overview-chart.tsx
index 39785bfeb5..75c8e6733f 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/overview-chart.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/overview-chart.tsx
@@ -190,7 +190,10 @@ export function OverviewChart() {
formatDateTooltip(date, { interval, start, end })
}
/>
- <YAxis showGridLines tickFormat={currencyFormatter} />
+ <YAxis
+ showGridLines
+ tickFormat={viewType === "leads" ? nFormatter : currencyFormatter}
+ />
<Areas />
</TimeSeriesChart>
)}
diff --git a/apps/web/lib/paypal/get-pending-payouts.ts b/apps/web/lib/paypal/get-pending-payouts.ts
index 90b1db7180..19e86ff411 100644
--- a/apps/web/lib/paypal/get-pending-payouts.ts
+++ b/apps/web/lib/paypal/get-pending-payouts.ts
@@ -1,5 +1,28 @@
import { prisma } from "@dub/prisma";
import { PAYPAL_SUPPORTED_COUNTRIES } from "@dub/utils";
+import { PayoutStatus } from "@prisma/client";
+import { z } from "zod";
+import { PartnerSchema } from "../zod/schemas/partners";
+import { ProgramSchema } from "../zod/schemas/programs";
+
+const PaypalPayoutResponseSchema = z.object({
+ program: ProgramSchema.pick({
+ id: true,
+ name: true,
+ logo: true,
+ }),
+ partner: PartnerSchema.pick({
+ id: true,
+ name: true,
+ email: true,
+ image: true,
+ country: true,
+ }),
+ status: z.nativeEnum(PayoutStatus),
+ amount: z.number(),
+});
+
+export type PaypalPayoutResponse = z.infer<typeof PaypalPayoutResponseSchema>;
export async function getPendingPaypalPayouts() {
const payouts = await prisma.payout.findMany({
@@ -19,15 +42,20 @@ export async function getPendingPaypalPayouts() {
},
},
},
+ orderBy: {
+ amount: "desc",
+ },
include: {
partner: true,
program: true,
},
});
- const eligiblePayouts = payouts.filter(
- (payout) => payout.amount >= payout.program.minPayoutAmount,
- );
-
- return eligiblePayouts;
+ return z
+ .array(PaypalPayoutResponseSchema)
+ .parse(
+ payouts.filter(
+ (payout) => payout.amount >= payout.program.minPayoutAmount,
+ ),
+ );
}
diff --git a/apps/web/scripts/partners/check-pending-paypal-payouts.ts b/apps/web/scripts/partners/check-pending-paypal-payouts.ts
index f818f256bf..a266e25dfe 100644
--- a/apps/web/scripts/partners/check-pending-paypal-payouts.ts
+++ b/apps/web/scripts/partners/check-pending-paypal-payouts.ts
@@ -21,7 +21,7 @@ async function main() {
partner: payout.partner.email,
status: payout.status,
country: payout.partner.country,
- amount: payout.amount,
+ amount: payout.amount / 100,
}));
console.table(finalPayouts);