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.

WIP featured programs

Tim Wilsonca88ab38ef2c
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/featured-programs.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/featured-programs.tsx
new file mode 100644
index 0000000000..53017c66fb
--- /dev/null
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/featured-programs.tsx
@@ -0,0 +1,32 @@
+import { NetworkProgramProps } from "@/lib/types";
+import { fetcher } from "@dub/utils";
+import useSWR from "swr";
+import { FeaturedProgramCard } from "./program-card";
+
+export function FeaturedPrograms() {
+ const { data: programs, error } = useSWR<NetworkProgramProps[]>(
+ `/api/network/programs?featured=true`,
+ fetcher,
+ { revalidateOnFocus: false, keepPreviousData: true },
+ );
+
+ return programs?.length === 0 ? null : (
+ <div>
+ <h2 className="text-content-emphasis text-base font-semibold">
+ Featured programs
+ </h2>
+ <div className="@3xl/page:grid-cols-2 mt-4 grid grid-cols-1 gap-4">
+ {programs ? (
+ programs.map((program) => (
+ <FeaturedProgramCard key={program.id} program={program} />
+ ))
+ ) : (
+ <>
+ <FeaturedProgramCard />
+ <FeaturedProgramCard />
+ </>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/page-client.tsx
index 38586c9d77..1560ade454 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/page-client.tsx
@@ -13,24 +13,25 @@ import {
} from "@dub/ui";
import { cn, fetcher } from "@dub/utils";
import useSWR from "swr";
+import { FeaturedPrograms } from "./featured-programs";
import { MarketplaceEmptyState } from "./marketplace-empty-state";
-import { FeaturedProgramCard, ProgramCard } from "./program-card";
+import { ProgramCard } from "./program-card";
import ProgramSort from "./program-sort";
import { useProgramNetworkFilters } from "./use-program-network-filters";
export function ProgramMarketplacePageClient() {
const { getQueryString } = useRouterStuff();
- const { data: programsCount, error: countError } = useNetworkProgramsCount();
+ const { data: programsCount, error: countError } = useNetworkProgramsCount(
+ {},
+ );
const {
data: programs,
error,
isValidating,
} = useSWR<NetworkProgramProps[]>(
- `/api/network/programs${getQueryString({
- //
- })}`,
+ `/api/network/programs${getQueryString()}`,
fetcher,
{ revalidateOnFocus: false, keepPreviousData: true },
);
@@ -50,15 +51,7 @@ export function ProgramMarketplacePageClient() {
return (
<div className="flex flex-col gap-6">
- <div>
- <h2 className="text-content-emphasis text-base font-semibold">
- Featured programs
- </h2>
- <div className="@3xl/page:grid-cols-2 mt-4 grid grid-cols-1 gap-4">
- <FeaturedProgramCard program={programs?.[0]} />
- <FeaturedProgramCard program={programs?.[1]} />
- </div>
- </div>
+ <FeaturedPrograms />
<div>
<div className="xs:flex-row xs:items-center flex flex-col justify-between gap-4">
<div className="flex items-center gap-2">
@@ -97,17 +90,19 @@ export function ProgramMarketplacePageClient() {
</div>
) : !programs || programs?.length ? (
<div>
- <div
- className={cn(
- "@4xl/page:grid-cols-3 @xl/page:grid-cols-2 grid min-h-[500px] grid-cols-1 items-start gap-4 transition-opacity lg:gap-6",
- isValidating && "opacity-50",
- )}
- >
- {programs
- ? programs?.map((program) => (
- <ProgramCard key={program.id} program={program} />
- ))
- : [...Array(5)].map((_, idx) => <ProgramCard key={idx} />)}
+ <div className="min-h-[300px]">
+ <div
+ className={cn(
+ "@4xl/page:grid-cols-3 @xl/page:grid-cols-2 grid grid-cols-1 gap-4 transition-opacity lg:gap-6",
+ isValidating && "opacity-50",
+ )}
+ >
+ {programs
+ ? programs?.map((program) => (
+ <ProgramCard key={program.id} program={program} />
+ ))
+ : [...Array(5)].map((_, idx) => <ProgramCard key={idx} />)}
+ </div>
</div>
<div className="sticky bottom-0 mt-4 rounded-b-[inherit] border-t border-neutral-200 bg-white px-3.5 py-2">
<PaginationControls
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/program-card.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/program-card.tsx
index 6ef5a994d5..b4b43d2cf3 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/program-card.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/marketplace/program-card.tsx
@@ -52,138 +52,139 @@ export function ProgramCard({ program }: { program?: NetworkProgramProps }) {
return (
<div
- className={cn(program?.id && "cursor-pointer hover:drop-shadow-sm")}
+ className={cn(
+ program?.id &&
+ "border-border-subtle cursor-pointer rounded-xl border bg-white p-6 hover:drop-shadow-sm",
+ )}
{...getClickHandlers(url, router)}
>
- <div className="border-border-subtle rounded-xl border bg-white p-6">
- <div className="flex justify-between gap-4">
- {program ? (
- <img
- src={program.logo || `${OG_AVATAR_URL}${program.name}`}
- alt={program.name}
- className="size-12 rounded-full"
- />
- ) : (
- <div className="size-12 animate-pulse rounded-full bg-neutral-200" />
- )}
+ <div className="flex justify-between gap-4">
+ {program ? (
+ <img
+ src={program.logo || `${OG_AVATAR_URL}${program.name}`}
+ alt={program.name}
+ className="size-12 rounded-full"
+ />
+ ) : (
+ <div className="size-12 animate-pulse rounded-full bg-neutral-200" />
+ )}
- {statusBadge && (
- <StatusBadge {...statusBadge} className="px-1.5 py-0.5">
- {statusBadge.label}
- </StatusBadge>
- )}
- </div>
+ {statusBadge && (
+ <StatusBadge {...statusBadge} className="px-1.5 py-0.5">
+ {statusBadge.label}
+ </StatusBadge>
+ )}
+ </div>
- <div className="mt-4 flex flex-col">
- {/* Name */}
+ <div className="mt-4 flex flex-col">
+ {/* Name */}
+ {program ? (
+ <span className="text-content-emphasis text-base font-semibold">
+ {program.name}
+ </span>
+ ) : (
+ <div className="h-6 w-32 animate-pulse rounded bg-neutral-200" />
+ )}
+
+ <div className="text-content-default mt-1 flex items-center gap-1">
+ <Link4 className="size-3.5" />
+ {/* Domain */}
{program ? (
- <span className="text-content-emphasis text-base font-semibold">
- {program.name}
- </span>
+ <a
+ href={program.url || `https://${program.domain}`}
+ target="_blank"
+ rel="noreferrer noopener"
+ className="text-sm font-medium"
+ >
+ {getPrettyUrl(program.url) || program.domain}
+ </a>
) : (
- <div className="h-6 w-32 animate-pulse rounded bg-neutral-200" />
+ <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
)}
+ </div>
- <div className="text-content-default mt-1 flex items-center gap-1">
- <Link4 className="size-3.5" />
- {/* Domain */}
- {program ? (
- <a
- href={program.url || `https://${program.domain}`}
- target="_blank"
- rel="noreferrer noopener"
- className="text-sm font-medium"
- >
- {getPrettyUrl(program.url) || program.domain}
- </a>
- ) : (
- <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
- )}
- </div>
-
- <div className="mt-4 flex gap-8">
- {program ? (
- <>
- {Boolean(program?.rewards?.length || program?.discount) && (
- <div>
- <span className="text-content-muted block text-xs font-medium">
- Rewards
- </span>
- <div className="mt-1 flex items-center gap-1.5">
- {program.rewards?.map((reward) => (
- <RewardOrDiscountIcon
- key={reward.id}
- icon={REWARD_EVENTS[reward.event].icon}
- description={formatRewardDescription({ reward })}
- onClick={() =>
- queryParams({
- set: {
- rewardType: reward.event,
- },
- del: "page",
- })
- }
- />
- ))}
- {program.discount && (
- <RewardOrDiscountIcon
- icon={Gift}
- description={formatDiscountDescription({
- discount: program.discount,
- })}
- onClick={() =>
- queryParams({
- set: {
- rewardType: "discount",
- },
- del: "page",
- })
- }
- />
- )}
- </div>
+ <div className="mt-4 flex gap-8">
+ {program ? (
+ <>
+ {Boolean(program?.rewards?.length || program?.discount) && (
+ <div>
+ <span className="text-content-muted block text-xs font-medium">
+ Rewards
+ </span>
+ <div className="mt-1 flex items-center gap-1.5">
+ {program.rewards?.map((reward) => (
+ <RewardOrDiscountIcon
+ key={reward.id}
+ icon={REWARD_EVENTS[reward.event].icon}
+ description={formatRewardDescription({ reward })}
+ onClick={() =>
+ queryParams({
+ set: {
+ rewardType: reward.event,
+ },
+ del: "page",
+ })
+ }
+ />
+ ))}
+ {program.discount && (
+ <RewardOrDiscountIcon
+ icon={Gift}
+ description={formatDiscountDescription({
+ discount: program.discount,
+ })}
+ onClick={() =>
+ queryParams({
+ set: {
+ rewardType: "discount",
+ },
+ del: "page",
+ })
+ }
+ />
+ )}
</div>
- )}
- {Boolean(program?.categories?.length) && (
- <div className="min-w-0">
- <span className="text-content-muted block text-xs font-medium">
- Industry
- </span>
- <div className="mt-1 flex items-center gap-1.5">
- {program.categories
- .slice(0, 1)
- ?.map((category) => (
- <CategoryButton key={category} category={category} />
- ))}
- {program.categories.length > 1 && (
- <Tooltip
- content={
- <div className="flex flex-col gap-0.5 p-2">
- {program.categories.slice(1).map((category) => (
- <CategoryButton
- key={category}
- category={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>
+ )}
+ {Boolean(program?.categories?.length) && (
+ <div className="min-w-0">
+ <span className="text-content-muted block text-xs font-medium">
+ Industry
+ </span>
+ <div className="mt-1 flex items-center gap-1.5">
+ {program.categories
+ .slice(0, 1)
+ ?.map((category) => (
+ <CategoryButton key={category} category={category} />
+ ))}
+ {program.categories.length > 1 && (
+ <Tooltip
+ content={
+ <div className="flex flex-col gap-0.5 p-2">
+ {program.categories.slice(1).map((category) => (
+ <CategoryButton
+ key={category}
+ category={category}
+ />
+ ))}
</div>
- </Tooltip>
- )}
- </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 className="h-3.5 w-12 animate-pulse rounded bg-neutral-200" />
- <div className="mt-1 h-6 w-24 animate-pulse rounded bg-neutral-200" />
- </div>
- )}
- </div>
+ </div>
+ )}
+ </>
+ ) : (
+ <div>
+ <div className="h-3.5 w-12 animate-pulse rounded bg-neutral-200" />
+ <div className="mt-1 h-6 w-24 animate-pulse rounded bg-neutral-200" />
+ </div>
+ )}
</div>
</div>
</div>
@@ -213,11 +214,14 @@ export function FeaturedProgramCard({
{...getClickHandlers(url, router)}
>
{program?.marketplaceHeaderImage && (
- <img
- src={program.marketplaceHeaderImage}
- alt=""
- className="absolute inset-0 size-full object-cover opacity-80"
- />
+ <>
+ <img
+ src={program.marketplaceHeaderImage}
+ alt=""
+ className="absolute inset-0 size-full object-cover opacity-80"
+ />
+ <div className="absolute inset-0 backdrop-blur-sm [mask-image:linear-gradient(transparent_10%,black)]" />
+ </>
)}
<div className="relative">
@@ -239,7 +243,7 @@ export function FeaturedProgramCard({
)}
</div>
- <div className="mt-4 flex flex-col">
+ <div className="mt-10 flex flex-col">
{/* Name */}
{program ? (
<span className="text-content-inverted text-3xl font-semibold">
@@ -250,23 +254,25 @@ export function FeaturedProgramCard({
)}
<div className="text-content-inverted mt-1 flex items-center gap-1">
- <Link4 className="size-3.5" />
- {/* Domain */}
+ {/* URL/domain */}
{program ? (
- <a
- href={program.url || `https://${program.domain}`}
- target="_blank"
- rel="noreferrer noopener"
- className="text-sm font-medium"
- >
- {getPrettyUrl(program.url) || program.domain}
- </a>
+ <>
+ <Link4 className="size-3.5" />
+ <a
+ href={program.url || `https://${program.domain}`}
+ target="_blank"
+ rel="noreferrer noopener"
+ className="text-sm font-medium"
+ >
+ {getPrettyUrl(program.url) || program.domain}
+ </a>
+ </>
) : (
- <div className="h-4 w-24 animate-pulse rounded bg-neutral-200" />
+ <div className="h-5 w-24 animate-pulse rounded bg-neutral-200" />
)}
</div>
- <div className="mt-4 flex gap-8">
+ <div className="mt-5 flex gap-8">
{program ? (
<>
{Boolean(program?.rewards?.length || program?.discount) && (
@@ -274,7 +280,7 @@ export function FeaturedProgramCard({
<span className="text-content-muted block text-xs font-medium">
Rewards
</span>
- <div className="mt-1 flex items-center gap-1.5">
+ <div className="mt-2 flex items-center gap-1.5">
{program.rewards?.map((reward) => (
<RewardOrDiscountIcon
key={reward.id}
@@ -288,6 +294,7 @@ export function FeaturedProgramCard({
del: "page",
})
}
+ className="text-content-inverted hover:bg-bg-default/10 active:bg-bg-default/20"
/>
))}
{program.discount && (
@@ -304,6 +311,7 @@ export function FeaturedProgramCard({
del: "page",
})
}
+ className="text-content-inverted hover:bg-bg-default/10 active:bg-bg-default/20"
/>
)}
</div>
@@ -314,11 +322,15 @@ export function FeaturedProgramCard({
<span className="text-content-muted block text-xs font-medium">
Industry
</span>
- <div className="mt-1 flex items-center gap-1.5">
+ <div className="mt-2 flex items-center gap-1.5">
{program.categories
.slice(0, 1)
?.map((category) => (
- <CategoryButton key={category} category={category} />
+ <CategoryButton
+ key={category}
+ category={category}
+ className="text-content-inverted hover:bg-bg-default/10 active:bg-bg-default/20"
+ />
))}
{program.categories.length > 1 && (
<Tooltip
@@ -333,7 +345,7 @@ export function FeaturedProgramCard({
</div>
}
>
- <div className="text-content-subtle -ml-1.5 flex size-6 items-center justify-center rounded-md text-xs font-medium">
+ <div className="text-content-inverted/70 -ml-1.5 flex size-6 items-center justify-center rounded-md text-xs font-medium">
+{program.categories.length - 1}
</div>
</Tooltip>
@@ -344,8 +356,8 @@ export function FeaturedProgramCard({
</>
) : (
<div>
- <div className="h-3.5 w-12 animate-pulse rounded bg-neutral-200" />
- <div className="mt-1 h-6 w-24 animate-pulse rounded bg-neutral-200" />
+ <div className="h-4 w-12 animate-pulse rounded bg-neutral-200" />
+ <div className="mt-2 h-6 w-24 animate-pulse rounded bg-neutral-200" />
</div>
)}
</div>
@@ -359,10 +371,12 @@ const RewardOrDiscountIcon = ({
icon: Icon,
description,
onClick,
+ className,
}: {
icon: Icon;
description: string;
onClick: () => void;
+ className?: string;
}) => (
<HoverCard.Root openDelay={100}>
<HoverCard.Portal>
@@ -379,15 +393,24 @@ const RewardOrDiscountIcon = ({
<button
type="button"
onClick={onClick}
- className="hover:bg-bg-subtle active:bg-bg-emphasis flex size-6 items-center justify-center rounded-md"
+ className={cn(
+ "hover:bg-bg-subtle active:bg-bg-emphasis text-content-default flex size-6 items-center justify-center rounded-md",
+ className,
+ )}
>
- <Icon className="text-content-default size-4" />
+ <Icon className="size-4" />
</button>
</HoverCard.Trigger>
</HoverCard.Root>
);
-const CategoryButton = ({ category }: { category: Category }) => {
+const CategoryButton = ({
+ category,
+ className,
+}: {
+ category: Category;
+ className?: string;
+}) => {
const { queryParams } = useRouterStuff();
const categoryData = categoriesMap[category];
const { icon: Icon, label } = categoryData ?? {
@@ -406,7 +429,10 @@ const CategoryButton = ({ category }: { category: Category }) => {
del: "page",
})
}
- className="hover:bg-bg-subtle text-content-default active:bg-bg-emphasis flex h-6 min-w-0 items-center gap-1 rounded-md px-1"
+ className={cn(
+ "hover:bg-bg-subtle text-content-default active:bg-bg-emphasis flex h-6 min-w-0 items-center gap-1 rounded-md px-1",
+ className,
+ )}
>
<Icon className="size-4" />
<span className="min-w-0 truncate text-sm font-medium">{label}</span>
diff --git a/apps/web/lib/zod/schemas/program-network.ts b/apps/web/lib/zod/schemas/program-network.ts
index b3ee05c2a8..b456bf30fb 100644
--- a/apps/web/lib/zod/schemas/program-network.ts
+++ b/apps/web/lib/zod/schemas/program-network.ts
@@ -40,7 +40,7 @@ export const getNetworkProgramsQuerySchema = z
(v) => (v === "null" ? null : v),
z.nativeEnum(ProgramEnrollmentStatus).nullish(),
),
- featured: z.boolean().optional(),
+ featured: z.coerce.boolean().optional(),
search: z.string().optional(),
sortBy: z.enum(["name", "createdAt", "popularity"]).default("popularity"),
sortOrder: z.enum(["asc", "desc"]).default("desc"),