The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Move over lander builder stuff
Tim Wilson10bcea96d210
diff --git a/apps/web/lib/api/programs/get-program-or-throw.ts b/apps/web/lib/api/programs/get-program-or-throw.tsindex d720187e6a..3d770a3d1f 100644--- a/apps/web/lib/api/programs/get-program-or-throw.ts+++ b/apps/web/lib/api/programs/get-program-or-throw.ts@@ -1,6 +1,9 @@import { reorderTopProgramRewards } from "@/lib/partners/reorder-top-program-rewards";import { DiscountProps, ProgramProps } from "@/lib/types";-import { ProgramSchema } from "@/lib/zod/schemas/programs";+import {+ ProgramSchema,+ ProgramWithLanderDataSchema,+} from "@/lib/zod/schemas/programs";import { prisma } from "@dub/prisma";import { DubApiError } from "../errors";@@ -16,10 +19,12 @@ export const getProgramOrThrow = async (includeDefaultDiscount = false,includeDefaultReward = false,includeRewards = false,+ includeLanderData = false,}: {includeDefaultDiscount?: boolean;includeDefaultReward?: boolean;includeRewards?: boolean;+ includeLanderData?: boolean;} = {},) => {const program = (await prisma.program.findUnique({@@ -54,7 +59,9 @@ export const getProgramOrThrow = async (});}- return ProgramSchema.parse({+ return (+ includeLanderData ? ProgramWithLanderDataSchema : ProgramSchema+ ).parse({...program,...(includeRewards && program.rewards?.length? { rewards: reorderTopProgramRewards(program.rewards as any) }diff --git a/apps/web/lib/middleware/utils/app-redirect.ts b/apps/web/lib/middleware/utils/app-redirect.tsindex 3b444b34a7..000a0c4c08 100644--- a/apps/web/lib/middleware/utils/app-redirect.ts+++ b/apps/web/lib/middleware/utils/app-redirect.ts@@ -26,6 +26,20 @@ export const appRedirect = (path: string) => {if (programSettingsRegex.test(path))return path.replace(programSettingsRegex, "/programs/$1/settings/rewards");+ // Redirect "programs/[programId]/settings/branding" to "programs/[programId]/branding/design"+ const programSettingsBrandingRegex =+ /\/programs\/([^\/]+)\/settings\/branding$/;+ if (programSettingsBrandingRegex.test(path))+ return path.replace(+ programSettingsBrandingRegex,+ "/programs/$1/branding/design",+ );++ // Redirect "programs/[programId]/branding" to "programs/[programId]/branding/design" (first tab)+ const programBrandingRegex = /\/programs\/([^\/]+)\/branding$/;+ if (programBrandingRegex.test(path))+ return path.replace(programBrandingRegex, "/programs/$1/branding/design");+// Redirect "/[slug]/programs/[programId]/sales" to "/[slug]/programs/[programId]/commissions"const salesRegex = /^\/([^\/]+)\/programs\/([^\/]+)\/sales$/;if (salesRegex.test(path))diff --git a/apps/web/lib/swr/use-program.ts b/apps/web/lib/swr/use-program.tsindex ba9cdcdf25..4680aa6dcd 100644--- a/apps/web/lib/swr/use-program.ts+++ b/apps/web/lib/swr/use-program.ts@@ -4,7 +4,11 @@ import useSWR from "swr";import { ProgramProps } from "../types";import useWorkspace from "./use-workspace";-export default function useProgram() {+export default function useProgram<T = ProgramProps>({+ query,+}: {+ query?: Record<string, any>;+} = {}) {const { id: workspaceId } = useWorkspace();const { programId } = useParams();@@ -12,10 +16,10 @@ export default function useProgram() {data: program,error,mutate,- } = useSWR<ProgramProps>(+ } = useSWR<T>(programId &&workspaceId &&- `/api/programs/${programId}?workspaceId=${workspaceId}`,+ `/api/programs/${programId}?${new URLSearchParams({ workspaceId, ...query }).toString()}`,fetcher,{dedupingInterval: 60000,diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex 927988f0ac..bf57158228 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -61,6 +61,7 @@ import {ProgramMetricsSchema,ProgramPartnerLinkSchema,ProgramSchema,+ ProgramWithLanderDataSchema,} from "./zod/schemas/programs";import { RewardSchema } from "./zod/schemas/rewards";import {@@ -402,6 +403,10 @@ export type DiscountProps = z.infer<typeof DiscountSchema>;export type ProgramProps = z.infer<typeof ProgramSchema>;+export type ProgramWithLanderDataProps = z.infer<+ typeof ProgramWithLanderDataSchema+>;+export type ProgramInviteProps = z.infer<typeof ProgramInviteSchema>;export type PartnerProgramInviteProps = z.infer<diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.tsindex 82ab8cabad..9701756e02 100644--- a/apps/web/lib/zod/schemas/programs.ts+++ b/apps/web/lib/zod/schemas/programs.ts@@ -7,6 +7,7 @@ import { LinkStructure, ProgramEnrollmentStatus } from "@dub/prisma/client";import { z } from "zod";import { DiscountSchema } from "./discount";import { LinkSchema } from "./links";+import { programLanderSchema } from "./program-lander";import { RewardSchema } from "./rewards";import { parseDateSchema } from "./utils";@@ -42,6 +43,10 @@ export const ProgramSchema = z.object({termsUrl: z.string().nullish(),});+export const ProgramWithLanderDataSchema = ProgramSchema.extend({+ landerData: programLanderSchema.nullish(),+});+export const updateProgramSchema = z.object({name: z.string(),cookieLength: z.number().min(1).max(180),@@ -103,6 +108,10 @@ export const ProgramInviteSchema = z.object({createdAt: z.date(),});+export const getProgramQuerySchema = z.object({+ includeLanderData: z.coerce.boolean().optional(),+});+export const getProgramMetricsQuerySchema = z.object({interval: z.enum(DATE_RANGE_INTERVAL_PRESETS)diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsxindex 0f35546b6d..a2979520c6 100644--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx@@ -102,8 +102,8 @@ const NAV_AREAS: SidebarNavAreas<{href: `/${slug}/programs/${defaultProgramId}/payouts?status=pending`,},{- name: "Resources",- href: `/${slug}/programs/${defaultProgramId}/resources`,+ name: "Branding",+ href: `/${slug}/programs/${defaultProgramId}/branding`,},{name: "Configuration",diff --git a/apps/web/ui/partners/design/preview-window.tsx b/apps/web/ui/partners/design/preview-window.tsxnew file mode 100644index 0000000000..c11857d1cf--- /dev/null+++ b/apps/web/ui/partners/design/preview-window.tsx@@ -0,0 +1,65 @@+import { buttonVariants, Copy, useCopyToClipboard } from "@dub/ui";+import { cn, getPrettyUrl } from "@dub/utils";+import { ArrowUpRight } from "lucide-react";+import Link from "next/link";+import { PropsWithChildren, RefObject } from "react";+import { toast } from "sonner";++export function PreviewWindow({+ url,+ scrollRef,+ children,+}: PropsWithChildren<{ url: string; scrollRef?: RefObject<HTMLDivElement> }>) {+ const [_, copyToClipboard] = useCopyToClipboard();++ return (+ <div className="flex size-full flex-col overflow-hidden rounded-t-xl border-x border-t border-neutral-200 bg-white shadow-md">+ <div className="flex items-center justify-between border-b border-neutral-200 px-4 py-2.5">+ <div className="flex grow basis-0 items-center gap-2">+ {[...Array(3)].map((_, idx) => (+ <div+ key={idx}+ className="size-2 rounded-full border border-neutral-300 bg-neutral-200"+ />+ ))}+ </div>+ <button+ type="button"+ onClick={() =>+ copyToClipboard(url, {+ onSuccess: () => {+ toast.success("Copied to clipboard");+ },+ })+ }+ className="group flex min-w-0 max-w-xs grow items-center justify-center rounded-lg bg-neutral-100 px-4 py-1.5"+ >+ <div className="relative">+ <span className="text-content-emphasis block truncate text-xs font-medium">+ {getPrettyUrl(url)}+ </span>+ <div className="absolute inset-y-0 left-full ml-1 flex translate-y-0.5 items-center opacity-0 transition-[opacity,transform] duration-100 group-hover:translate-y-0 group-hover:opacity-100">+ <Copy className="size-3" />+ </div>+ </div>+ </button>+ <div className="flex grow basis-0 justify-end">+ <Link+ href={url}+ target="_blank"+ className={cn(+ buttonVariants({ variant: "secondary" }),+ "flex h-7 w-fit items-center gap-1 rounded-md border px-2 text-sm",+ )}+ >+ View+ <ArrowUpRight className="size-3" />+ </Link>+ </div>+ </div>+ <div className="scrollbar-hide grow overflow-y-auto" ref={scrollRef}>+ {children}+ </div>+ </div>+ );+}diff --git a/apps/web/ui/partners/lander-hero.tsx b/apps/web/ui/partners/lander-hero.tsxnew file mode 100644index 0000000000..fea8f366b3--- /dev/null+++ b/apps/web/ui/partners/lander-hero.tsx@@ -0,0 +1,43 @@+import { cn } from "@dub/utils";+import { Program } from "@prisma/client";++export function LanderHero({+ program,+ preview,+}: {+ program: Pick<Program, "name">;+ preview?: boolean;+}) {+ const Heading = preview ? "div" : "h1";++ return (+ <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>+ <Heading+ 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+ </Heading>+ <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>+ </div>+ );+}diff --git a/apps/web/ui/partners/lander-rewards.tsx b/apps/web/ui/partners/lander-rewards.tsxnew file mode 100644index 0000000000..13499e33d6--- /dev/null+++ b/apps/web/ui/partners/lander-rewards.tsx@@ -0,0 +1,19 @@+import { DiscountProps, RewardProps } from "@/lib/types";+import { ProgramRewardList } from "./program-reward-list";++export function LanderRewards({+ program,+}: {+ program: { rewards: RewardProps[]; defaultDiscount: DiscountProps | null };+}) {+ return (+ <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>+ );+}diff --git a/packages/ui/src/hooks/use-scroll.ts b/packages/ui/src/hooks/use-scroll.tsindex 058409582f..7b4aabbbfd 100644--- a/packages/ui/src/hooks/use-scroll.ts+++ b/packages/ui/src/hooks/use-scroll.ts@@ -1,15 +1,22 @@-import { useCallback, useEffect, useState } from "react";+import { RefObject, useCallback, useEffect, useState } from "react";-export function useScroll(threshold: number) {+export function useScroll(+ threshold: number,+ { container }: { container?: RefObject<HTMLElement> } = {},+) {const [scrolled, setScrolled] = useState(false);const onScroll = useCallback(() => {- setScrolled(window.scrollY > threshold);+ setScrolled(+ (container?.current ? container.current.scrollTop : window.scrollY) >+ threshold,+ );}, [threshold]);useEffect(() => {- window.addEventListener("scroll", onScroll);- return () => window.removeEventListener("scroll", onScroll);+ const element = container?.current ?? window;+ element.addEventListener("scroll", onScroll);+ return () => element.removeEventListener("scroll", onScroll);}, [onScroll]);// also check on first load