The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Reject $0 sales, restore Zod error prefixes, and fix clawback success UI.
Kiran K7aeb104e9906
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.tsxindex a351a11a92..0fbfb9088d 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@@ -40,7 +40,7 @@ function CreateClawbackSheetContent(reset,watch,getValues,- formState: { errors, isSubmitting, isSubmitSuccessful },+ formState: { errors, isSubmitting },} = useForm<FormData>({defaultValues: {partnerId: params.partnerId,@@ -66,8 +66,8 @@ function CreateClawbackSheetContent(amount: data.amount ? -Math.round(data.amount * 100) : 0,description: data.reason,},- onSuccess: async ({ message }) => {- toast.success(message);+ onSuccess: async () => {+ toast.success("A clawback has been created for the partner!");setIsOpen(false);await mutatePrefix("/api/commissions");const currentValues = getValues();@@ -76,8 +76,6 @@ function CreateClawbackSheetContent(});};- const disableSubmitButton = !partnerId || !amount || !reason;-return (<form onSubmit={handleSubmit(onSubmit)} className="flex h-full flex-col"><div className="sticky top-0 z-10 border-b border-neutral-200 bg-white">@@ -216,15 +214,15 @@ function CreateClawbackSheetContent(onClick={() => setIsOpen(false)}text="Cancel"className="w-fit"- disabled={isCreating || isSubmitting || isSubmitSuccessful}+ disabled={isCreating || isSubmitting}/><Buttontype="submit"variant="primary"text="Create clawback"className="w-fit"- loading={isCreating || isSubmitting || isSubmitSuccessful}- disabled={disableSubmitButton}+ loading={isCreating || isSubmitting}+ disabled={!partnerId || !amount || !reason}/></div></div>diff --git a/apps/web/lib/api/errors.ts b/apps/web/lib/api/errors.tsindex c58d3eabf8..0f129910fd 100644--- a/apps/web/lib/api/errors.ts+++ b/apps/web/lib/api/errors.ts@@ -63,20 +63,6 @@ export class DubApiError extends Error {const docErrorUrl = "https://dub.co/docs/api-reference/errors";export function fromZodError(error: z.ZodError): ErrorResponse {- const [issue] = error.issues;-- // Custom business rules already include human-readable messages.- // Example: "custom: description: Description is required..." → "Description is required..."- if (error.issues.length === 1 && issue.code === "custom") {- return {- error: {- code: "unprocessable_entity",- message: issue.message,- doc_url: `${docErrorUrl}#unprocessable-entity`,- },- };- }-return {error: {code: "unprocessable_entity",diff --git a/apps/web/lib/zod/schemas/commissions.ts b/apps/web/lib/zod/schemas/commissions.tsindex 7cf8af8034..e9baeb30f6 100644--- a/apps/web/lib/zod/schemas/commissions.ts+++ b/apps/web/lib/zod/schemas/commissions.ts@@ -547,7 +547,14 @@ 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))+ .pipe(+ z+ .number()+ .min(0)+ .refine((n) => n !== 0, {+ message: "Sale amount cannot be 0.",+ }),+ ).nullish().describe("Required when `importStripeInvoices` is `false`. The sale amount in cents for the manual sale event. Ignored when importing from Stripe.",diff --git a/apps/web/playwright/api/clawbacks/clawbacks.spec.ts b/apps/web/playwright/api/clawbacks/clawbacks.spec.tsindex a28158a260..8a0a6a9fb7 100644--- a/apps/web/playwright/api/clawbacks/clawbacks.spec.ts+++ b/apps/web/playwright/api/clawbacks/clawbacks.spec.ts@@ -162,7 +162,7 @@ const clawbackErrorCases = [},expected: apiError({code: "unprocessable_entity",- message: "Amount cannot be 0.",+ message: "custom: amount: Amount cannot be 0.",}),},{@@ -171,7 +171,7 @@ const clawbackErrorCases = [expected: apiError({code: "unprocessable_entity",message:- "`description` is required when creating a clawback (negative amount).",+ "custom: description: `description` is required when creating a clawback (negative amount).",}),},];diff --git a/apps/web/tests/commissions/create-commission.test.ts b/apps/web/tests/commissions/create-commission.test.tsindex e4a88fc97a..941c92120e 100644--- a/apps/web/tests/commissions/create-commission.test.ts+++ b/apps/web/tests/commissions/create-commission.test.ts@@ -31,7 +31,7 @@ const validationCases = [name: "custom commission with amount 0",body: { type: "custom", partnerId: E2E_PARTNER.id, amount: 0 },expectedStatus: 422,- expectedMessage: "Amount cannot be 0.",+ expectedMessage: "custom: amount: Amount cannot be 0.",},{name: "sale commission missing saleAmount",@@ -43,7 +43,19 @@ const validationCases = [},expectedStatus: 422,expectedMessage:- "saleAmount is required when importStripeInvoices is false.",+ "custom: saleAmount: `saleAmount` is required when `importStripeInvoices` is false.",+ },+ {+ name: "sale commission with saleAmount 0",+ body: {+ type: "sale",+ partnerId: E2E_PARTNER.id,+ customerId: E2E_CUSTOMER_ID,+ importStripeInvoices: false,+ saleAmount: 0,+ },+ expectedStatus: 422,+ expectedMessage: "custom: saleAmount: Sale amount cannot be 0.",},];