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.

Exclude payouts from confirmation

Tim Wilson11e564dff095
diff --git a/apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts b/apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts
index ac2425912c..4fdcba3c46 100644
--- a/apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts
@@ -32,6 +32,7 @@ export async function confirmPayouts({
userId,
paymentMethodId,
cutoffPeriod,
+ excludedPayoutIds,
}: {
workspace: Pick<
Project,
@@ -47,6 +48,7 @@ export async function confirmPayouts({
userId: string;
paymentMethodId: string;
cutoffPeriod?: CUTOFF_PERIOD_TYPES;
+ excludedPayoutIds?: string[];
}) {
const cutoffPeriodValue = CUTOFF_PERIOD.find(
(c) => c.id === cutoffPeriod,
@@ -78,6 +80,7 @@ export async function confirmPayouts({
},
],
}),
+ ...(excludedPayoutIds && { id: { notIn: excludedPayoutIds } }),
},
select: {
id: true,
diff --git a/apps/web/app/(ee)/api/cron/payouts/confirm/route.ts b/apps/web/app/(ee)/api/cron/payouts/confirm/route.ts
index d3d1709b7f..af18424bba 100644
--- a/apps/web/app/(ee)/api/cron/payouts/confirm/route.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/confirm/route.ts
@@ -15,6 +15,7 @@ const confirmPayoutsSchema = z.object({
userId: z.string(),
paymentMethodId: z.string(),
cutoffPeriod: CUTOFF_PERIOD_ENUM,
+ excludedPayoutIds: z.array(z.string()).optional(),
});
// POST /api/cron/payouts/confirm
@@ -26,8 +27,13 @@ export async function POST(req: Request) {
await verifyQstashSignature({ req, rawBody });
- const { workspaceId, userId, paymentMethodId, cutoffPeriod } =
- confirmPayoutsSchema.parse(JSON.parse(rawBody));
+ const {
+ workspaceId,
+ userId,
+ paymentMethodId,
+ cutoffPeriod,
+ excludedPayoutIds,
+ } = confirmPayoutsSchema.parse(JSON.parse(rawBody));
const workspace = await prisma.project.findUniqueOrThrow({
where: {
@@ -45,6 +51,7 @@ export async function POST(req: Request) {
await splitPayouts({
program,
cutoffPeriod,
+ excludedPayoutIds,
});
}
@@ -54,6 +61,7 @@ export async function POST(req: Request) {
userId,
paymentMethodId,
cutoffPeriod,
+ excludedPayoutIds,
});
return new Response(`Payouts confirmed for program ${program.name}.`);
diff --git a/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts b/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts
index 540ffa8e3b..5910191c82 100644
--- a/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts
@@ -10,9 +10,11 @@ import { endOfMonth } from "date-fns";
export async function splitPayouts({
program,
cutoffPeriod,
+ excludedPayoutIds,
}: {
program: Pick<Program, "id" | "minPayoutAmount">;
cutoffPeriod: CUTOFF_PERIOD_TYPES;
+ excludedPayoutIds?: string[];
}) {
const payouts = await prisma.payout.findMany({
where: {
@@ -30,6 +32,7 @@ export async function splitPayouts({
periodStart: {
not: null, // exclude the manual payouts
},
+ ...(excludedPayoutIds && { id: { notIn: excludedPayoutIds } }),
},
include: {
commissions: true,
diff --git a/apps/web/lib/actions/partners/confirm-payouts.ts b/apps/web/lib/actions/partners/confirm-payouts.ts
index c9c662ea4d..7d02832378 100644
--- a/apps/web/lib/actions/partners/confirm-payouts.ts
+++ b/apps/web/lib/actions/partners/confirm-payouts.ts
@@ -13,6 +13,7 @@ const confirmPayoutsSchema = z.object({
workspaceId: z.string(),
paymentMethodId: z.string(),
cutoffPeriod: CUTOFF_PERIOD_ENUM,
+ excludedPayoutIds: z.array(z.string()).optional(),
});
// Confirm payouts
@@ -20,7 +21,7 @@ export const confirmPayoutsAction = authActionClient
.schema(confirmPayoutsSchema)
.action(async ({ parsedInput, ctx }) => {
const { workspace, user } = ctx;
- const { paymentMethodId, cutoffPeriod } = parsedInput;
+ const { paymentMethodId, cutoffPeriod, excludedPayoutIds } = parsedInput;
if (workspace.role !== "owner") {
throw new Error("Only workspace owners can confirm payouts.");
@@ -61,6 +62,7 @@ export const confirmPayoutsAction = authActionClient
userId: user.id,
paymentMethodId,
cutoffPeriod,
+ excludedPayoutIds,
},
});
diff --git a/apps/web/ui/partners/payout-invoice-sheet.tsx b/apps/web/ui/partners/payout-invoice-sheet.tsx
index 6a9bad6c4e..b059a3d1b1 100644
--- a/apps/web/ui/partners/payout-invoice-sheet.tsx
+++ b/apps/web/ui/partners/payout-invoice-sheet.tsx
@@ -114,6 +114,16 @@ function PayoutInvoiceSheetContent() {
fetcher,
);
+ const [excludedPayoutIds, setExcludedPayoutIds] = useState<string[]>([]);
+
+ const includedPayouts = useMemo(
+ () =>
+ eligiblePayouts?.filter(
+ (payout) => !excludedPayoutIds.includes(payout.id),
+ ),
+ [eligiblePayouts, excludedPayoutIds],
+ );
+
const { executeAsync, isPending } = useAction(confirmPayoutsAction, {
onSuccess: async () => {
await mutatePrefix(`/api/programs/${defaultProgramId}/payouts`);
@@ -177,10 +187,10 @@ function PayoutInvoiceSheetContent() {
const amount = useMemo(
() =>
- eligiblePayouts?.reduce((acc, payout) => {
+ includedPayouts?.reduce((acc, payout) => {
return acc + payout.amount;
}, 0),
- [eligiblePayouts],
+ [includedPayouts],
);
const invoiceData = useMemo(() => {
@@ -308,40 +318,85 @@ function PayoutInvoiceSheetContent() {
];
}, [amount, paymentMethods, selectedPaymentMethod, cutoffPeriod]);
+ const partnerColumn = useMemo(
+ () => ({
+ header: "Partner",
+ cell: ({ row }) => (
+ <div className="flex items-center gap-2">
+ <img
+ src={
+ row.original.partner.image ||
+ `${OG_AVATAR_URL}${row.original.partner.name}`
+ }
+ alt={row.original.partner.name}
+ className="size-6 rounded-full"
+ />
+ <span className="text-sm text-neutral-700">
+ {row.original.partner.name}
+ </span>
+ </div>
+ ),
+ }),
+ [],
+ );
+
const table = useTable({
data: eligiblePayouts || [],
columns: [
- {
- header: "Partner",
- cell: ({ row }) => (
- <div className="flex items-center gap-2">
- <img
- src={
- row.original.partner.image ||
- `${OG_AVATAR_URL}${row.original.partner.name}`
- }
- alt={row.original.partner.name}
- className="size-6 rounded-full"
- />
- <span className="text-sm text-neutral-700">
- {row.original.partner.name}
- </span>
- </div>
- ),
- },
+ partnerColumn,
{
id: "total",
header: "Total",
- cell: ({ row }) =>
- currencyFormatter(row.original.amount / 100, {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- }),
+ cell: ({ row }) => (
+ <>
+ <div className="relative">
+ <span
+ className={cn(
+ "group-hover/row:opacity-0",
+ excludedPayoutIds.includes(row.original.id) && "line-through",
+ )}
+ >
+ {currencyFormatter(row.original.amount / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ })}
+ </span>
+ <div className="pointer-events-none absolute right-0 top-1/2 -translate-y-1/2 opacity-0 group-hover/row:pointer-events-auto group-hover/row:opacity-100">
+ <Button
+ variant="secondary"
+ text={
+ excludedPayoutIds.includes(row.original.id)
+ ? "Include"
+ : "Exclude"
+ }
+ className="h-6 w-fit px-2"
+ onClick={() =>
+ // Toggle excluded
+ setExcludedPayoutIds((ids) =>
+ ids.includes(row.original.id)
+ ? ids.filter((id) => id !== row.original.id)
+ : [...excludedPayoutIds, row.original.id],
+ )
+ }
+ />
+ </div>
+ </div>
+ </>
+ ),
},
],
thClassName: (id) =>
cn(id === "total" && "[&>div]:justify-end", "border-l-0"),
- tdClassName: (id) => cn(id === "total" && "text-right", "border-l-0"),
+ tdClassName: (id, row) =>
+ cn(
+ "transition-opacity",
+ excludedPayoutIds.includes(row.original.id) && [
+ "[&>div]:opacity-50",
+ id === "total" && "group-hover/row:[&>div]:opacity-100",
+ ], // Excluded payout
+ id === "total" && "text-right",
+ "border-l-0",
+ ),
className: "[&_tr:last-child>td]:border-b-transparent",
scrollWrapperClassName: "min-h-[40px]",
resourceName: (p) => `eligible payout${p ? "s" : ""}`,
@@ -349,13 +404,7 @@ function PayoutInvoiceSheetContent() {
error: eligiblePayoutsError
? "Failed to load payouts for this invoice."
: undefined,
- } as any);
-
- useEffect(() => {
- if (eligiblePayouts) {
- table.table.toggleAllRowsSelected();
- }
- }, [eligiblePayouts]);
+ });
const { error: permissionsError } = clientAccessCheck({
role,
diff --git a/packages/ui/src/table/table.tsx b/packages/ui/src/table/table.tsx
index e8d7a2fa20..a9550f98e2 100644
--- a/packages/ui/src/table/table.tsx
+++ b/packages/ui/src/table/table.tsx
@@ -245,7 +245,7 @@ const ResizableTableRow = memo(
row.index === table.getRowModel().rows.length - 1,
),
typeof tdClassName === "function"
- ? tdClassName(cell.column.id)
+ ? tdClassName(cell.column.id, row)
: tdClassName,
)}
style={{
@@ -487,7 +487,7 @@ export function Table<T>({
row.index === table.getRowModel().rows.length - 1,
),
typeof tdClassName === "function"
- ? tdClassName(cell.column.id)
+ ? tdClassName(cell.column.id, row)
: tdClassName,
)}
style={{
diff --git a/packages/ui/src/table/types.ts b/packages/ui/src/table/types.ts
index ddc8df591d..6d7a449bbf 100644
--- a/packages/ui/src/table/types.ts
+++ b/packages/ui/src/table/types.ts
@@ -64,7 +64,7 @@ type BaseTableProps<T> = {
containerClassName?: string;
scrollWrapperClassName?: string;
thClassName?: string | ((columnId: string) => string);
- tdClassName?: string | ((columnId: string) => string);
+ tdClassName?: string | ((columnId: string, row: Row<T>) => string);
};
export type UseTableProps<T> = BaseTableProps<T> &