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.

Refactor constructRewardAmount usage

Kiran K20861f4012e2
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 781d506545..d03255d52b 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
@@ -20,7 +20,7 @@ export function ReferralsEmbedFAQ({
reward: RewardProps | null;
}) {
const rewardDescription = reward
- ? `For each new customer you refer, you'll earn a ${constructRewardAmount({ reward })} commission on their subscription${
+ ? `For each new customer you refer, you'll earn a ${constructRewardAmount(reward)} commission on their subscription${
reward.maxDuration === null
? " for their lifetime"
: reward.maxDuration && reward.maxDuration > 1
diff --git a/apps/web/app/api/og/program/route.tsx b/apps/web/app/api/og/program/route.tsx
index eead44f394..8ca020e8e6 100644
--- a/apps/web/app/api/og/program/route.tsx
+++ b/apps/web/app/api/og/program/route.tsx
@@ -147,8 +147,7 @@ export async function GET(req: NextRequest) {
tw="font-semibold mr-1"
style={{ fontFamily: "Inter Semibold" }}
>
- {constructRewardAmount({ reward: rewards[0] })} per{" "}
- {rewards[0].event}
+ {constructRewardAmount(rewards[0])} per {rewards[0].event}
</strong>
{rewards[0].maxDuration === null ? (
"for the customer's lifetime"
diff --git a/apps/web/lib/api/sales/construct-reward-amount.ts b/apps/web/lib/api/sales/construct-reward-amount.ts
index 1486e483da..b96a741c5a 100644
--- a/apps/web/lib/api/sales/construct-reward-amount.ts
+++ b/apps/web/lib/api/sales/construct-reward-amount.ts
@@ -2,11 +2,9 @@ import { RewardProps } from "@/lib/types";
import { rewardConditionsArraySchema } from "@/lib/zod/schemas/rewards";
import { currencyFormatter } from "@dub/utils";
-export const constructRewardAmount = ({
- reward,
-}: {
- reward: Pick<RewardProps, "amount" | "type" | "maxDuration" | "modifiers">;
-}) => {
+export const constructRewardAmount = (
+ reward: Pick<RewardProps, "amount" | "type" | "maxDuration" | "modifiers">,
+) => {
// If there are modifiers, we need to check if they match the primary reward
if (reward.modifiers) {
const parsedModifiers = rewardConditionsArraySchema.safeParse(
diff --git a/apps/web/ui/partners/format-discount-description.ts b/apps/web/ui/partners/format-discount-description.ts
index 36db3fa365..d7d9138b87 100644
--- a/apps/web/ui/partners/format-discount-description.ts
+++ b/apps/web/ui/partners/format-discount-description.ts
@@ -14,9 +14,7 @@ export function formatDiscountDescription({
return discount.description;
}
- const discountAmount = constructRewardAmount({
- reward: discount,
- });
+ const discountAmount = constructRewardAmount(discount);
const parts: string[] = [];
diff --git a/apps/web/ui/partners/format-reward-description.ts b/apps/web/ui/partners/format-reward-description.ts
index d8c88d1f8f..e3d41b7e76 100644
--- a/apps/web/ui/partners/format-reward-description.ts
+++ b/apps/web/ui/partners/format-reward-description.ts
@@ -13,7 +13,7 @@ export function formatRewardDescription({
return reward.description;
}
- const rewardAmount = constructRewardAmount({ reward });
+ const rewardAmount = constructRewardAmount(reward);
const parts: string[] = [];
parts.push("Earn");
diff --git a/apps/web/ui/partners/program-reward-description.tsx b/apps/web/ui/partners/program-reward-description.tsx
index 6d35a45453..8986403f97 100644
--- a/apps/web/ui/partners/program-reward-description.tsx
+++ b/apps/web/ui/partners/program-reward-description.tsx
@@ -26,9 +26,7 @@ export function ProgramRewardDescription({
<>
Earn{" "}
<strong className={cn("font-semibold", amountClassName)}>
- {constructRewardAmount({
- reward,
- })}{" "}
+ {constructRewardAmount(reward)}{" "}
</strong>
{reward.event === "sale" && reward.maxDuration === 0 ? (
<>for the first sale</>
@@ -70,9 +68,7 @@ export function ProgramRewardDescription({
{" "}
New users get{" "}
<strong className={cn("font-semibold", amountClassName)}>
- {constructRewardAmount({
- reward: discount,
- })}
+ {constructRewardAmount(discount)}
</strong>{" "}
off{" "}
{discount.maxDuration === null ? (
diff --git a/apps/web/ui/partners/program-reward-list.tsx b/apps/web/ui/partners/program-reward-list.tsx
index 5cd03d3cc8..dac800c14b 100644
--- a/apps/web/ui/partners/program-reward-list.tsx
+++ b/apps/web/ui/partners/program-reward-list.tsx
@@ -30,9 +30,7 @@ export function ProgramRewardList({
<Item key={reward.id} icon={REWARD_EVENTS[reward.event].icon}>
{reward.description || (
<>
- {constructRewardAmount({
- reward,
- })}{" "}
+ {constructRewardAmount(reward)}{" "}
{reward.event === "sale" && reward.maxDuration === 0 ? (
<>for the first sale</>
) : (
@@ -72,11 +70,7 @@ export function ProgramRewardList({
{discount.description || (
<>
{" "}
- New users get{" "}
- {constructRewardAmount({
- reward: discount,
- })}{" "}
- off{" "}
+ New users get {constructRewardAmount(discount)} off{" "}
{discount.maxDuration === null ? (
<> for their lifetime</>
) : discount.maxDuration && discount.maxDuration > 1 ? (
diff --git a/apps/web/ui/partners/program-reward-modifiers-tooltip.tsx b/apps/web/ui/partners/program-reward-modifiers-tooltip.tsx
index fc2f40b6ea..cdb220261d 100644
--- a/apps/web/ui/partners/program-reward-modifiers-tooltip.tsx
+++ b/apps/web/ui/partners/program-reward-modifiers-tooltip.tsx
@@ -67,10 +67,8 @@ const RewardItem = ({
>[number]["conditions"];
}) => {
const rewardAmount = constructRewardAmount({
- reward: {
- ...reward,
- modifiers: undefined,
- },
+ ...reward,
+ modifiers: undefined,
});
const durationText =
diff --git a/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx b/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx
index 0f2ea3bb93..b35245b458 100644
--- a/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx
+++ b/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx
@@ -293,11 +293,9 @@ function RewardSheetContent({
text={
amount
? constructRewardAmount({
- reward: {
- amount: type === "flat" ? amount * 100 : amount,
- type,
- maxDuration,
- },
+ amount: type === "flat" ? amount * 100 : amount,
+ type,
+ maxDuration,
})
: "amount"
}
diff --git a/apps/web/ui/partners/rewards/rewards-logic.tsx b/apps/web/ui/partners/rewards/rewards-logic.tsx
index ee2ae76d84..8faa00b09e 100644
--- a/apps/web/ui/partners/rewards/rewards-logic.tsx
+++ b/apps/web/ui/partners/rewards/rewards-logic.tsx
@@ -616,11 +616,9 @@ function ResultTerms({ modifierIndex }: { modifierIndex: number }) {
text={
amount
? constructRewardAmount({
- reward: {
- amount: displayType === "flat" ? amount * 100 : amount,
- type: displayType,
- maxDuration: displayMaxDuration,
- },
+ amount: displayType === "flat" ? amount * 100 : amount,
+ type: displayType,
+ maxDuration: displayMaxDuration,
})
: "amount"
}