The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
allow min payout for whitelisted workspaces
Pedro Ladeira83975d59f235
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-settings-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-settings-sheet.tsxindex bf55af01fb..e9a99b99d0 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-settings-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-settings-sheet.tsx@@ -2,7 +2,7 @@import { parseActionError } from "@/lib/actions/parse-action-errors";import { updateProgramAction } from "@/lib/actions/partners/update-program";-import { ALLOWED_MIN_PAYOUT_AMOUNTS } from "@/lib/constants/payouts";+import { getAllowedMinPayoutAmounts } from "@/lib/constants/payouts";import { mutatePrefix } from "@/lib/swr/mutate";import useProgram from "@/lib/swr/use-program";import useWorkspace from "@/lib/swr/use-workspace";@@ -71,6 +71,9 @@ function ProgramPayoutSettingsSheetContent({};const minPayoutAmount = watch("minPayoutAmount");+ const allowedMinPayoutAmounts = workspaceId+ ? getAllowedMinPayoutAmounts(workspaceId)+ : [];return (<form onSubmit={handleSubmit(onSubmit)} className="flex h-full flex-col">@@ -146,18 +149,11 @@ function ProgramPayoutSettingsSheetContent({<Slidervalue={minPayoutAmount}- min={ALLOWED_MIN_PAYOUT_AMOUNTS[0]}- max={- ALLOWED_MIN_PAYOUT_AMOUNTS[- ALLOWED_MIN_PAYOUT_AMOUNTS.length - 1- ]- }+ min={allowedMinPayoutAmounts[0]}+ max={allowedMinPayoutAmounts[allowedMinPayoutAmounts.length - 1]}onChange={(value) => {- const closest = ALLOWED_MIN_PAYOUT_AMOUNTS.reduce(- (prev, curr) =>- Math.abs(curr - value) < Math.abs(prev - value)- ? curr- : prev,+ const closest = allowedMinPayoutAmounts.reduce((prev, curr) =>+ Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev,);setValue("minPayoutAmount", closest, {@@ -165,7 +161,7 @@ function ProgramPayoutSettingsSheetContent({shouldValidate: true,});}}- marks={ALLOWED_MIN_PAYOUT_AMOUNTS}+ marks={allowedMinPayoutAmounts}/></div></div>diff --git a/apps/web/lib/actions/partners/update-program.ts b/apps/web/lib/actions/partners/update-program.tsindex 2ac24c1104..70924d3a37 100644--- a/apps/web/lib/actions/partners/update-program.ts+++ b/apps/web/lib/actions/partners/update-program.ts@@ -2,6 +2,7 @@import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";+import { getAllowedMinPayoutAmounts } from "@/lib/constants/payouts";import { getPlanCapabilities } from "@/lib/plan-capabilities";import { prisma } from "@/lib/prisma";import { submittedLeadFormSchema } from "@/lib/zod/schemas/submitted-lead-form";@@ -37,6 +38,13 @@ export const updateProgramAction = authActionClientrequiredRoles: ["owner", "member"],});+ if (+ minPayoutAmount !== undefined &&+ !getAllowedMinPayoutAmounts(workspace.id).includes(minPayoutAmount)+ ) {+ throw new Error("Invalid minimum payout amount.");+ }+const programId = getDefaultProgramIdOrThrow(workspace);const program = await getProgramOrThrow({diff --git a/apps/web/lib/constants/payouts.ts b/apps/web/lib/constants/payouts.tsindex 06e4f1ec56..0ce3349d66 100644--- a/apps/web/lib/constants/payouts.ts+++ b/apps/web/lib/constants/payouts.ts@@ -4,6 +4,20 @@ import { PaymentMethodOption } from "../types";export const PAYOUT_HOLDING_PERIOD_DAYS = [0, 7, 14, 30, 60, 90];export const ALLOWED_MIN_PAYOUT_AMOUNTS = [0, 1000, 2000, 5000, 10000];+export const EXTENDED_MIN_PAYOUT_AMOUNT_CENTS = 20000; // $200++export const EXTENDED_MIN_PAYOUT_WORKSPACE_IDS = new Set<string>([+ "clsvopiw0000ejy0grp821me0",+ "clrei1gld0002vs9mzn93p8ik",+]);++export function getAllowedMinPayoutAmounts(workspaceId: string): number[] {+ if (EXTENDED_MIN_PAYOUT_WORKSPACE_IDS.has(workspaceId)) {+ return [...ALLOWED_MIN_PAYOUT_AMOUNTS, EXTENDED_MIN_PAYOUT_AMOUNT_CENTS];+ }++ return ALLOWED_MIN_PAYOUT_AMOUNTS;+}export const PAYOUTS_SHEET_ITEMS_LIMIT = 10;export const ELIGIBLE_PAYOUTS_MAX_PAGE_SIZE = 500;diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.tsindex cbfb419ec1..93d510b973 100644--- a/apps/web/lib/zod/schemas/programs.ts+++ b/apps/web/lib/zod/schemas/programs.ts@@ -2,10 +2,7 @@ import {DATE_RANGE_INTERVAL_PRESETS,DUB_PARTNERS_ANALYTICS_INTERVAL,} from "@/lib/analytics/constants";-import {- ALLOWED_MIN_PAYOUT_AMOUNTS,- PAYOUT_HOLDING_PERIOD_DAYS,-} from "@/lib/constants/payouts";+import { PAYOUT_HOLDING_PERIOD_DAYS } from "@/lib/constants/payouts";import { COUNTRY_CODES } from "@dub/utils";import {Category,@@ -98,11 +95,7 @@ export const updateProgramSchema = z.object({.refine((val) => PAYOUT_HOLDING_PERIOD_DAYS.includes(val), {message: `Holding period must be ${PAYOUT_HOLDING_PERIOD_DAYS.join(", ")} days`,}),- minPayoutAmount: z.coerce- .number()- .refine((val) => ALLOWED_MIN_PAYOUT_AMOUNTS.includes(val), {- message: `Minimum payout amount must be one of ${ALLOWED_MIN_PAYOUT_AMOUNTS.join(", ")}`,- }),+ minPayoutAmount: z.coerce.number(),supportEmail: z.email().max(255).nullish(),helpUrl: z.httpUrl().max(500).nullish(),termsUrl: z.httpUrl().max(500).nullish(),