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 `ProgramRewardList` to landing + apply pages

Tim Wilson409370c9e82c
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 f3e05700a5..76daf1ae82 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,8 +1,7 @@
import { getProgram } from "@/lib/fetchers/get-program";
-import { getReward } from "@/lib/fetchers/get-reward";
+import { ProgramRewardList } from "@/ui/partners/program-reward-list";
import { notFound } from "next/navigation";
import { CSSProperties } from "react";
-import { DetailsGrid } from "../details-grid";
import { Header } from "../header";
import { ProgramApplicationForm } from "./form";
@@ -11,14 +10,15 @@ export default async function ApplicationPage({
}: {
params: { programSlug: string };
}) {
- const program = await getProgram({ slug: programSlug });
+ const program = await getProgram({
+ slug: programSlug,
+ include: ["rewards", "defaultDiscount"],
+ });
if (!program || !program.defaultRewardId) {
notFound();
}
- const reward = await getReward({ id: program.defaultRewardId });
-
return (
<div
className="relative"
@@ -49,8 +49,16 @@ export default async function ApplicationPage({
</p>
</div>
- {/* Program details grid */}
- <DetailsGrid reward={reward} className="mt-10" />
+ <div className="mt-10">
+ <h2 className="mb-2 text-base font-semibold text-neutral-800">
+ Rewards
+ </h2>
+ <ProgramRewardList
+ rewards={program.rewards}
+ discount={program.defaultDiscount}
+ className="bg-neutral-100"
+ />
+ </div>
{/* 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
deleted file mode 100644
index 2bbc3c69cb..0000000000
--- a/apps/web/app/partners.dub.co/(apply)/[programSlug]/details-grid.tsx
+++ /dev/null
@@ -1,45 +0,0 @@
-import { constructRewardAmount } from "@/lib/api/sales/construct-reward-amount";
-import { RewardProps } from "@/lib/types";
-import { Calendar6, MoneyBills2 } from "@dub/ui/icons";
-import { cn } from "@dub/utils";
-
-export function DetailsGrid({
- reward,
- className,
-}: {
- reward: RewardProps;
- className?: string;
-}) {
- return (
- <div className={cn("grid grid-cols-1 gap-4 sm:grid-cols-2", className)}>
- {[
- {
- icon: MoneyBills2,
- title: "Commission",
- value: constructRewardAmount({
- amount: reward.amount,
- type: reward.type,
- }),
- },
- {
- icon: Calendar6,
- title: "Duration",
- value:
- reward.maxDuration === null
- ? "Lifetime"
- : reward.maxDuration === 0
- ? "1 month"
- : `${reward.maxDuration} months`,
- },
- ].map(({ icon: Icon, title, value }) => (
- <div key={title} className="rounded-xl bg-neutral-100 p-4">
- <Icon className="size-5 text-neutral-500" />
- <div className="mt-6">
- <p className="font-mono text-xl text-neutral-900">{value}</p>
- <p className="mt-0.5 text-sm text-neutral-500">{title}</p>
- </div>
- </div>
- ))}
- </div>
- );
-}
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 711a669b89..87d2d0b5cd 100644
--- a/apps/web/app/partners.dub.co/(apply)/[programSlug]/page.tsx
+++ b/apps/web/app/partners.dub.co/(apply)/[programSlug]/page.tsx
@@ -1,12 +1,11 @@
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 { ProgramRewardList } from "@/ui/partners/program-reward-list";
import { cn } from "@dub/utils";
import { notFound } from "next/navigation";
import { CSSProperties } from "react";
import { ApplyButton } from "./apply-button";
-import { DetailsGrid } from "./details-grid";
import { Header } from "./header";
export default async function ApplyPage({
@@ -14,13 +13,15 @@ export default async function ApplyPage({
}: {
params: { programSlug: string };
}) {
- const program = await getProgram({ slug: programSlug });
+ const program = await getProgram({
+ slug: programSlug,
+ include: ["rewards", "defaultDiscount"],
+ });
if (!program || !program.landerData || !program.defaultRewardId) {
notFound();
}
- const reward = await getReward({ id: program.defaultRewardId });
const landerData = programLanderSchema.parse(program.landerData);
return (
@@ -79,10 +80,16 @@ export default async function ApplyPage({
</div>
{/* Program details grid */}
- <DetailsGrid
- reward={reward}
- className="animate-slide-up-fade mt-10 [animation-delay:300ms] [animation-duration:1s] [animation-fill-mode:both]"
- />
+ <div className="mt-10">
+ <h2 className="mb-2 text-base font-semibold text-neutral-800">
+ Rewards
+ </h2>
+ <ProgramRewardList
+ rewards={program.rewards}
+ discount={program.defaultDiscount}
+ className="bg-neutral-100"
+ />
+ </div>
{/* Buttons */}
<div className="animate-scale-in-fade mt-10 flex flex-col gap-2 [animation-delay:400ms] [animation-fill-mode:both]">
diff --git a/apps/web/lib/fetchers/get-program.ts b/apps/web/lib/fetchers/get-program.ts
index 414accca3c..7a1c64c8d3 100644
--- a/apps/web/lib/fetchers/get-program.ts
+++ b/apps/web/lib/fetchers/get-program.ts
@@ -1,10 +1,42 @@
import { prisma } from "@dub/prisma";
import { cache } from "react";
-export const getProgram = cache(async ({ slug }: { slug: string }) => {
- return await prisma.program.findUnique({
- where: {
- slug,
- },
- });
-});
+export const getProgram = cache(
+ async ({
+ slug,
+ include,
+ }: {
+ slug: string;
+ include?: ("rewards" | "defaultDiscount")[];
+ }) => {
+ const program = await prisma.program.findUnique({
+ where: {
+ slug,
+ },
+ include: {
+ ...(include?.includes("rewards") && {
+ rewards: {
+ where: {
+ partners: {
+ none: {}, // program-wide rewards only
+ },
+ },
+ },
+ }),
+ ...(include?.includes("defaultDiscount") && {
+ defaultDiscount: true,
+ }),
+ },
+ });
+
+ if (program && include?.includes("rewards")) {
+ program.rewards = ["click", "lead", "sale"]
+ .map((event) =>
+ program?.rewards.find((reward) => reward.event === event),
+ )
+ .filter((reward) => reward !== undefined && reward !== null);
+ }
+
+ return program;
+ },
+);