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.

display the correct reward on the apply pages

Kiran K025b8f1a8cc8
diff --git a/apps/web/app/partners.dub.co/(apply)/[programSlug]/apply/page.tsx b/apps/web/app/partners.dub.co/(apply)/[programSlug]/apply/page.tsx
index 8476c2e1dd..af0b294c1b 100644
--- a/apps/web/app/partners.dub.co/(apply)/[programSlug]/apply/page.tsx
+++ b/apps/web/app/partners.dub.co/(apply)/[programSlug]/apply/page.tsx
@@ -1,4 +1,5 @@
import { getProgram } from "@/lib/fetchers/get-program";
+import { getReward } from "@/lib/fetchers/get-reward";
import { notFound } from "next/navigation";
import { CSSProperties } from "react";
import { DetailsGrid } from "../details-grid";
@@ -12,10 +13,12 @@ export default async function ApplicationPage({
}) {
const program = await getProgram({ slug: programSlug });
- if (!program) {
+ if (!program || !program.defaultRewardId) {
notFound();
}
+ const reward = await getReward({ id: program.defaultRewardId });
+
return (
<div
className="relative"
@@ -47,7 +50,7 @@ export default async function ApplicationPage({
</div>
{/* Program details grid */}
- <DetailsGrid program={program} className="mt-10" />
+ <DetailsGrid reward={reward} className="mt-10" />
{/* Application form */}
<div className="mt-10">
diff --git a/apps/web/app/partners.dub.co/(apply)/[programSlug]/details-grid.tsx b/apps/web/app/partners.dub.co/(apply)/[programSlug]/details-grid.tsx
index c6b4fd9c8c..0af1b4d1f8 100644
--- a/apps/web/app/partners.dub.co/(apply)/[programSlug]/details-grid.tsx
+++ b/apps/web/app/partners.dub.co/(apply)/[programSlug]/details-grid.tsx
@@ -1,13 +1,13 @@
import { constructRewardAmount } from "@/lib/api/sales/construct-reward-amount";
-import { Program } from "@dub/prisma/client";
+import { Reward } from "@dub/prisma/client";
import { Calendar6, MoneyBills2 } from "@dub/ui/icons";
-import { cn, INFINITY_NUMBER, pluralize } from "@dub/utils";
+import { cn } from "@dub/utils";
export function DetailsGrid({
- program,
+ reward,
className,
}: {
- program: Program;
+ reward: Reward;
className?: string;
}) {
return (
@@ -17,20 +17,19 @@ export function DetailsGrid({
icon: MoneyBills2,
title: "Commission",
value: constructRewardAmount({
- amount: program.commissionAmount,
- type: program.commissionType,
+ amount: reward.amount,
+ type: reward.type,
}),
},
{
icon: Calendar6,
title: "Duration",
value:
- program.commissionDuration === INFINITY_NUMBER
+ reward.maxDuration === null
? "Lifetime"
- : `${program.commissionDuration} ${pluralize(
- program.commissionInterval || "cycle",
- program.commissionDuration || 0,
- )}`,
+ : reward.maxDuration === 0
+ ? "1 month"
+ : `${reward.maxDuration} months`,
},
].map(({ icon: Icon, title, value }) => (
<div className="rounded-xl bg-neutral-100 p-4">
diff --git a/apps/web/app/partners.dub.co/(apply)/[programSlug]/page.tsx b/apps/web/app/partners.dub.co/(apply)/[programSlug]/page.tsx
index c093233e68..711a669b89 100644
--- a/apps/web/app/partners.dub.co/(apply)/[programSlug]/page.tsx
+++ b/apps/web/app/partners.dub.co/(apply)/[programSlug]/page.tsx
@@ -1,4 +1,5 @@
import { getProgram } from "@/lib/fetchers/get-program";
+import { getReward } from "@/lib/fetchers/get-reward";
import { programLanderSchema } from "@/lib/zod/schemas/program-lander";
import { BLOCK_COMPONENTS } from "@/ui/partners/lander-blocks";
import { cn } from "@dub/utils";
@@ -15,10 +16,11 @@ export default async function ApplyPage({
}) {
const program = await getProgram({ slug: programSlug });
- if (!program || !program.landerData) {
+ if (!program || !program.landerData || !program.defaultRewardId) {
notFound();
}
+ const reward = await getReward({ id: program.defaultRewardId });
const landerData = programLanderSchema.parse(program.landerData);
return (
@@ -78,7 +80,7 @@ export default async function ApplyPage({
{/* Program details grid */}
<DetailsGrid
- program={program}
+ reward={reward}
className="animate-slide-up-fade mt-10 [animation-delay:300ms] [animation-duration:1s] [animation-fill-mode:both]"
/>
diff --git a/apps/web/lib/fetchers/get-reward.ts b/apps/web/lib/fetchers/get-reward.ts
new file mode 100644
index 0000000000..9434d099dc
--- /dev/null
+++ b/apps/web/lib/fetchers/get-reward.ts
@@ -0,0 +1,10 @@
+import { prisma } from "@dub/prisma";
+import { cache } from "react";
+
+export const getReward = cache(async ({ id }: { id: string }) => {
+ return await prisma.reward.findUniqueOrThrow({
+ where: {
+ id,
+ },
+ });
+});
diff --git a/packages/prisma/schema/program.prisma b/packages/prisma/schema/program.prisma
index 18731845ff..726eea1c5c 100644
--- a/packages/prisma/schema/program.prisma
+++ b/packages/prisma/schema/program.prisma
@@ -25,33 +25,28 @@ enum ProgramResourceType {
}
model Program {
- id String @id @default(cuid())
- workspaceId String
- defaultFolderId String?
- name String
- slug String @unique
- logo String?
- wordmark String?
- brandColor String?
- domain String?
- url String?
- type ProgramType @default(affiliate)
- cookieLength Int @default(90)
+ id String @id @default(cuid())
+ workspaceId String
+ defaultFolderId String?
+ name String
+ slug String @unique
+ logo String?
+ wordmark String?
+ brandColor String?
+ domain String?
+ url String?
+ type ProgramType @default(affiliate)
+ cookieLength Int @default(90)
+ holdingPeriodDays Int @default(0) // number of days to wait before earnings are added to a payout
+ defaultRewardId String? // default reward for the program
+ landerData Json? @db.Json
// Commission details
- // TODO: Remove this after merging Rewards
+ // TODO: Remove this after merging Rewards PR
commissionAmount Int @default(0)
commissionType CommissionType @default(percentage)
commissionDuration Int?
commissionInterval CommissionInterval?
- holdingPeriodDays Int @default(0) // number of days to wait before earnings are added to a payout
-
- defaultRewardId String? // default reward for the program
-
- // Discounts (for dual-sided incentives)
- discounts Discount[]
-
- landerData Json? @db.Json
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -67,6 +62,7 @@ model Program {
links Link[]
commissions Commission[]
rewards Reward[]
+ discounts Discount[]
@@index([workspaceId])
@@index([domain])