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.

account for click-based commissions

Steven Teya55baff1b069
diff --git a/apps/web/app/api/programs/[programId]/commissions/route.ts b/apps/web/app/api/programs/[programId]/commissions/route.ts
index 0524926a23..f1ae58a10b 100644
--- a/apps/web/app/api/programs/[programId]/commissions/route.ts
+++ b/apps/web/app/api/programs/[programId]/commissions/route.ts
@@ -32,7 +32,7 @@ export const GET = withWorkspace(
programId,
});
- const sales = await prisma.commission.findMany({
+ const commissions = await prisma.commission.findMany({
where: {
earnings: {
gt: 0,
@@ -56,6 +56,8 @@ export const GET = withWorkspace(
orderBy: { [sortBy]: sortOrder },
});
- return NextResponse.json(z.array(CommissionResponseSchema).parse(sales));
+ return NextResponse.json(
+ z.array(CommissionResponseSchema).parse(commissions),
+ );
},
);
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/commission-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/commission-table.tsx
index 7e65fde9d9..2ea2715851 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/commission-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/commission-table.tsx
@@ -89,6 +89,10 @@ const CommissionTableInner = memo(
{
header: "Customer",
cell: ({ row }) => {
+ if (!row.original.customer) {
+ return "-";
+ }
+
return (
<div className="flex items-center gap-2">
<img
@@ -108,9 +112,12 @@ const CommissionTableInner = memo(
);
},
meta: {
- filterParams: ({ row }) => ({
- customerId: row.original.customer.id,
- }),
+ filterParams: ({ row }) =>
+ row.original.customer
+ ? {
+ customerId: row.original.customer.id,
+ }
+ : {},
},
},
{
diff --git a/apps/web/lib/zod/schemas/commissions.ts b/apps/web/lib/zod/schemas/commissions.ts
index 513188fcbd..e30af76dbf 100644
--- a/apps/web/lib/zod/schemas/commissions.ts
+++ b/apps/web/lib/zod/schemas/commissions.ts
@@ -20,8 +20,8 @@ export const CommissionSchema = z.object({
export const CommissionResponseSchema = CommissionSchema.merge(
z.object({
- customer: CustomerSchema,
partner: PartnerSchema,
+ customer: CustomerSchema.nullable(), // customer can be null for click-based commissions
}),
);