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.

Add support for custom discount description

Steven Teyb6f2baddc662
diff --git a/apps/web/lib/zod/schemas/discount.ts b/apps/web/lib/zod/schemas/discount.ts
index ce21d67f4c..f5da8fd1cc 100644
--- a/apps/web/lib/zod/schemas/discount.ts
+++ b/apps/web/lib/zod/schemas/discount.ts
@@ -7,6 +7,7 @@ export const DiscountSchema = z.object({
amount: z.number(),
type: z.nativeEnum(CommissionType),
maxDuration: z.number().nullable(),
+ description: z.string().nullish(),
couponId: z.string().nullable(),
couponTestId: z.string().nullable(),
partnersCount: z.number().nullish(),
diff --git a/apps/web/ui/partners/format-discount-description.ts b/apps/web/ui/partners/format-discount-description.ts
index b88a402eb0..b1658fa4ba 100644
--- a/apps/web/ui/partners/format-discount-description.ts
+++ b/apps/web/ui/partners/format-discount-description.ts
@@ -5,8 +5,15 @@ import { pluralize } from "@dub/utils";
export function formatDiscountDescription({
discount,
}: {
- discount: Pick<DiscountProps, "amount" | "type" | "maxDuration">;
+ discount: Pick<
+ DiscountProps,
+ "amount" | "type" | "maxDuration" | "description"
+ >;
}): string {
+ if (discount.description) {
+ return discount.description;
+ }
+
const discountAmount = constructRewardAmount(discount);
const parts: string[] = [];
diff --git a/apps/web/ui/partners/program-reward-list.tsx b/apps/web/ui/partners/program-reward-list.tsx
index e034309905..7e73e503c9 100644
--- a/apps/web/ui/partners/program-reward-list.tsx
+++ b/apps/web/ui/partners/program-reward-list.tsx
@@ -41,24 +41,25 @@ export function ProgramRewardList({
)}
</Item>
))}
- {discount && (
- <Item icon={Gift}>
- {" "}
- New users get{" "}
- {constructRewardAmount({
- amount: discount.amount,
- type: discount.type,
- })}{" "}
- off{" "}
- {discount.maxDuration === null ? (
- <> for their lifetime</>
- ) : discount.maxDuration && discount.maxDuration > 1 ? (
- <>for {discount.maxDuration} months</>
- ) : (
- <>for their first purchase</>
- )}
- </Item>
- )}
+ {discount &&
+ (discount.description || (
+ <Item icon={Gift}>
+ {" "}
+ New users get{" "}
+ {constructRewardAmount({
+ amount: discount.amount,
+ type: discount.type,
+ })}{" "}
+ off{" "}
+ {discount.maxDuration === null ? (
+ <> for their lifetime</>
+ ) : discount.maxDuration && discount.maxDuration > 1 ? (
+ <>for {discount.maxDuration} months</>
+ ) : (
+ <>for their first purchase</>
+ )}
+ </Item>
+ ))}
</ul>
);
}
diff --git a/packages/prisma/schema/discount.prisma b/packages/prisma/schema/discount.prisma
index 04ec8ac3c8..69ca3634b6 100644
--- a/packages/prisma/schema/discount.prisma
+++ b/packages/prisma/schema/discount.prisma
@@ -4,6 +4,7 @@ model Discount {
amount Int @default(0)
type CommissionType @default(percentage)
maxDuration Int? // in months (0 -> not recurring, null -> lifetime)
+ description String?
couponId String?
couponTestId String?
@@ -17,9 +18,5 @@ model Discount {
defaultForProgram Program? @relation("ProgramDefaultDiscount")
program Program @relation("ProgramDiscounts", fields: [programId], references: [id], onDelete: Cascade, onUpdate: Cascade)
- // Remove these fields after running the migration
- duration Int?
- interval CommissionInterval?
-
@@index(programId)
}