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 amount ranges to reward descriptions

Tim Wilsona982d85fac02
diff --git a/apps/web/app/(ee)/app.dub.co/embed/referrals/faq.tsx b/apps/web/app/(ee)/app.dub.co/embed/referrals/faq.tsx
index d15857f7df..6148d92d80 100644
--- a/apps/web/app/(ee)/app.dub.co/embed/referrals/faq.tsx
+++ b/apps/web/app/(ee)/app.dub.co/embed/referrals/faq.tsx
@@ -21,7 +21,14 @@ export function ReferralsEmbedFAQ({
}) {
const rewardDescription = reward
? `For each new customer you refer, you'll earn a ${constructRewardAmount({
- amount: reward.amount,
+ ...(reward.modifiers
+ ? {
+ amounts: [
+ reward.amount,
+ ...reward.modifiers.map(({ amount }) => amount),
+ ],
+ }
+ : { amount: reward.amount }),
type: reward.type,
})} commission on their subscription${
reward.maxDuration === null
diff --git a/apps/web/app/api/og/program/route.tsx b/apps/web/app/api/og/program/route.tsx
index a95357bd6f..e267f65e4e 100644
--- a/apps/web/app/api/og/program/route.tsx
+++ b/apps/web/app/api/og/program/route.tsx
@@ -139,7 +139,14 @@ export async function GET(req: NextRequest) {
style={{ fontFamily: "Inter Semibold" }}
>
{constructRewardAmount({
- amount: rewards[0].amount,
+ ...(rewards[0].modifiers
+ ? {
+ amounts: [
+ rewards[0].amount,
+ ...rewards[0].modifiers.map(({ amount }) => amount),
+ ],
+ }
+ : { amount: rewards[0].amount }),
type: rewards[0].type,
})}{" "}
per {rewards[0].event}
diff --git a/apps/web/lib/api/sales/construct-reward-amount.ts b/apps/web/lib/api/sales/construct-reward-amount.ts
index bfd31f63dd..3ddd66aa32 100644
--- a/apps/web/lib/api/sales/construct-reward-amount.ts
+++ b/apps/web/lib/api/sales/construct-reward-amount.ts
@@ -2,21 +2,36 @@ import { RewardStructure } from "@dub/prisma/client";
import { currencyFormatter } from "@dub/utils";
export const constructRewardAmount = ({
- amount,
type,
+ amount: amountProp,
+ amounts,
}: {
- amount: number;
type: RewardStructure;
-}) => {
- return type === "percentage"
- ? `${amount}%`
- : currencyFormatter(
- amount / 100,
- amount % 100 === 0
- ? undefined
- : {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- },
- );
+} & (
+ | { amount: number; amounts?: never }
+ | { amount?: never; amounts: number[] }
+)) => {
+ // Range of amounts
+ if (amounts && amounts.length > 1) {
+ const min = Math.min(...amounts);
+ const max = Math.max(...amounts);
+ return type === "percentage"
+ ? `${min} - ${max}%`
+ : `${formatCurrency(min)} - ${formatCurrency(max)}`;
+ }
+
+ // Single amount
+ const amount = amountProp ?? amounts?.[0];
+ return type === "percentage" ? `${amount}%` : formatCurrency(amount);
};
+
+const formatCurrency = (amount: number) =>
+ currencyFormatter(
+ amount / 100,
+ amount % 100 === 0
+ ? undefined
+ : {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ },
+ );
diff --git a/apps/web/ui/partners/program-reward-description.tsx b/apps/web/ui/partners/program-reward-description.tsx
index 4b0b28043e..fa0e8dbb66 100644
--- a/apps/web/ui/partners/program-reward-description.tsx
+++ b/apps/web/ui/partners/program-reward-description.tsx
@@ -10,7 +10,7 @@ export function ProgramRewardDescription({
}: {
reward?: Pick<
RewardProps,
- "amount" | "type" | "event" | "maxDuration" | "description"
+ "amount" | "type" | "event" | "maxDuration" | "description" | "modifiers"
> | null;
discount?: DiscountProps | null;
amountClassName?: string;
@@ -24,7 +24,14 @@ export function ProgramRewardDescription({
Earn{" "}
<strong className={cn("font-semibold", amountClassName)}>
{constructRewardAmount({
- amount: reward.amount,
+ ...(reward.modifiers
+ ? {
+ amounts: [
+ reward.amount,
+ ...reward.modifiers.map(({ amount }) => amount),
+ ],
+ }
+ : { amount: reward.amount }),
type: reward.type,
})}{" "}
</strong>
diff --git a/apps/web/ui/partners/program-reward-list.tsx b/apps/web/ui/partners/program-reward-list.tsx
index 47034929a7..5e8344451f 100644
--- a/apps/web/ui/partners/program-reward-list.tsx
+++ b/apps/web/ui/partners/program-reward-list.tsx
@@ -28,7 +28,14 @@ export function ProgramRewardList({
{reward.description || (
<>
{constructRewardAmount({
- amount: reward.amount,
+ ...(reward.modifiers
+ ? {
+ amounts: [
+ reward.amount,
+ ...reward.modifiers.map(({ amount }) => amount),
+ ],
+ }
+ : { amount: reward.amount }),
type: reward.type,
})}{" "}
{reward.event === "sale" && reward.maxDuration === 0 ? (
diff --git a/packages/ui/src/sheet.tsx b/packages/ui/src/sheet.tsx
index 80b6224587..3bd4dc54bf 100644
--- a/packages/ui/src/sheet.tsx
+++ b/packages/ui/src/sheet.tsx
@@ -40,7 +40,7 @@ function SheetRoot({
// 8px between edge of screen and drawer
{
"--initial-transform": "calc(100% + 8px)",
- "user-select": "auto", // Override default user-select: none from Vaul
+ userSelect: "auto", // Override default user-select: none from Vaul
...contentProps?.style,
} as React.CSSProperties
}