The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
show one marketplace reward with a count badge
Pedro Ladeira4fbdbfde52f3
diff --git a/apps/web/ui/program-marketplace/featured-program-card.tsx b/apps/web/ui/program-marketplace/featured-program-card.tsxindex 1b7d065918..3eebd5f1ed 100644--- a/apps/web/ui/program-marketplace/featured-program-card.tsx+++ b/apps/web/ui/program-marketplace/featured-program-card.tsx@@ -1,14 +1,9 @@import { NetworkProgramProps } from "@/lib/types";import {- ProgramCategory,- programCategorySurfaceClassName,-} from "@/ui/program-marketplace/program-category";-import { ProgramRewardsDisplay } from "@/ui/program-marketplace/program-rewards-display";-import {- getMarketplaceAllHref,- getMarketplaceCategoryHref,-} from "@/ui/program-marketplace/utils/urls";-import { Tooltip } from "@dub/ui";+ MarketplaceRewardsLabel,+ ProgramRewardsDisplay,+} from "@/ui/program-marketplace/program-rewards-display";+import { getMarketplaceAllHref } from "@/ui/program-marketplace/utils/urls";import { ArrowUpRight, Globe } from "@dub/ui/icons";import { OG_AVATAR_URL, getDomainWithoutWWW } from "@dub/utils";import Link from "next/link";@@ -47,6 +42,7 @@ export function FeaturedProgramCard({colorIndex?: number;}) {const router = useRouter();+ const rewards = program.rewards;// Derive the tint from the program's image// Fall back to the palette if extraction is blocked@@ -93,69 +89,23 @@ export function FeaturedProgramCard({</div><div className="pointer-events-auto relative z-30 mt-5 flex flex-wrap gap-x-8 gap-y-4">- {Boolean(program.rewards?.length) && (- <div>- <span className="block text-xs font-medium text-neutral-400">- Rewards- </span>+ {rewards?.length ? (+ <div className="min-w-0">+ <MarketplaceRewardsLabel+ count={rewards.length}+ className="text-xs font-medium text-neutral-400"+ /><ProgramRewardsDisplay- iconsOnly- rewards={program.rewards}+ rewards={rewards}onRewardClick={(reward) =>router.push(getMarketplaceAllHref({ rewardType: reward.event }),)}className="mt-2 min-h-6"- iconClassName="text-neutral-900"/></div>- )}- {Boolean(program.categories.length) && (- <div className="min-w-0">- <span className="block text-xs font-medium text-neutral-400">- Category- </span>- <div className="mt-2 flex min-h-6 items-center gap-1.5">- {program.categories- .slice(0, 1)- ?.map((category) => (- <ProgramCategory- key={category}- category={category}- variant="surface"- onClick={() =>- router.push(getMarketplaceCategoryHref(category))- }- />- ))}- {program.categories.length > 1 && (- <Tooltip- content={- <div className="flex flex-col gap-1 p-1">- {program.categories.slice(1).map((category) => (- <ProgramCategory- key={category}- category={category}- variant="surface"- onClick={() =>- router.push(- getMarketplaceCategoryHref(category),- )- }- />- ))}- </div>- }- >- <div className={programCategorySurfaceClassName}>- +{program.categories.length - 1}- </div>- </Tooltip>- )}- </div>- </div>- )}+ ) : null}{program.url && (<div className="basis-full sm:basis-auto"><span className="block text-xs font-medium text-neutral-400">@@ -216,14 +166,7 @@ export function FeaturedProgramCardSkeleton() {<div className="mt-5 flex flex-wrap gap-x-8 gap-y-4"><div><div className="h-4 w-12 animate-pulse rounded bg-neutral-200" />- <div className="mt-2 flex gap-1.5">- <div className="size-4 animate-pulse rounded bg-neutral-200" />- <div className="size-4 animate-pulse rounded bg-neutral-200" />- </div>- </div>- <div>- <div className="h-4 w-14 animate-pulse rounded bg-neutral-200" />- <div className="mt-2 h-5 w-24 animate-pulse rounded-full bg-neutral-200" />+ <div className="mt-2 h-5 w-40 animate-pulse rounded bg-neutral-200" /></div><div className="basis-full sm:basis-auto"><div className="h-4 w-12 animate-pulse rounded bg-neutral-200" />diff --git a/apps/web/ui/program-marketplace/program-card.tsx b/apps/web/ui/program-marketplace/program-card.tsxindex 748b7933b0..d46aed651f 100644--- a/apps/web/ui/program-marketplace/program-card.tsx+++ b/apps/web/ui/program-marketplace/program-card.tsx@@ -1,13 +1,11 @@"use client";import { NetworkProgramProps } from "@/lib/types";-import { ProgramCategory } from "@/ui/program-marketplace/program-category";-import { ProgramRewardsDisplay } from "@/ui/program-marketplace/program-rewards-display";import {- getMarketplaceAllHref,- getMarketplaceCategoryHref,-} from "@/ui/program-marketplace/utils/urls";-import { Tooltip } from "@dub/ui";+ MarketplaceRewardsLabel,+ ProgramRewardsDisplay,+} from "@/ui/program-marketplace/program-rewards-display";+import { getMarketplaceAllHref } from "@/ui/program-marketplace/utils/urls";import { OG_AVATAR_URL, cn } from "@dub/utils";import Link from "next/link";import { useRouter } from "next/navigation";@@ -23,6 +21,7 @@ export function MarketplaceProgramCard({className?: string;}) {const router = useRouter();+ const rewards = program.rewards;return (<Link@@ -52,72 +51,21 @@ export function MarketplaceProgramCard({`${program.name} is a program in the Dub Partner Network. Join the network to start partnering with them.`}</div>- <div className="mt-5 flex gap-4">- {Boolean(program.rewards?.length) && (- <div>- <span className="text-content-muted block text-xs font-medium">- Rewards- </span>- <ProgramRewardsDisplay- rewards={program.rewards}- onRewardClick={(reward) =>- router.push(- getMarketplaceAllHref({ rewardType: reward.event }),- )- }- className="mt-2"- {...(externalMarketplace- ? { descriptionClassName: "sm:max-w-[200px]" }- : {})}- />- </div>- )}- {Boolean(program.categories.length) &&- // hide categories for external marketplace (narrow max width)- !externalMarketplace && (- <div className="hidden min-w-0 sm:block">- <span className="text-content-muted block text-xs font-medium">- Category- </span>- <div className="mt-2 flex items-center gap-1.5">- {program.categories- .slice(0, 1)- ?.map((category) => (- <ProgramCategory- key={category}- category={category}- onClick={() =>- router.push(getMarketplaceCategoryHref(category))- }- />- ))}- {program.categories.length > 1 && (- <Tooltip- content={- <div className="flex flex-col gap-0.5 p-2">- {program.categories.slice(1).map((category) => (- <ProgramCategory- key={category}- category={category}- onClick={() =>- router.push(- getMarketplaceCategoryHref(category),- )- }- />- ))}- </div>- }- >- <div className="text-content-subtle -ml-1.5 flex size-6 items-center justify-center rounded-md text-xs font-medium">- +{program.categories.length - 1}- </div>- </Tooltip>- )}- </div>- </div>- )}- </div>+ {rewards?.length ? (+ <div className="mt-5 min-w-0">+ <MarketplaceRewardsLabel+ count={rewards.length}+ className="text-content-muted text-xs font-medium"+ />+ <ProgramRewardsDisplay+ rewards={rewards}+ onRewardClick={(reward) =>+ router.push(getMarketplaceAllHref({ rewardType: reward.event }))+ }+ className="mt-2"+ />+ </div>+ ) : null}</div></Link>);@@ -149,7 +97,7 @@ export function MarketplaceProgramCardSkeleton({<div className="h-4 w-3/4 animate-pulse rounded bg-neutral-200" /></div>- {/* Rewards/Category section - matches actual card structure */}+ {/* Rewards section - matches actual card structure */}<div className="mt-4 flex gap-4"><div><div className="h-3.5 w-12 animate-pulse rounded bg-neutral-200" />diff --git a/apps/web/ui/program-marketplace/program-rewards-display.tsx b/apps/web/ui/program-marketplace/program-rewards-display.tsxindex f0cc30266f..d334d567be 100644--- a/apps/web/ui/program-marketplace/program-rewards-display.tsx+++ b/apps/web/ui/program-marketplace/program-rewards-display.tsx@@ -4,25 +4,41 @@ import { formatRewardDescription } from "@/ui/partners/format-reward-descriptionimport { REWARD_EVENT_ICON } from "@/ui/partners/rewards/reward-event-icon";import { Gift, Icon } from "@dub/ui";import { cn } from "@dub/utils";-import * as HoverCard from "@radix-ui/react-hover-card";-import { ProgramRewardIcon } from "./program-reward-icon";type RewardItem = {id: string;+ event: RewardProps["event"] | "discount";icon: Icon;description: string;onClick?: () => void;};+export function MarketplaceRewardsLabel({+ count,+ className,+}: {+ count: number;+ className?: string;+}) {+ return (+ <span className={cn("flex items-center gap-1", className)}>+ Rewards+ {count > 1 ? (+ <span className="flex h-4 min-w-4 items-center justify-center rounded-md bg-[#EDEDED] px-1 text-xs font-semibold leading-4 tracking-[-0.02em] text-[#404040]">+ {count}+ </span>+ ) : null}+ </span>+ );+}+interface ProgramRewardsDisplayProps {rewards?: RewardProps[] | null;discount?: DiscountProps | null;isDarkImage?: boolean;- iconsOnly?: boolean;className?: string;onRewardClick?: (reward: RewardProps) => void;onDiscountClick?: (discount: DiscountProps) => void;- iconClassName?: string;descriptionClassName?: string;}@@ -30,21 +46,18 @@ export function ProgramRewardsDisplay({rewards,discount,isDarkImage = false,- iconsOnly = false,className,onRewardClick,onDiscountClick,- iconClassName,descriptionClassName,}: ProgramRewardsDisplayProps) {- // Concatenate rewards and discount into a single arrayconst items: RewardItem[] = [];- // Add rewardsif (rewards) {rewards.forEach((reward) => {items.push({id: reward.id,+ event: reward.event,icon: REWARD_EVENT_ICON[reward.event],description: formatRewardDescription(reward, {includeEarnPrefix: false,@@ -54,104 +67,79 @@ export function ProgramRewardsDisplay({});}- // Add discount if presentif (discount) {items.push({id: "discount",+ event: "discount",icon: Gift,description: formatDiscountDescription(discount),onClick: onDiscountClick ? () => onDiscountClick(discount) : undefined,});}- // shouldn't happen, but just in caseif (items.length === 0) return null;- if (iconsOnly) {- return (- <div className={cn("flex min-h-6 items-center gap-1.5", className)}>- {items.map((item) => (- <ProgramRewardIcon- key={item.id}- icon={item.icon}- description={item.description}- onClick={item.onClick}- className={cn(isDarkImage && "text-content-inverted")}- iconClassName={cn("text-neutral-600", iconClassName)}- />- ))}- </div>- );- }-- // If there's only one item, show the full description- if (items.length === 1) {- const item = items[0];- const As = item.onClick ? "button" : "div";- return (- <HoverCard.Root openDelay={100}>- <HoverCard.Portal>- <HoverCard.Content- side="bottom"- sideOffset={8}- className="animate-slide-up-fade z-[99] flex items-center gap-2 overflow-hidden rounded-xl border border-neutral-200 bg-white p-2 text-xs text-neutral-700 shadow-sm"- >- <item.icon className="text-content-default size-4" />- <span>{item.description}</span>- </HoverCard.Content>- </HoverCard.Portal>- <HoverCard.Trigger asChild>- <As- {...(item.onClick && {- type: "button",- onClick: (e) => {- e.preventDefault();- e.stopPropagation();- item.onClick?.();- },- })}- className={cn(- "-ml-1 flex items-center gap-1 pr-1",- item.onClick &&- "hover:bg-bg-subtle active:bg-bg-emphasis rounded-md transition-colors",- className,- )}- >- <div- className={cn(- "text-content-default flex size-6 items-center justify-center rounded-md",- isDarkImage && "text-content-inverted",- )}- >- <item.icon className="size-4" />- </div>- <span- className={cn(- "text-content-default max-w-[120px] truncate text-sm font-medium sm:max-w-[160px]",- isDarkImage && "text-content-inverted",- descriptionClassName,- )}- >- {item.description}- </span>- </As>- </HoverCard.Trigger>- </HoverCard.Root>- );- }+ const featuredItem =+ items.find((item) => item.event === "sale") ??+ items.find((item) => item.event === "lead") ??+ items.find((item) => item.event === "click") ??+ items[0];- // If there are multiple items, show icons with tooltipsreturn (- <div className={cn("-ml-1 flex items-center gap-1.5", className)}>- {items.map((item) => (- <ProgramRewardIcon- key={item.id}- icon={item.icon}- description={item.description}- onClick={item.onClick}- className={cn(isDarkImage && "text-content-inverted", iconClassName)}- />- ))}+ <div className={cn("-ml-1 min-w-0", className)}>+ <RewardExpandedItem+ item={featuredItem}+ isDarkImage={isDarkImage}+ descriptionClassName={descriptionClassName}+ /></div>);}++function RewardExpandedItem({+ item,+ isDarkImage,+ descriptionClassName,+}: {+ item: RewardItem;+ isDarkImage: boolean;+ descriptionClassName?: string;+}) {+ const As = item.onClick ? "button" : "div";++ return (+ <As+ {...(item.onClick && {+ type: "button",+ onClick: (e) => {+ e.preventDefault();+ e.stopPropagation();+ item.onClick?.();+ },+ })}+ className={cn(+ "flex min-w-0 items-center gap-1 pr-1",+ item.onClick &&+ "hover:bg-bg-subtle active:bg-bg-emphasis rounded-md transition-colors",+ )}+ >+ <div+ className={cn(+ "text-content-default flex size-6 shrink-0 items-center justify-center rounded-md",+ isDarkImage && "text-content-inverted",+ )}+ >+ <item.icon className="size-4" />+ </div>+ <span+ className={cn(+ "min-w-0 truncate text-sm font-normal leading-5 tracking-[-0.02em] text-black",+ isDarkImage && "text-content-inverted",+ descriptionClassName,+ )}+ >+ {item.description}+ </span>+ </As>+ );+}