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.

Return a clawback-specific queued message from POST /commissions.

Kiran Kdc3d4690112d
diff --git a/apps/web/app/(ee)/api/commissions/route.ts b/apps/web/app/(ee)/api/commissions/route.ts
index 3e130c3a79..d23d65fe92 100644
--- a/apps/web/app/(ee)/api/commissions/route.ts
+++ b/apps/web/app/(ee)/api/commissions/route.ts
@@ -90,15 +90,18 @@ export const POST = withWorkspace(
console.timeEnd("createManualCommissions");
- return NextResponse.json(
- createCommissionResponseSchema.parse({
- success: true,
- message: "Your commissions are being created and will appear shortly.",
- }),
- {
- status: 202,
- },
- );
+ const isClawback = body.type === "custom" && body.amount < 0;
+
+ const response = createCommissionResponseSchema.parse({
+ success: true,
+ message: isClawback
+ ? "A clawback has been queued for the partner!"
+ : "Your commissions are being created and will appear shortly.",
+ });
+
+ return NextResponse.json(response, {
+ status: 202,
+ });
},
{
requiredPlan: ["business", "advanced", "enterprise"],
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 0fbfb9088d..8935540645 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
@@ -66,8 +66,8 @@ function CreateClawbackSheetContent(
amount: data.amount ? -Math.round(data.amount * 100) : 0,
description: data.reason,
},
- onSuccess: async () => {
- toast.success("A clawback has been created for the partner!");
+ onSuccess: async ({ message }) => {
+ toast.success(message);
setIsOpen(false);
await mutatePrefix("/api/commissions");
const currentValues = getValues();
diff --git a/apps/web/lib/zod/schemas/commissions.ts b/apps/web/lib/zod/schemas/commissions.ts
index e9baeb30f6..8b515f4918 100644
--- a/apps/web/lib/zod/schemas/commissions.ts
+++ b/apps/web/lib/zod/schemas/commissions.ts
@@ -547,14 +547,7 @@ export const createManualCommissionBodySchema = z
"When `true`, import all unimported paid Stripe invoices for the customer and create a commission for each. When `false`, create a single manual sale event using `saleAmount`.",
),
saleAmount: centsSchema
- .pipe(
- z
- .number()
- .min(0)
- .refine((n) => n !== 0, {
- message: "Sale amount cannot be 0.",
- }),
- )
+ .pipe(z.number().min(0))
.nullish()
.describe(
"Required when `importStripeInvoices` is `false`. The sale amount in cents for the manual sale event. Ignored when importing from Stripe.",
@@ -579,8 +572,8 @@ export const createManualCommissionBodySchema = z
}),
])
.superRefine((data, ctx) => {
- if (data.type === "custom" && data.amount < 0) {
- if (!data.description?.trim()) {
+ if (data.type === "custom") {
+ if (data.amount < 0 && !data.description?.trim()) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message:
@@ -591,15 +584,28 @@ export const createManualCommissionBodySchema = z
return;
}
- if (data.type !== "sale") return;
+ if (data.type === "sale") {
+ if (data.importStripeInvoices) {
+ return;
+ }
- if (!data.importStripeInvoices && data.saleAmount == null) {
- ctx.addIssue({
- code: z.ZodIssueCode.custom,
- message:
- "`saleAmount` is required when `importStripeInvoices` is false.",
- path: ["saleAmount"],
- });
+ if (data.saleAmount == null) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message:
+ "`saleAmount` is required when `importStripeInvoices` is false.",
+ path: ["saleAmount"],
+ });
+ return;
+ }
+
+ if (data.saleAmount === 0) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "Sale amount cannot be 0.",
+ path: ["saleAmount"],
+ });
+ }
}
});
diff --git a/apps/web/playwright/api/clawbacks/clawbacks.spec.ts b/apps/web/playwright/api/clawbacks/clawbacks.spec.ts
index 8a0a6a9fb7..6928224527 100644
--- a/apps/web/playwright/api/clawbacks/clawbacks.spec.ts
+++ b/apps/web/playwright/api/clawbacks/clawbacks.spec.ts
@@ -7,7 +7,7 @@ import { createPartner, deletePartner } from "../partners/helpers";
const expectedQueuedResponse = {
success: true,
- message: "Your commissions are being created and will appear shortly.",
+ message: "A clawback has been queued for the partner!",
};
async function expectClawbackCreated({