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.

display the negative earnings in the commission table

Kiran Kdf924a742d3c
diff --git a/apps/web/app/(ee)/api/commissions/count/route.ts b/apps/web/app/(ee)/api/commissions/count/route.ts
index 3174681077..9f533668a4 100644
--- a/apps/web/app/(ee)/api/commissions/count/route.ts
+++ b/apps/web/app/(ee)/api/commissions/count/route.ts
@@ -31,7 +31,7 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {
by: ["status"],
where: {
earnings: {
- gt: 0,
+ not: 0,
},
programId,
partnerId,
diff --git a/apps/web/app/(ee)/api/commissions/route.ts b/apps/web/app/(ee)/api/commissions/route.ts
index 61accd8df7..597984589a 100644
--- a/apps/web/app/(ee)/api/commissions/route.ts
+++ b/apps/web/app/(ee)/api/commissions/route.ts
@@ -43,7 +43,7 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {
}
: {
earnings: {
- gt: 0,
+ not: 0,
},
programId,
partnerId,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-table.tsx
index 79ff6f35d7..7b1b98a46c 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-table.tsx
@@ -3,6 +3,7 @@
import useCommissionsCount from "@/lib/swr/use-commissions-count";
import useWorkspace from "@/lib/swr/use-workspace";
import { CommissionResponse } from "@/lib/types";
+import { CLAWBACK_REASONS } from "@/lib/zod/schemas/commissions";
import { CustomerRowItem } from "@/ui/customers/customer-row-item";
import { CommissionRowMenu } from "@/ui/partners/commission-row-menu";
import { CommissionStatusBadges } from "@/ui/partners/commission-status-badges";
@@ -16,6 +17,7 @@ import {
Filter,
StatusBadge,
Table,
+ Tooltip,
usePagination,
useRouterStuff,
useTable,
@@ -71,6 +73,7 @@ const CommissionTableInner = memo(
keepPreviousData: true,
},
);
+
const { commissionsCount } = useCommissionsCount({
exclude: ["status", "page"],
});
@@ -147,11 +150,30 @@ const CommissionTableInner = memo(
{
id: "commission",
header: "Commission",
- accessorFn: (d) =>
- currencyFormatter(d.earnings / 100, {
+ cell: ({ row }) => {
+ const commission = row.original;
+
+ const earnings = currencyFormatter(commission.earnings / 100, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
- }),
+ });
+
+ if (commission.description) {
+ const reasonDescription = CLAWBACK_REASONS.find(
+ (r) => r.value === commission.description,
+ )?.description;
+
+ return (
+ <Tooltip content={reasonDescription}>
+ <span className="cursor-help truncate underline decoration-dotted underline-offset-2">
+ {earnings}
+ </span>
+ </Tooltip>
+ );
+ }
+
+ return earnings;
+ },
},
{
header: "Status",
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-clawback-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-clawback-sheet.tsx
index 54eb6bff7f..e9abe80805 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-clawback-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-clawback-sheet.tsx
@@ -67,6 +67,7 @@ function CreateClawbackSheetContent(
await executeAsync({
...data,
+ amount: data.amount * 100,
workspaceId,
});
};
diff --git a/apps/web/lib/actions/partners/create-clawback.ts b/apps/web/lib/actions/partners/create-clawback.ts
index f04ac0512d..4bbb99542d 100644
--- a/apps/web/lib/actions/partners/create-clawback.ts
+++ b/apps/web/lib/actions/partners/create-clawback.ts
@@ -27,7 +27,8 @@ export const createClawbackAction = authActionClient
partnerId,
description,
type: "custom",
- amount: -amount,
+ amount: 0,
+ earnings: -amount,
quantity: 1,
},
});
diff --git a/apps/web/lib/zod/schemas/commissions.ts b/apps/web/lib/zod/schemas/commissions.ts
index 7041a12d8b..4126b75bcb 100644
--- a/apps/web/lib/zod/schemas/commissions.ts
+++ b/apps/web/lib/zod/schemas/commissions.ts
@@ -16,6 +16,7 @@ export const CommissionSchema = z.object({
currency: z.string(),
status: z.nativeEnum(CommissionStatus),
invoiceId: z.string().nullish(),
+ description: z.string().nullish(),
createdAt: z.date(),
updatedAt: z.date(),
});
@@ -182,5 +183,7 @@ export const createClawbackSchema = z.object({
workspaceId: z.string(),
partnerId: z.string(),
amount: z.number().min(0, "Amount must be positive."),
- description: z.enum(CLAWBACK_REASONS.map((r) => r.value) as [string, ...string[]]),
+ description: z.enum(
+ CLAWBACK_REASONS.map((r) => r.value) as [string, ...string[]],
+ ),
});