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 marking sales as duplicate/fraud

Tim Wilson58a8598bdeb0
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/sales/sale-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/sales/sale-table.tsx
index bb80bd90b1..5de5c0a299 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/sales/sale-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/sales/sale-table.tsx
@@ -6,20 +6,23 @@ import {
PartnerSchema,
SaleSchema,
} from "@/lib/zod/schemas/partners";
+import { SaleRowMenu } from "@/ui/partners/sale-row-menu";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import SimpleDateRangePicker from "@/ui/shared/simple-date-range-picker";
import {
AnimatedSizeContainer,
CircleCheck,
CircleHalfDottedClock,
+ Duplicate,
Filter,
+ ShieldAlert,
StatusBadge,
Table,
usePagination,
useRouterStuff,
useTable,
} from "@dub/ui";
-import { MoneyBill2 } from "@dub/ui/src/icons";
+import { CircleXmark, MoneyBill2 } from "@dub/ui/src/icons";
import {
currencyFormatter,
DICEBEAR_AVATAR_URL,
@@ -57,6 +60,24 @@ export const SaleStatusBadges = {
className: "text-green-600 bg-green-100",
icon: CircleCheck,
},
+ fraud: {
+ label: "Fraud",
+ variant: "error",
+ className: "text-red-600 bg-red-100",
+ icon: ShieldAlert,
+ },
+ duplicate: {
+ label: "Duplicate",
+ variant: "error",
+ className: "text-red-600 bg-red-100",
+ icon: Duplicate,
+ },
+ refunded: {
+ label: "Refunded",
+ variant: "error",
+ className: "text-red-600 bg-red-100",
+ icon: CircleXmark,
+ },
};
export function SaleTableBusiness({ limit }: { limit?: number }) {
@@ -144,7 +165,17 @@ export function SaleTableBusiness({ limit }: { limit?: number }) {
);
},
},
+ // Menu
+ {
+ id: "menu",
+ enableHiding: false,
+ minSize: 43,
+ size: 43,
+ maxSize: 43,
+ cell: ({ row }) => <SaleRowMenu row={row} />,
+ },
],
+ columnPinning: { right: ["menu"] },
...(!limit
? {
pagination,
diff --git a/apps/web/lib/actions/update-sale-status.ts b/apps/web/lib/actions/update-sale-status.ts
index 7da0285ef5..95cc8516b8 100644
--- a/apps/web/lib/actions/update-sale-status.ts
+++ b/apps/web/lib/actions/update-sale-status.ts
@@ -32,6 +32,8 @@ export const updateSaleStatusAction = authActionClient
// TODO:
// Send email to the partner informing them about the sale status change
+ // TODO: [payouts] Update associated payout based on new status (fraud, duplicate, etc.)
+
return {
ok: true,
};
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index caee98026b..fb1ca4fbf5 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -23,6 +23,7 @@ import {
PayoutWithSalesSchema,
ProgramEnrollmentSchema,
ProgramSchema,
+ SaleSchema,
} from "./zod/schemas/partners";
import { trackSaleResponseSchema } from "./zod/schemas/sales";
import { tokenSchema } from "./zod/schemas/token";
@@ -297,6 +298,7 @@ export type UsageResponse = z.infer<typeof usageResponse>;
export type PartnersCount = Record<ProgramEnrollmentStatus | "all", number>;
+export type SaleProps = z.infer<typeof SaleSchema>;
export type SalesCount = Record<SaleStatus | "all", number>;
export type PartnerProps = z.infer<typeof PartnerSchema>;
diff --git a/apps/web/ui/partners/payout-details-sheet.tsx b/apps/web/ui/partners/payout-details-sheet.tsx
index cbd0147570..31c6b36ce4 100644
--- a/apps/web/ui/partners/payout-details-sheet.tsx
+++ b/apps/web/ui/partners/payout-details-sheet.tsx
@@ -25,6 +25,7 @@ import { Dispatch, Fragment, SetStateAction, useMemo, useState } from "react";
import { toast } from "sonner";
import useSWR, { mutate } from "swr";
import { PayoutStatusBadges } from "./payout-status-badges";
+import { SaleRowMenu } from "./sale-row-menu";
type PayoutDetailsSheetProps = {
payout: PayoutWithPartnerProps;
@@ -92,7 +93,10 @@ function PayoutDetailsSheetContent({
});
const table = useTable({
- data: payoutWithSales?.sales || [],
+ data:
+ payoutWithSales?.sales?.filter(
+ ({ status }) => !["duplicate", "fraud"].includes(status),
+ ) || [],
columns: [
{
header: "Sale",
@@ -116,6 +120,15 @@ function PayoutDetailsSheetContent({
maximumFractionDigits: 2,
}),
},
+ // Menu
+ {
+ id: "menu",
+ enableHiding: false,
+ minSize: 43,
+ size: 43,
+ maxSize: 43,
+ cell: ({ row }) => <SaleRowMenu row={row} />,
+ },
],
...(showPagination && {
pagination,
diff --git a/apps/web/ui/partners/sale-row-menu.tsx b/apps/web/ui/partners/sale-row-menu.tsx
new file mode 100644
index 0000000000..bc192b2674
--- /dev/null
+++ b/apps/web/ui/partners/sale-row-menu.tsx
@@ -0,0 +1,127 @@
+import { updateSaleStatusAction } from "@/lib/actions/update-sale-status";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { SaleProps } from "@/lib/types";
+import { Button, Icon, Popover } from "@dub/ui";
+import {
+ CircleHalfDottedClock,
+ Dots,
+ Duplicate,
+ ShieldAlert,
+} from "@dub/ui/src/icons";
+import { cn } from "@dub/utils";
+import { Row } from "@tanstack/react-table";
+import { Command } from "cmdk";
+import { useAction } from "next-safe-action/hooks";
+import { useParams } from "next/navigation";
+import { useState } from "react";
+import { toast } from "sonner";
+import { mutate } from "swr";
+
+export function SaleRowMenu({ row }: { row: Row<SaleProps> }) {
+ const { id: workspaceId } = useWorkspace();
+ const { programId } = useParams() as { programId: string };
+ const [isOpen, setIsOpen] = useState(false);
+
+ const { executeAsync } = useAction(updateSaleStatusAction, {
+ onSuccess: async () => {
+ mutate(
+ (key) =>
+ typeof key === "string" &&
+ (key.startsWith(`/api/programs/${programId}/sales`) ||
+ key.startsWith(`/api/programs/${programId}/payouts`)),
+ );
+ },
+ });
+
+ const updateStatus = (status: "pending" | "duplicate" | "fraud") => {
+ toast.promise(
+ executeAsync({
+ workspaceId: workspaceId!,
+ saleId: row.original.id,
+ status,
+ }),
+ {
+ loading: "Updating sale status...",
+ success: "Sale status updated",
+ error: "Failed to update sale status",
+ },
+ );
+ };
+
+ return (
+ <Popover
+ openPopover={isOpen}
+ setOpenPopover={setIsOpen}
+ content={
+ <Command
+ tabIndex={0}
+ loop
+ className="pointer-events-auto 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]">
+ {["duplicate", "fraud"].includes(row.original.status) ? (
+ <MenuItem
+ icon={CircleHalfDottedClock}
+ label="Mark as pending"
+ onSelect={() => {
+ updateStatus("pending");
+ setIsOpen(false);
+ }}
+ />
+ ) : (
+ <>
+ <MenuItem
+ icon={Duplicate}
+ label="Mark as duplicate"
+ onSelect={() => {
+ updateStatus("duplicate");
+ setIsOpen(false);
+ }}
+ />
+ <MenuItem
+ icon={ShieldAlert}
+ label="Mark as fraud"
+ onSelect={() => {
+ updateStatus("fraud");
+ 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/duplicate.tsx b/packages/ui/src/icons/nucleo/duplicate.tsx
new file mode 100644
index 0000000000..901711ce48
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/duplicate.tsx
@@ -0,0 +1,37 @@
+import { SVGProps } from "react";
+
+export function Duplicate(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">
+ <rect
+ height="11"
+ width="11"
+ fill="none"
+ rx="2"
+ ry="2"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x="5.25"
+ y="5.25"
+ />
+ <path
+ d="M2.801,11.998L1.772,5.074c-.162-1.093,.592-2.11,1.684-2.272l6.924-1.029c.933-.139,1.81,.39,2.148,1.228"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index f9e6492525..c8ecab759d 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -49,6 +49,7 @@ export * from "./desktop";
export * from "./diamond-turn-right";
export * from "./dots";
export * from "./download";
+export * from "./duplicate";
export * from "./earth-position";
export * from "./eye";
export * from "./eye-slash";
@@ -110,6 +111,7 @@ export * from "./robot";
export * from "./satellite-dish";
export * from "./scan-text";
export * from "./scribble";
+export * from "./shield-alert";
export * from "./shield-check";
export * from "./shuffle";
export * from "./sliders";
diff --git a/packages/ui/src/icons/nucleo/shield-alert.tsx b/packages/ui/src/icons/nucleo/shield-alert.tsx
new file mode 100644
index 0000000000..83399f340a
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/shield-alert.tsx
@@ -0,0 +1,40 @@
+import { SVGProps } from "react";
+
+export function ShieldAlert(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="M9.305,1.848l5.25,1.68c.414,.133,.695,.518,.695,.952v6.52c0,3.03-4.684,4.748-5.942,5.155-.203,.066-.413,.066-.616,0-1.258-.407-5.942-2.125-5.942-5.155V4.48c0-.435,.281-.82,.695-.952l5.25-1.68c.198-.063,.411-.063,.61,0Z"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ d="M9,13c-.551,0-1-.449-1-1s.449-1,1-1,1,.449,1,1-.449,1-1,1Z"
+ fill="currentColor"
+ stroke="none"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="9"
+ x2="9"
+ y1="5.75"
+ y2="9.25"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/sheet.tsx b/packages/ui/src/sheet.tsx
index 49d0830548..ba35e7631f 100644
--- a/packages/ui/src/sheet.tsx
+++ b/packages/ui/src/sheet.tsx
@@ -19,6 +19,16 @@ function SheetRoot({
<Drawer.Overlay className="fixed inset-0 bg-black/20" />
<Drawer.Content
{...contentProps}
+ onPointerDownOutside={(e) => {
+ // Don't dismiss when clicking inside a toast
+ if (
+ e.target instanceof Element &&
+ e.target.closest("[data-sonner-toast]")
+ )
+ e.preventDefault();
+
+ contentProps?.onPointerDownOutside?.(e);
+ }}
className={cn(
"fixed bottom-2 right-2 top-2 z-10 flex w-[calc(100%-16px)] outline-none md:w-[540px]",
contentProps?.className,