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 resources to partners dashboard

Tim Wilson0ae78676e2fe
diff --git a/apps/web/app/api/partner-profile/programs/[programId]/resources/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/resources/route.ts
new file mode 100644
index 0000000000..5c1da1a649
--- /dev/null
+++ b/apps/web/app/api/partner-profile/programs/[programId]/resources/route.ts
@@ -0,0 +1,22 @@
+import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
+import { withPartnerProfile } from "@/lib/auth/partner";
+import { programResourcesSchema } from "@/lib/zod/schemas/program-resources";
+import { NextResponse } from "next/server";
+
+// GET /api/partner-profile/programs/[programId]/resources – get resources for an enrolled program
+export const GET = withPartnerProfile(async ({ partner, params }) => {
+ const { program } = await getProgramEnrollmentOrThrow({
+ partnerId: partner.id,
+ programId: params.programId,
+ });
+
+ const resources = programResourcesSchema.parse(
+ program?.resources ?? {
+ logos: [],
+ colors: [],
+ files: [],
+ },
+ );
+
+ return NextResponse.json(resources);
+});
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-color-modal.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-color-modal.tsx
index d6f5d8b46c..27f11b2f52 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-color-modal.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-color-modal.tsx
@@ -48,7 +48,10 @@ const DEFAULT_COLORS = ["#dc2626", "#84cc16", "#14b8a6", "#0ea5e9", "#d946ef"];
function AddColorModalInner({ setShowAddColorModal }: AddColorModalProps) {
const { programId } = useParams();
const { id: workspaceId } = useWorkspace();
- const { mutate } = useProgramResources();
+ const { mutate } = useProgramResources({
+ workspaceId: workspaceId!,
+ programId: programId as string,
+ });
const [hexInputValue, setHexInputValue] = useState("#000000");
const {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-file-modal.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-file-modal.tsx
index d2555baaf4..dad0b3a708 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-file-modal.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-file-modal.tsx
@@ -46,7 +46,10 @@ function AddFileModal(props: AddFileModalProps) {
function AddFileModalInner({ setShowAddFileModal }: AddFileModalProps) {
const { programId } = useParams();
const { id: workspaceId } = useWorkspace();
- const { mutate } = useProgramResources();
+ const { mutate } = useProgramResources({
+ workspaceId: workspaceId!,
+ programId: programId as string,
+ });
const {
register,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-logo-modal.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-logo-modal.tsx
index b2e437dfe3..3de411b701 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-logo-modal.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/add-logo-modal.tsx
@@ -46,7 +46,10 @@ function AddLogoModal(props: AddLogoModalProps) {
function AddLogoModalInner({ setShowAddLogoModal }: AddLogoModalProps) {
const { programId } = useParams();
const { id: workspaceId } = useWorkspace();
- const { mutate } = useProgramResources();
+ const { mutate } = useProgramResources({
+ workspaceId: workspaceId!,
+ programId: programId as string,
+ });
const {
register,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/page-client.tsx
index 719fa66818..616b21b501 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/resources/page-client.tsx
@@ -4,20 +4,12 @@ import { deleteProgramResourceAction } from "@/lib/actions/partners/program-reso
import useProgramResources from "@/lib/swr/use-program-resources";
import useWorkspace from "@/lib/swr/use-workspace";
import { ProgramResourceType } from "@/lib/zod/schemas/program-resources";
-import { ThreeDots } from "@/ui/shared/icons";
-import {
- AnimatedSizeContainer,
- Button,
- Download,
- FileContent,
- LoadingSpinner,
- Popover,
- Trash,
-} from "@dub/ui";
-import { capitalize, cn, formatFileSize } from "@dub/utils";
+import { ResourceCard } from "@/ui/partners/resources/resource-card";
+import { ResourceSection } from "@/ui/partners/resources/resource-section";
+import { FileContent } from "@dub/ui";
+import { capitalize, formatFileSize } from "@dub/utils";
import { useAction } from "next-safe-action/hooks";
import { useParams } from "next/navigation";
-import { PropsWithChildren, ReactNode, useState } from "react";
import { toast } from "sonner";
import { useAddColorModal } from "./add-color-modal";
import { useAddFileModal } from "./add-file-modal";
@@ -27,7 +19,10 @@ export function ProgramResourcesPageClient() {
const { programId } = useParams();
const { id: workspaceId } = useWorkspace();
- const { resources, mutate } = useProgramResources();
+ const { resources, mutate, isLoading, isValidating } = useProgramResources({
+ workspaceId: workspaceId!,
+ programId: programId as string,
+ });
const { setShowAddLogoModal, AddLogoModal } = useAddLogoModal();
const { setShowAddColorModal, AddColorModal } = useAddColorModal();
const { setShowAddFileModal, AddFileModal } = useAddFileModal();
@@ -64,10 +59,12 @@ export function ProgramResourcesPageClient() {
<AddColorModal />
<AddFileModal />
<div className="flex flex-col gap-10">
- <Section
+ <ResourceSection
resource="logo"
title="Brand logos"
description="SVG, JPG, or PNG, max size of 10 MB"
+ isLoading={isLoading}
+ isValidating={isValidating}
onAdd={() => setShowAddLogoModal(true)}
>
{resources?.logos?.map((logo) => (
@@ -89,11 +86,13 @@ export function ProgramResourcesPageClient() {
onDelete={() => handleDelete("logo", logo.id)}
/>
))}
- </Section>
- <Section
+ </ResourceSection>
+ <ResourceSection
resource="color"
title="Colors"
description="Provide affiliates with official colors"
+ isLoading={isLoading}
+ isValidating={isValidating}
onAdd={() => setShowAddColorModal(true)}
>
{resources?.colors?.map((color) => (
@@ -108,14 +107,17 @@ export function ProgramResourcesPageClient() {
}
title={color.name || "Color"}
description={color.color.toUpperCase()}
+ copyText={color.color.toUpperCase()}
onDelete={() => handleDelete("color", color.id)}
/>
))}
- </Section>
- <Section
+ </ResourceSection>
+ <ResourceSection
resource="file"
title="Additional files"
description="Any document file format, max size 10 MB"
+ isLoading={isLoading}
+ isValidating={isValidating}
onAdd={() => setShowAddFileModal(true)}
>
{resources?.files?.map((file) => (
@@ -133,166 +135,8 @@ export function ProgramResourcesPageClient() {
onDelete={() => handleDelete("file", file.id)}
/>
))}
- </Section>
+ </ResourceSection>
</div>
</>
);
}
-
-function Section({
- resource,
- title,
- description,
- onAdd,
- children,
-}: PropsWithChildren<{
- resource: string;
- title: string;
- description: string;
- onAdd?: () => void;
-}>) {
- const { isLoading, isValidating } = useProgramResources();
-
- return (
- <div className="grid grid-cols-1 gap-4 rounded-lg border border-neutral-200 p-4 sm:grid-cols-2 sm:p-6">
- <div>
- <h2 className="text-lg font-semibold text-neutral-900">{title}</h2>
- <p className="text-sm text-neutral-600">{description}</p>
- </div>
- <div className="-m-1">
- <AnimatedSizeContainer
- height={!isLoading}
- transition={{ duration: 0.2, ease: "easeInOut" }}
- >
- <div
- className={cn(
- "flex flex-col items-end gap-4 p-1 transition-opacity",
- isValidating && "opacity-50",
- )}
- >
- {isLoading ? <ResourceCardSkeleton /> : children}
- <Button
- type="button"
- text={`Add ${resource}`}
- onClick={onAdd || (() => alert("WIP"))}
- className="h-8 w-fit px-3"
- />
- </div>
- </AnimatedSizeContainer>
- </div>
- </div>
- );
-}
-
-function ResourceCardSkeleton() {
- return (
- <div className="flex w-full items-center gap-4 rounded-lg border border-neutral-200 p-4">
- <div className="flex size-10 shrink-0 animate-pulse items-center justify-center rounded-md bg-neutral-200" />
- <div className="flex min-w-0 animate-pulse flex-col gap-1">
- <div className="h-4 w-32 max-w-full rounded-md bg-neutral-200" />
- <div className="h-4 w-16 max-w-full rounded-md bg-neutral-200" />
- </div>
- </div>
- );
-}
-
-function ResourceCard({
- resourceType,
- title,
- description,
- icon,
- onDelete,
- downloadUrl,
-}: {
- resourceType: ProgramResourceType;
- title: string;
- description: string;
- icon: ReactNode;
- onDelete?: () => Promise<boolean>;
- downloadUrl?: string;
-}) {
- const [openPopover, setOpenPopover] = useState(false);
- const [isDeleting, setIsDeleting] = useState(false);
-
- return (
- <div className="flex w-full items-center justify-between gap-4 rounded-lg border border-neutral-200 p-4 shadow-sm">
- <div className="flex min-w-0 items-center gap-4">
- <div className="flex size-10 shrink-0 items-center justify-center overflow-hidden rounded-md border border-neutral-200">
- {icon}
- </div>
- <div className="flex min-w-0 flex-col">
- <span className="truncate text-sm font-medium text-neutral-800">
- {title}
- </span>
- <span className="truncate text-xs text-neutral-500">
- {description}
- </span>
- </div>
- </div>
- <div className="relative">
- {(onDelete || downloadUrl) && (
- <Popover
- content={
- <div className="grid w-full grid-cols-1 gap-px p-2 sm:w-48">
- {downloadUrl && (
- <Button
- text="Download"
- variant="outline"
- onClick={async () => {
- window.open(downloadUrl, "_blank");
- }}
- icon={<Download className="size-4" />}
- className="h-9 justify-start px-2 font-medium"
- />
- )}
- {onDelete && (
- <Button
- text={`Delete ${resourceType}`}
- variant="danger-outline"
- onClick={async () => {
- setOpenPopover(false);
-
- if (
- !confirm(
- "Are you sure you want to delete this resource?",
- )
- )
- return;
-
- setIsDeleting(true);
- const success = await onDelete();
- if (success) setIsDeleting(false);
- }}
- icon={<Trash className="size-4" />}
- className="h-9 justify-start px-2 font-medium"
- />
- )}
- </div>
- }
- align="end"
- openPopover={openPopover}
- setOpenPopover={setOpenPopover}
- >
- <Button
- variant="secondary"
- className={cn(
- "h-8 px-1.5 text-neutral-500 outline-none transition-all duration-200",
- "border-transparent data-[state=open]:border-neutral-500 sm:group-hover/card:data-[state=closed]:border-neutral-200",
- )}
- icon={
- isDeleting ? (
- <LoadingSpinner className="size-4 shrink-0" />
- ) : (
- <ThreeDots className="size-4 shrink-0" />
- )
- }
- onClick={() => {
- setOpenPopover(!openPopover);
- }}
- />
- </Popover>
- )}
- </div>
- </div>
- );
-}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/resources/page-client.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/resources/page-client.tsx
index bc61e68188..a27b3196df 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/resources/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/resources/page-client.tsx
@@ -1,28 +1,123 @@
"use client";
+import useProgramResources from "@/lib/swr/use-program-resources";
+import { ResourceCard } from "@/ui/partners/resources/resource-card";
+import { ResourceSection } from "@/ui/partners/resources/resource-section";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import { MaxWidthWrapper } from "@dub/ui";
-import { FileZip2, Palette2, Post } from "@dub/ui/icons";
+import { FileContent, FileZip2, Palette2, Post } from "@dub/ui/icons";
+import { formatFileSize } from "@dub/utils";
+import { useParams } from "next/navigation";
const emptyStateIcons = [Post, Palette2, FileZip2];
export function ResourcesPageClient() {
+ const { programSlug } = useParams();
+
+ const { resources, isLoading, isValidating } = useProgramResources({
+ programId: programSlug as string,
+ });
+
+ const isEmpty =
+ !isLoading &&
+ ["logos", "colors", "files"].every(
+ (resource) => !resources?.[resource]?.length,
+ );
+
return (
<MaxWidthWrapper>
- <AnimatedEmptyState
- title="Resources"
- description="Partner guides and materials to boost promotion and earnings"
- cardContent={(idx) => {
- const Icon = emptyStateIcons[idx % emptyStateIcons.length];
- return (
- <>
- <Icon className="size-4 text-neutral-700" />
- <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
- </>
- );
- }}
- pillContent="Coming soon"
- />
+ {isLoading || !isEmpty ? (
+ <div className="flex flex-col gap-10">
+ {(isLoading || !!resources?.logos?.length) && (
+ <ResourceSection
+ resource="logo"
+ title="Brand logos"
+ isLoading={isLoading}
+ isValidating={isValidating}
+ >
+ {resources?.logos?.map((logo) => (
+ <ResourceCard
+ key={logo.id}
+ resourceType="logo"
+ icon={
+ <div className="relative size-8 overflow-hidden">
+ <img
+ src={logo.url}
+ alt="thumbnail"
+ className="size-full object-contain"
+ />
+ </div>
+ }
+ title={logo.name || "Logo"}
+ description={formatFileSize(logo.size, 0)}
+ downloadUrl={logo.url}
+ />
+ ))}
+ </ResourceSection>
+ )}
+ {(isLoading || !!resources?.colors?.length) && (
+ <ResourceSection
+ resource="color"
+ title="Colors"
+ isLoading={isLoading}
+ isValidating={isValidating}
+ >
+ {resources?.colors?.map((color) => (
+ <ResourceCard
+ key={color.id}
+ resourceType="color"
+ icon={
+ <div
+ className="size-full"
+ style={{ backgroundColor: color.color }}
+ />
+ }
+ title={color.name || "Color"}
+ description={color.color.toUpperCase()}
+ copyText={color.color.toUpperCase()}
+ />
+ ))}
+ </ResourceSection>
+ )}
+ {(isLoading || !!resources?.files?.length) && (
+ <ResourceSection
+ resource="file"
+ title="Additional files"
+ isLoading={isLoading}
+ isValidating={isValidating}
+ >
+ {resources?.files?.map((file) => (
+ <ResourceCard
+ key={file.id}
+ resourceType="file"
+ icon={
+ <div className="flex size-full items-center justify-center bg-neutral-50">
+ <FileContent className="size-4 text-neutral-800" />
+ </div>
+ }
+ title={file.name || "File"}
+ description={formatFileSize(file.size, 0)}
+ downloadUrl={file.url}
+ />
+ ))}
+ </ResourceSection>
+ )}
+ </div>
+ ) : (
+ <AnimatedEmptyState
+ title="Resources"
+ description="When this program adds resources, they'll appear here"
+ cardContent={(idx) => {
+ const Icon = emptyStateIcons[idx % emptyStateIcons.length];
+ return (
+ <>
+ <Icon className="size-4 text-neutral-700" />
+ <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
+ </>
+ );
+ }}
+ />
+ )}
</MaxWidthWrapper>
);
}
diff --git a/apps/web/lib/actions/partners/program-resources/delete-program-resource.ts b/apps/web/lib/actions/partners/program-resources/delete-program-resource.ts
index fec912bfff..242d6ace45 100644
--- a/apps/web/lib/actions/partners/program-resources/delete-program-resource.ts
+++ b/apps/web/lib/actions/partners/program-resources/delete-program-resource.ts
@@ -40,7 +40,7 @@ export const deleteProgramResourceAction = authActionClient
if (!program.resources) throw new Error("Program resources not found");
// Create a copy of the current resources to update
- const updatedResources = { ...program.resources };
+ const updatedResources = { ...(program.resources as any) };
// Find the resource to delete
const resourceKey = `${resourceType}s`;
diff --git a/apps/web/lib/swr/use-program-resources.ts b/apps/web/lib/swr/use-program-resources.ts
index eb34cd21a0..afdbc1e4a5 100644
--- a/apps/web/lib/swr/use-program-resources.ts
+++ b/apps/web/lib/swr/use-program-resources.ts
@@ -1,38 +1,37 @@
import { fetcher } from "@dub/utils";
-import { useParams } from "next/navigation";
import useSWR from "swr";
import { z } from "zod";
import { programResourcesSchema } from "../zod/schemas/program-resources";
-import useWorkspace from "./use-workspace";
export type ProgramResourcesProps = z.infer<typeof programResourcesSchema>;
-export default function useProgramResources() {
- const { id: workspaceId } = useWorkspace();
- const { programId } = useParams();
+export default function useProgramResources(
+ props: { workspaceId: string; programId: string } | { programId: string },
+) {
+ const endpoint =
+ props.programId &&
+ ("workspaceId" in props
+ ? props.workspaceId
+ ? `/api/programs/${props.programId}/resources?workspaceId=${props.workspaceId}`
+ : null
+ : `/api/partner-profile/programs/${props.programId}/resources`);
const {
data: resources,
error,
isValidating,
mutate,
- } = useSWR<ProgramResourcesProps>(
- programId && workspaceId
- ? `/api/programs/${programId}/resources?workspaceId=${workspaceId}`
- : null,
- fetcher,
- {
- dedupingInterval: 60000,
- revalidateOnFocus: false,
- keepPreviousData: true,
- },
- );
+ } = useSWR<ProgramResourcesProps>(endpoint, fetcher, {
+ dedupingInterval: 60000,
+ revalidateOnFocus: false,
+ keepPreviousData: true,
+ });
return {
resources,
error,
mutate,
isValidating,
- isLoading: programId && !resources && !error,
+ isLoading: Boolean(props.programId && !resources && !error),
};
}
diff --git a/apps/web/ui/partners/resources/resource-card.tsx b/apps/web/ui/partners/resources/resource-card.tsx
new file mode 100644
index 0000000000..945314e67f
--- /dev/null
+++ b/apps/web/ui/partners/resources/resource-card.tsx
@@ -0,0 +1,191 @@
+"use client";
+
+import { ProgramResourceType } from "@/lib/zod/schemas/program-resources";
+import { ThreeDots } from "@/ui/shared/icons";
+import {
+ Button,
+ Check,
+ Copy,
+ Download,
+ LoadingSpinner,
+ Popover,
+ Trash,
+ useCopyToClipboard,
+} from "@dub/ui";
+import { cn } from "@dub/utils";
+import { ReactNode, useState } from "react";
+import { toast } from "sonner";
+
+export function ResourceCardSkeleton() {
+ return (
+ <div className="flex w-full items-center gap-4 rounded-lg border border-neutral-200 p-4">
+ <div className="flex size-10 shrink-0 animate-pulse items-center justify-center rounded-md bg-neutral-200" />
+ <div className="flex min-w-0 animate-pulse flex-col gap-1">
+ <div className="h-4 w-32 max-w-full rounded-md bg-neutral-200" />
+ <div className="h-4 w-16 max-w-full rounded-md bg-neutral-200" />
+ </div>
+ </div>
+ );
+}
+
+export function ResourceCard({
+ resourceType,
+ title,
+ description,
+ icon,
+ onDelete,
+ downloadUrl,
+ copyText,
+}: {
+ resourceType: ProgramResourceType;
+ title: string;
+ description: string;
+ icon: ReactNode;
+ onDelete?: () => Promise<boolean>;
+ downloadUrl?: string;
+ copyText?: string;
+}) {
+ const [openPopover, setOpenPopover] = useState(false);
+ const [isDeleting, setIsDeleting] = useState(false);
+
+ const [copied, copyToClipboard] = useCopyToClipboard();
+
+ const handleDownload = () => window.open(downloadUrl, "_blank");
+
+ return (
+ <div className="flex w-full items-center justify-between gap-4 rounded-lg border border-neutral-200 p-4 shadow-sm">
+ <div className="flex min-w-0 items-center gap-4">
+ <div className="flex size-10 shrink-0 items-center justify-center overflow-hidden rounded-md border border-neutral-200">
+ {icon}
+ </div>
+ <div className="flex min-w-0 flex-col">
+ <span className="truncate text-sm font-medium text-neutral-800">
+ {title}
+ </span>
+ <span className="truncate text-xs text-neutral-500">
+ {description}
+ </span>
+ </div>
+ </div>
+ <div className="relative">
+ {onDelete || (downloadUrl && copyText) ? (
+ <Popover
+ content={
+ <div className="grid w-full grid-cols-1 gap-px p-2 sm:w-48">
+ {downloadUrl && (
+ <Button
+ text="Download"
+ variant="outline"
+ onClick={() => {
+ handleDownload();
+ setOpenPopover(false);
+ }}
+ icon={<Download className="size-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ />
+ )}
+ {copyText && (
+ <Button
+ text="Copy"
+ variant="outline"
+ onClick={() => {
+ copyToClipboard(copyText, {
+ onSuccess: () => toast.success("Copied to clipboard"),
+ });
+ setOpenPopover(false);
+ }}
+ icon={<Copy className="size-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ />
+ )}
+ {onDelete && (
+ <Button
+ text={`Delete ${resourceType}`}
+ variant="danger-outline"
+ onClick={async () => {
+ setOpenPopover(false);
+
+ if (
+ !confirm(
+ "Are you sure you want to delete this resource?",
+ )
+ )
+ return;
+
+ setIsDeleting(true);
+ const success = await onDelete();
+ if (success) setIsDeleting(false);
+ }}
+ icon={<Trash className="size-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ />
+ )}
+ </div>
+ }
+ align="end"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <Button
+ variant="secondary"
+ className={cn(
+ "h-8 px-1.5 text-neutral-500 outline-none transition-all duration-200",
+ "border-transparent data-[state=open]:border-neutral-500 sm:group-hover/card:data-[state=closed]:border-neutral-200",
+ )}
+ icon={
+ isDeleting ? (
+ <LoadingSpinner className="size-4 shrink-0" />
+ ) : (
+ <ThreeDots className="size-4 shrink-0" />
+ )
+ }
+ onClick={() => {
+ setOpenPopover(!openPopover);
+ }}
+ />
+ </Popover>
+ ) : (
+ <>
+ {downloadUrl && (
+ <Button
+ icon={<Download className="size-4" />}
+ text="Download"
+ variant="secondary"
+ className="h-8 px-3"
+ onClick={handleDownload}
+ />
+ )}
+ {copyText && (
+ <Button
+ icon={
+ <div className="relative size-4">
+ <div
+ className={cn(
+ "absolute inset-0 transition-[transform,opacity]",
+ copied && "translate-y-1 opacity-0",
+ )}
+ >
+ <Copy className="size-4" />
+ </div>
+ <div
+ className={cn(
+ "absolute inset-0 transition-[transform,opacity]",
+ !copied && "translate-y-1 opacity-0",
+ )}
+ >
+ <Check className="size-4" />
+ </div>
+ </div>
+ }
+ text={copied ? "Copied" : "Copy"}
+ variant="secondary"
+ className="h-8 px-3"
+ onClick={() => copyToClipboard(copyText)}
+ />
+ )}
+ </>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/ui/partners/resources/resource-section.tsx b/apps/web/ui/partners/resources/resource-section.tsx
new file mode 100644
index 0000000000..675fe780f4
--- /dev/null
+++ b/apps/web/ui/partners/resources/resource-section.tsx
@@ -0,0 +1,57 @@
+"use client";
+
+import { AnimatedSizeContainer, Button } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { PropsWithChildren } from "react";
+import { ResourceCardSkeleton } from "./resource-card";
+
+export function ResourceSection({
+ resource,
+ title,
+ description,
+ isLoading,
+ isValidating,
+ onAdd,
+ children,
+}: PropsWithChildren<{
+ resource: string;
+ title: string;
+ description?: string;
+ isLoading?: boolean;
+ isValidating?: boolean;
+ onAdd?: () => void;
+}>) {
+ return (
+ <div className="grid grid-cols-1 gap-4 rounded-lg border border-neutral-200 p-4 sm:grid-cols-2 sm:p-6">
+ <div>
+ <h2 className="text-lg font-semibold text-neutral-900">{title}</h2>
+ {description && (
+ <p className="text-sm text-neutral-600">{description}</p>
+ )}
+ </div>
+ <div className="-m-1">
+ <AnimatedSizeContainer
+ height={!isLoading}
+ transition={{ duration: 0.2, ease: "easeInOut" }}
+ >
+ <div
+ className={cn(
+ "flex flex-col items-end gap-4 p-1 transition-opacity",
+ isValidating && "opacity-50",
+ )}
+ >
+ {isLoading ? <ResourceCardSkeleton /> : children}
+ {onAdd && (
+ <Button
+ type="button"
+ text={`Add ${resource}`}
+ onClick={onAdd}
+ className="h-8 w-fit px-3"
+ />
+ )}
+ </div>
+ </AnimatedSizeContainer>
+ </div>
+ </div>
+ );
+}
diff --git a/packages/ui/src/hooks/use-copy-to-clipboard.tsx b/packages/ui/src/hooks/use-copy-to-clipboard.tsx
index 714707e602..a5b4beb097 100644
--- a/packages/ui/src/hooks/use-copy-to-clipboard.tsx
+++ b/packages/ui/src/hooks/use-copy-to-clipboard.tsx
@@ -14,7 +14,10 @@ export const useCopyToClipboard = (
};
const copyToClipboard = useCallback(
- async (value: string | ClipboardItem) => {
+ async (
+ value: string | ClipboardItem,
+ { onSuccess }: { onSuccess?: () => void } = {},
+ ) => {
clearTimer();
try {
if (typeof value === "string") {
@@ -23,6 +26,7 @@ export const useCopyToClipboard = (
await navigator.clipboard.write([value]);
}
setCopied(true);
+ onSuccess?.();
// Ensure timeout is a non-negative finite number
if (Number.isFinite(timeout) && timeout >= 0) {