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.

Add payout details sheet

Tim Wilson64c46ceab0b8
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-details-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-details-sheet.tsx
new file mode 100644
index 0000000000..8c3748cada
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-details-sheet.tsx
@@ -0,0 +1,206 @@
+import { PayoutWithPartnerProps } from "@/lib/types";
+import { X } from "@/ui/shared/icons";
+import {
+ Button,
+ Sheet,
+ StatusBadge,
+ Table,
+ useTable,
+ useTablePagination,
+} from "@dub/ui";
+import { capitalize, cn, currencyFormatter, formatDate } from "@dub/utils";
+import { subDays } from "date-fns";
+import { Dispatch, Fragment, SetStateAction, useMemo, useState } from "react";
+import { toast } from "sonner";
+import { StatusBadges } from "./payout-table";
+
+function PayoutDetailsSheetContent({
+ payout,
+ setIsOpen,
+}: {
+ payout: PayoutWithPartnerProps;
+ setIsOpen: Dispatch<SetStateAction<boolean>>;
+}) {
+ const canConfirmPayout = ["created", "pending", "flagged", "failed"].includes(
+ payout.status,
+ );
+
+ // TODO: Fetch real data
+ const totalConversions = 2;
+ const conversions = [
+ {
+ id: "1",
+ date: subDays(payout.periodEnd, 1).toISOString(),
+ customer: {
+ email: "[email protected]",
+ },
+ amount: 1000,
+ },
+ {
+ id: "2",
+ date: subDays(payout.periodEnd, 2).toISOString(),
+ customer: {
+ email: "[email protected]",
+ },
+ amount: 1600,
+ },
+ ];
+ const totalConversionsError = null;
+ const loadingTotalConversions =
+ totalConversions === undefined && !totalConversionsError;
+ const error = null;
+ const loading = !conversions && !error;
+
+ const invoiceData = useMemo(() => {
+ const statusBadge = StatusBadges[payout.status];
+ return {
+ Partner: payout.partner.name,
+ Period: `${formatDate(payout.periodStart, {
+ month: "short",
+ year:
+ new Date(payout.periodStart).getFullYear() ===
+ new Date(payout.periodEnd).getFullYear()
+ ? undefined
+ : "numeric",
+ })}-${formatDate(payout.periodEnd, { month: "short" })}`,
+ Total: currencyFormatter(payout.total / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ }),
+ Conversions: totalConversionsError ? (
+ "-"
+ ) : loadingTotalConversions ? (
+ <div className="h-5 w-10 animate-pulse rounded-md bg-neutral-200" />
+ ) : (
+ totalConversions
+ ),
+ Status: (
+ <StatusBadge variant={statusBadge.variant} icon={statusBadge.icon}>
+ {statusBadge.label}
+ </StatusBadge>
+ ),
+ };
+ }, [
+ payout,
+ totalConversions,
+ totalConversionsError,
+ loadingTotalConversions,
+ ]);
+
+ const { pagination, setPagination } = useTablePagination({
+ pageSize: 100,
+ page: 1,
+ });
+
+ const showPagination = totalConversions > 100;
+
+ const table = useTable({
+ data: conversions || [],
+ columns: [
+ {
+ header: "Conversion",
+ cell: ({ row }) => row.original.customer.email,
+ },
+ {
+ id: "total",
+ header: "Total",
+ cell: ({ row }) =>
+ currencyFormatter(row.original.amount / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ }),
+ },
+ ],
+ ...(showPagination && {
+ pagination,
+ onPaginationChange: setPagination,
+ rowCount: totalConversions,
+ }),
+ columnPinning: { right: ["menu"] },
+ thClassName: (id) =>
+ cn(id === "total" && "[&>div]:justify-end", "border-l-0"),
+ tdClassName: (id) => cn(id === "total" && "text-right", "border-l-0"),
+ className: cn(
+ !showPagination && "[&_tr:last-child>td]:border-b-transparent", // Hide bottom row border
+ ),
+ scrollWrapperClassName: "min-h-0",
+ resourceName: (p) => `conversion${p ? "s" : ""}`,
+ loading: loading || loadingTotalConversions,
+ error: error ? "Failed to load conversions" : undefined,
+ } as any);
+
+ return (
+ <>
+ <div>
+ <div className="flex items-start justify-between border-b border-neutral-200 p-6">
+ <Sheet.Title className="text-xl font-semibold">
+ {capitalize(payout.status)} payout
+ </Sheet.Title>
+ <Sheet.Close asChild>
+ <Button
+ variant="outline"
+ icon={<X className="size-5" />}
+ className="h-auto w-fit p-1"
+ />
+ </Sheet.Close>
+ </div>
+ <div className="flex flex-col gap-4 p-6">
+ <div className="text-base font-medium text-neutral-900">
+ Invoice details
+ </div>
+ <div className="grid grid-cols-2 gap-3 text-sm">
+ {Object.entries(invoiceData).map(([key, value]) => (
+ <Fragment key={key}>
+ <div className="font-medium text-neutral-500">{key}</div>
+ <div className="text-neutral-800">{value}</div>
+ </Fragment>
+ ))}
+ </div>
+ </div>
+ <div className="p-6 pt-2">
+ <Table {...table} />
+ </div>
+ </div>
+ <div className="flex grow flex-col justify-end">
+ <div className="flex items-center justify-end gap-2 border-t border-neutral-200 p-5">
+ <Button
+ type="button"
+ variant="secondary"
+ onClick={() => setIsOpen(false)}
+ text={canConfirmPayout ? "Cancel" : "Close"}
+ className="w-fit"
+ />
+ {canConfirmPayout && (
+ <Button
+ type="button"
+ variant="primary"
+ onClick={() => {
+ toast.info("WIP");
+ setIsOpen(false);
+ }}
+ text="Confirm payout"
+ className="w-fit"
+ />
+ )}
+ </div>
+ </div>
+ </>
+ );
+}
+
+export function usePayoutDetailsSheet({
+ payout,
+}: {
+ payout: PayoutWithPartnerProps;
+}) {
+ const [isOpen, setIsOpen] = useState(false);
+
+ return {
+ payoutDetailsSheet: (
+ <Sheet open={isOpen} onOpenChange={setIsOpen}>
+ <PayoutDetailsSheetContent payout={payout} setIsOpen={setIsOpen} />
+ </Sheet>
+ ),
+ setIsOpen,
+ };
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-table.tsx
index 6d98f9ec66..7bcb350af6 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/payouts/payout-table.tsx
@@ -5,8 +5,11 @@ import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import { SearchBoxPersisted } from "@/ui/shared/search-box";
import {
AnimatedSizeContainer,
+ Button,
Filter,
+ Icon,
MoneyBill2,
+ Popover,
StatusBadge,
Table,
usePagination,
@@ -19,11 +22,24 @@ import {
CircleHalfDottedClock,
CircleWarning,
CircleXmark,
+ Dots,
+ GreekTemple,
+ ScanText,
+ Users,
} from "@dub/ui/src/icons";
-import { currencyFormatter, DICEBEAR_AVATAR_URL, formatDate } from "@dub/utils";
+import {
+ cn,
+ currencyFormatter,
+ DICEBEAR_AVATAR_URL,
+ formatDate,
+} from "@dub/utils";
import { fetcher } from "@dub/utils/src/functions/fetcher";
+import { Row } from "@tanstack/react-table";
+import { Command } from "cmdk";
import { useEffect, useMemo, useState } from "react";
+import { toast } from "sonner";
import useSWR from "swr";
+import { usePayoutDetailsSheet } from "./payout-details-sheet";
import { usePayoutFilters } from "./use-payout-filters";
export const StatusBadges = {
@@ -155,6 +171,10 @@ export function PayoutTable({ programId }: { programId: string }) {
);
},
},
+ {
+ header: "Conversions",
+ accessorFn: () => "-", // TODO: Use actual data
+ },
{
id: "total",
header: "Total",
@@ -164,6 +184,15 @@ export function PayoutTable({ programId }: { programId: string }) {
maximumFractionDigits: 2,
}),
},
+ // Menu
+ {
+ id: "menu",
+ enableHiding: false,
+ minSize: 43,
+ size: 43,
+ maxSize: 43,
+ cell: ({ row }) => <RowMenuButton row={row} />,
+ },
],
pagination,
onPaginationChange: setPagination,
@@ -177,6 +206,7 @@ export function PayoutTable({ programId }: { programId: string }) {
...(sortOrder && { order: sortOrder }),
},
}),
+ columnPinning: { right: ["menu"] },
thClassName: "border-l-0",
tdClassName: "border-l-0",
resourceName: (p) => `payout${p ? "s" : ""}`,
@@ -243,3 +273,83 @@ export function PayoutTable({ programId }: { programId: string }) {
</div>
);
}
+
+function RowMenuButton({ row }: { row: Row<PayoutWithPartnerProps> }) {
+ const [isOpen, setIsOpen] = useState(false);
+
+ const { payoutDetailsSheet, setIsOpen: setShowPayoutDetailsSheet } =
+ usePayoutDetailsSheet({
+ payout: row.original,
+ });
+
+ return (
+ <>
+ {payoutDetailsSheet}
+ <Popover
+ openPopover={isOpen}
+ setOpenPopover={setIsOpen}
+ content={
+ <Command tabIndex={0} loop className="focus:outline-none">
+ <Command.List className="flex w-screen flex-col gap-1 p-1.5 text-sm sm:w-auto sm:min-w-[130px]">
+ <MenuItem
+ icon={GreekTemple}
+ label="Pay invoice"
+ onSelect={() => {
+ toast.info("WIP");
+ setIsOpen(false);
+ }}
+ />
+ <MenuItem
+ icon={ScanText}
+ label="Review"
+ onSelect={() => {
+ setShowPayoutDetailsSheet(true);
+ setIsOpen(false);
+ }}
+ />
+ <MenuItem
+ icon={Users}
+ label="View partner"
+ onSelect={() => {
+ toast.info("WIP");
+ setIsOpen(false);
+ }}
+ />
+ </Command.List>
+ </Command>
+ }
+ align="end"
+ >
+ <Button
+ type="button"
+ className="h-8 whitespace-nowrap px-2"
+ variant="outline"
+ icon={<Dots className="h-4 w-4 shrink-0" />}
+ />
+ </Popover>
+ </>
+ );
+}
+
+function MenuItem({
+ icon: IconComp,
+ label,
+ onSelect,
+}: {
+ icon: Icon;
+ label: string;
+ onSelect: () => void;
+}) {
+ return (
+ <Command.Item
+ className={cn(
+ "flex cursor-pointer select-none items-center gap-2 whitespace-nowrap rounded-md p-2 text-sm text-neutral-600",
+ "data-[selected=true]:bg-gray-100",
+ )}
+ onSelect={onSelect}
+ >
+ <IconComp className="size-4 shrink-0 text-neutral-500" />
+ {label}
+ </Command.Item>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index dad5413b6e..018ef9b00e 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -105,6 +105,7 @@ export * from "./referred-via";
export * from "./refresh2";
export * from "./robot";
export * from "./satellite-dish";
+export * from "./scan-text";
export * from "./scribble";
export * from "./shield-check";
export * from "./shuffle";
diff --git a/packages/ui/src/icons/nucleo/scan-text.tsx b/packages/ui/src/icons/nucleo/scan-text.tsx
new file mode 100644
index 0000000000..dcc5b03e46
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/scan-text.tsx
@@ -0,0 +1,81 @@
+import { SVGProps } from "react";
+
+export function ScanText(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <path
+ d="M2.75,6.25v-1.5c0-1.105,.895-2,2-2h2"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ d="M11.25,2.75h2c1.105,0,2,.895,2,2v1.5"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ d="M15.25,11.75v1.5c0,1.105-.895,2-2,2h-2"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ d="M6.75,15.25h-2c-1.105,0-2-.895-2-2v-1.5"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="12.25"
+ x2="5.75"
+ y1="9"
+ y2="9"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="12.25"
+ x2="5.75"
+ y1="6.25"
+ y2="6.25"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="10.25"
+ x2="5.75"
+ y1="11.75"
+ y2="11.75"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/table/table.tsx b/packages/ui/src/table/table.tsx
index 7422e2714f..999332300a 100644
--- a/packages/ui/src/table/table.tsx
+++ b/packages/ui/src/table/table.tsx
@@ -54,8 +54,8 @@ type UseTableProps<T> = {
className?: string;
containerClassName?: string;
scrollWrapperClassName?: string;
- thClassName?: string;
- tdClassName?: string;
+ thClassName?: string | ((columnId: string) => string);
+ tdClassName?: string | ((columnId: string) => string);
} & (
| {
pagination: PaginationState;
@@ -174,6 +174,7 @@ export function Table<T>({
// Remove side borders from table to avoid interfering with outer border
"[&_tr>*:first-child]:border-l-transparent", // Left column
"[&_tr>*:last-child]:border-r-transparent", // Right column
+ "[&_tr>*:last-child]:border-r-transparent", // Bottom column
],
className,
)}
@@ -197,7 +198,9 @@ export function Table<T>({
header.column,
!table.getRowModel().rows.length,
),
- thClassName,
+ typeof thClassName === "function"
+ ? thClassName(header.column.id)
+ : thClassName,
)}
style={{
minWidth: header.column.columnDef.minSize,
@@ -263,7 +266,9 @@ export function Table<T>({
cell.column,
row.index === table.getRowModel().rows.length - 1,
),
- tdClassName,
+ typeof tdClassName === "function"
+ ? tdClassName(cell.column.id)
+ : tdClassName,
)}
style={{
minWidth: cell.column.columnDef.minSize,