The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Refactor payout settings to use allowed minimum amounts and update related schemas
Kiran K997c354617c9
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-settings-modal.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-settings-modal.tsxindex f23dbe2450..dbe3167bb8 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-settings-modal.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-settings-modal.tsx@@ -4,7 +4,7 @@ import { updatePartnerPayoutSettingsAction } from "@/lib/actions/partners/updateimport {BELOW_MIN_WITHDRAWAL_FEE_CENTS,MIN_WITHDRAWAL_AMOUNT_CENTS,- MINIMUM_WITHDRAWAL_AMOUNTS,+ ALLOWED_MIN_WITHDRAWAL_AMOUNTS,} from "@/lib/partners/constants";import { mutatePrefix } from "@/lib/swr/mutate";import usePartnerProfile from "@/lib/swr/use-partner-profile";@@ -114,14 +114,14 @@ function PayoutSettingsModalInner({<Slidervalue={minWithdrawalAmount}- min={MINIMUM_WITHDRAWAL_AMOUNTS[0]}+ min={ALLOWED_MIN_WITHDRAWAL_AMOUNTS[0]}max={- MINIMUM_WITHDRAWAL_AMOUNTS[- MINIMUM_WITHDRAWAL_AMOUNTS.length - 1+ ALLOWED_MIN_WITHDRAWAL_AMOUNTS[+ ALLOWED_MIN_WITHDRAWAL_AMOUNTS.length - 1]}onChange={(value) => {- const closest = MINIMUM_WITHDRAWAL_AMOUNTS.reduce(+ const closest = ALLOWED_MIN_WITHDRAWAL_AMOUNTS.reduce((prev, curr) =>Math.abs(curr - value) < Math.abs(prev - value)? curr@@ -130,7 +130,7 @@ function PayoutSettingsModalInner({setValue("minWithdrawalAmount", closest, { shouldDirty: true });}}- marks={MINIMUM_WITHDRAWAL_AMOUNTS}+ marks={ALLOWED_MIN_WITHDRAWAL_AMOUNTS}hint={minWithdrawalAmount < MIN_WITHDRAWAL_AMOUNT_CENTS? `${currencyFormatter(BELOW_MIN_WITHDRAWAL_FEE_CENTS / 100)} payout fee for payouts under $100`diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-settings-modal.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-settings-modal.tsxindex 9be934b3fc..c31921e4e1 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-settings-modal.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-settings-modal.tsx@@ -2,14 +2,14 @@import { parseActionError } from "@/lib/actions/parse-action-errors";import { updateProgramAction } from "@/lib/actions/partners/update-program";-import { handleMoneyInputChange, handleMoneyKeyDown } from "@/lib/form-utils";+import { ALLOWED_MIN_PAYOUT_AMOUNTS } from "@/lib/partners/constants";import { mutatePrefix } from "@/lib/swr/mutate";import useProgram from "@/lib/swr/use-program";import useWorkspace from "@/lib/swr/use-workspace";import { ProgramProps } from "@/lib/types";import { HOLDING_PERIOD_DAYS } from "@/lib/zod/schemas/programs";import { Button, Modal } from "@dub/ui";-import { cn } from "@dub/utils";+import { currencyFormatter } from "@dub/utils";import { useAction } from "next-safe-action/hooks";import {Dispatch,@@ -53,7 +53,7 @@ function ProgramPayoutSettingsModalInner({register,handleSubmit,setValue,- formState: { isDirty, isValid, isSubmitting, errors },+ formState: { isDirty, isValid, isSubmitting },} = useForm<FormData>({mode: "onBlur",});@@ -61,7 +61,7 @@ function ProgramPayoutSettingsModalInner({useEffect(() => {if (program) {setValue("holdingPeriodDays", program.holdingPeriodDays);- setValue("minPayoutAmount", program.minPayoutAmount / 100);+ setValue("minPayoutAmount", program.minPayoutAmount);}}, [program, setValue]);@@ -118,26 +118,16 @@ function ProgramPayoutSettingsModalInner({Minimum payout amount</label><div className="relative mt-2 rounded-md shadow-sm">- <span className="absolute inset-y-0 left-0 flex items-center pl-3 text-sm text-neutral-400">- $- </span>-- <input- className={cn(- "block w-full rounded-md border-neutral-300 pl-6 pr-12 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",- errors.minPayoutAmount &&- "border-red-600 pr-7 focus:border-red-500 focus:ring-red-600",- )}- {...register("minPayoutAmount", {- valueAsNumber: true,- onChange: handleMoneyInputChange,- })}- onKeyDown={handleMoneyKeyDown}- />-- <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-sm text-neutral-400">- USD- </span>+ <select+ className="block w-full rounded-md border border-neutral-300 bg-white py-2 pl-3 pr-10 text-sm text-neutral-900 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500"+ {...register("minPayoutAmount", { required: true })}+ >+ {ALLOWED_MIN_PAYOUT_AMOUNTS.map((amount) => (+ <option value={amount} key={amount}>+ {currencyFormatter(amount / 100)} USD+ </option>+ ))}+ </select></div></div></div>diff --git a/apps/web/lib/actions/partners/update-program.ts b/apps/web/lib/actions/partners/update-program.tsindex 33118e3a9d..f4422663b4 100644--- a/apps/web/lib/actions/partners/update-program.ts+++ b/apps/web/lib/actions/partners/update-program.ts@@ -45,8 +45,6 @@ export const updateProgramAction = authActionClientdefaultFolderId,} = parsedInput;- console.log({ minPayoutAmount });-const programId = getDefaultProgramIdOrThrow(workspace);const program = await getProgramOrThrow({workspaceId: workspace.id,diff --git a/apps/web/lib/partners/constants.ts b/apps/web/lib/partners/constants.tsindex 3578b4695d..a3e60e0672 100644--- a/apps/web/lib/partners/constants.ts+++ b/apps/web/lib/partners/constants.ts@@ -9,6 +9,9 @@ export const FOREX_MARKUP_RATE = 0.005; // 0.5%export const MIN_WITHDRAWAL_AMOUNT_CENTS = 10000; // $100export const BELOW_MIN_WITHDRAWAL_FEE_CENTS = 200; // $2+export const ALLOWED_MIN_WITHDRAWAL_AMOUNTS = [1000, 2500, 5000, 7500, 10000];+export const ALLOWED_MIN_PAYOUT_AMOUNTS = [0, 2000, 5000, 10000, 20000];+// Direct debit payment types for Partner payoutexport const DIRECT_DEBIT_PAYMENT_TYPES_INFO: {type: Stripe.PaymentMethod.Type;@@ -76,5 +79,3 @@ export const PROGRAM_IMPORT_SOURCES = [helpUrl: "https://dub.co/help/article/migrating-from-tolt",},] as const;--export const MINIMUM_WITHDRAWAL_AMOUNTS = [1000, 2500, 5000, 7500, 10000];diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.tsindex e757cf1a87..b696449e73 100644--- a/apps/web/lib/zod/schemas/partners.ts+++ b/apps/web/lib/zod/schemas/partners.ts@@ -1,4 +1,4 @@-import { MINIMUM_WITHDRAWAL_AMOUNTS } from "@/lib/partners/constants";+import { ALLOWED_MIN_WITHDRAWAL_AMOUNTS } from "@/lib/partners/constants";import {PartnerBannedReason,PartnerProfileType,@@ -589,7 +589,7 @@ export const partnerPayoutSettingsSchema = z.object({.number().min(1000, "Minimum withdrawal amount must be greater than $10.").default(10000)- .refine((val) => MINIMUM_WITHDRAWAL_AMOUNTS.includes(val), {- message: `Minimum withdrawal amount must be one of ${MINIMUM_WITHDRAWAL_AMOUNTS.join(", ")}`,+ .refine((val) => ALLOWED_MIN_WITHDRAWAL_AMOUNTS.includes(val), {+ message: `Minimum withdrawal amount must be one of ${ALLOWED_MIN_WITHDRAWAL_AMOUNTS.join(", ")}`,}),});diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.tsindex 5785823c5d..2294891f54 100644--- a/apps/web/lib/zod/schemas/programs.ts+++ b/apps/web/lib/zod/schemas/programs.ts@@ -2,7 +2,9 @@ import {DATE_RANGE_INTERVAL_PRESETS,DUB_PARTNERS_ANALYTICS_INTERVAL,} from "@/lib/analytics/constants";+import { ALLOWED_MIN_PAYOUT_AMOUNTS } from "@/lib/partners/constants";import { LinkStructure, ProgramEnrollmentStatus } from "@dub/prisma/client";+import { currencyFormatter } from "@dub/utils";import { z } from "zod";import { DiscountSchema } from "./discount";import { LinkSchema } from "./links";@@ -57,9 +59,10 @@ export const updateProgramSchema = z.object({}),minPayoutAmount: z.coerce.number()- .nonnegative()- .nullish()- .transform((val) => (val ? val * 100 : 0)),+ .refine((val) => ALLOWED_MIN_PAYOUT_AMOUNTS.includes(val), {+ message: `Minimum payout amount must be one of ${ALLOWED_MIN_PAYOUT_AMOUNTS.map((amount) => currencyFormatter(amount / 100)).join(", ")}`,+ })+ .transform((val) => val * 100),linkStructure: z.nativeEnum(LinkStructure),supportEmail: z.string().email().max(255).nullish(),helpUrl: z.string().url().max(500).nullish(),