The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Dynamic program pages
Steven Teyb27e793fbe33
diff --git a/apps/web/app/partners.dub.co/(dashboard)/marketplace/[marketplaceProgramSlug]/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/marketplace/[marketplaceProgramSlug]/page.tsxnew file mode 100644index 0000000000..e089c9e238--- /dev/null+++ b/apps/web/app/partners.dub.co/(dashboard)/marketplace/[marketplaceProgramSlug]/page.tsx@@ -0,0 +1,112 @@+import { getProgram } from "@/lib/fetchers/get-program";+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 { MaxWidthWrapper } from "@dub/ui";+import { cn } from "@dub/utils";+import { ApplyButton } from "app/partners.dub.co/(apply)/[programSlug]/apply-button";+import { notFound } from "next/navigation";+import { CSSProperties } from "react";++export default async function MarketplaceProgramPage({+ params: { marketplaceProgramSlug },+}: {+ params: { marketplaceProgramSlug: string };+}) {+ const program = await getProgram({+ slug: marketplaceProgramSlug,+ include: ["rewards", "defaultDiscount"],+ });++ if (!program) {+ notFound();+ }++ // TODO: reuse from /(apply)/[programSlug]/page.tsx+ return (+ <MaxWidthWrapper>+ <div+ className="relative"+ style={+ {+ "--brand": "#000000",+ "--brand-ring": "rgb(from var(--brand) r g b / 0.2)",+ } as CSSProperties+ }+ >+ <div className="p-6">+ {/* Hero section */}+ <div className="grid grid-cols-1 gap-5 sm:pt-20">+ <span+ className={cn(+ "font-mono text-xs font-medium uppercase text-[var(--brand)]",+ "animate-slide-up-fade [--offset:5px] [animation-duration:1s] [animation-fill-mode:both]",+ )}+ >+ Affiliate Program+ </span>+ <h1+ className={cn(+ "text-4xl font-semibold",+ "animate-slide-up-fade [--offset:5px] [animation-delay:100ms] [animation-duration:1s] [animation-fill-mode:both]",+ )}+ >+ Join the {program.name} affiliate program+ </h1>+ <p+ className={cn(+ "text-base text-neutral-700",+ "animate-slide-up-fade [--offset:5px] [animation-delay:200ms] [animation-duration:1s] [animation-fill-mode:both]",+ )}+ >+ Share {program.name} with your audience and for each subscription+ generated through your referral, you'll earn a share of the+ revenue on any plans they purchase.+ </p>+ {/* <p className="text-xs text-neutral-500">+ Read our{" "}+ <a+ href="#"+ className="underline transition-colors duration-100 hover:text-neutral-600"+ >+ Terms of Service+ </a>{" "}+ for more details.+ </p> */}+ </div>++ {/* Program details grid */}+ <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]">+ <ApplyButton programSlug={program.slug} />+ </div>+ </div>++ {/* Content blocks */}+ {program.landerData && (+ <div className="mt-16 grid grid-cols-1 gap-10">+ {programLanderSchema+ .parse(program.landerData)+ .blocks.map((block, idx) => {+ const Component = BLOCK_COMPONENTS[block.type];+ return Component ? (+ <Component key={idx} block={block} logo={program.logo} />+ ) : null;+ })}+ </div>+ )}+ </div>+ </MaxWidthWrapper>+ );+}diff --git a/apps/web/lib/middleware/partners.ts b/apps/web/lib/middleware/partners.tsindex 3627d9cbe0..2831789c7b 100644--- a/apps/web/lib/middleware/partners.ts+++ b/apps/web/lib/middleware/partners.ts@@ -1,4 +1,5 @@import { parse } from "@/lib/middleware/utils";+import { prismaEdge } from "@dub/prisma/edge";import { NextRequest, NextResponse } from "next/server";import { getDefaultPartnerId } from "./utils/get-default-partner";import { getUserViaToken } from "./utils/get-user-via-token";@@ -57,6 +58,22 @@ export default async function PartnersMiddleware(req: NextRequest) {return NextResponse.redirect(new URL(`/programs/${match[1]}`, req.url));}return NextResponse.redirect(new URL("/", req.url)); // Redirect authenticated users to dashboard+ } else if (path.startsWith("/programs/")) {+ const programSlug = path.split("/")[2];+ const programEnrollment = await prismaEdge.programEnrollment.findFirst({+ where: {+ partnerId: defaultPartnerId,+ program: {+ slug: programSlug,+ },+ },+ });++ if (!programEnrollment) {+ return NextResponse.rewrite(+ new URL(`/partners.dub.co/marketplace/${programSlug}`, req.url),+ );+ }}}diff --git a/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsxindex e56fa4f155..aacc780980 100644--- a/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx+++ b/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx@@ -13,7 +13,6 @@ import {User,Users,} from "@dub/ui/icons";-import { Store } from "lucide-react";import { useParams, usePathname } from "next/navigation";import { ReactNode, useMemo } from "react";import { Hyperlink } from "./icons/hyperlink";@@ -36,15 +35,15 @@ const NAV_AREAS: SidebarNavAreas<{{items: [{- name: "Programs",- icon: GridIcon,- href: "/programs",+ name: "Overview",+ icon: Gauge6,+ href: "/",exact: true,},{- name: "Marketplace",- icon: Store,- href: "/marketplace",+ name: "Programs",+ icon: GridIcon,+ href: "/programs",},{name: "Settings",