The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add empty states
Tim Wilson931d60128c21
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsxindex 8cadd789f5..5027f17a26 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx@@ -5,8 +5,14 @@ import { clickEventEnrichedSchema } from "@/lib/zod/schemas/clicks";import { leadEventEnrichedSchema } from "@/lib/zod/schemas/leads";import { saleEventEnrichedSchema } from "@/lib/zod/schemas/sales";import { EventList } from "@dub/blocks";-import { CursorRays, Globe, InvoiceDollar, UserCheck } from "@dub/ui/src/icons";-import { COUNTRIES, timeAgo } from "@dub/utils";+import {+ ChartActivity2,+ CursorRays,+ Globe,+ InvoiceDollar,+ UserCheck,+} from "@dub/ui/src/icons";+import { capitalize, COUNTRIES, timeAgo } from "@dub/utils";import { useSearchParams } from "next/navigation";import { z } from "zod";@@ -46,6 +52,12 @@ export function ActivityList({};})}totalEvents={totalEvents}+ emptyState={{+ icon: ChartActivity2,+ title: `${capitalize(event)} Activity`,+ description: `No referral ${event} have been recorded yet.`,+ learnMore: "https://d.to/conversions",+ }}/>);}diff --git a/apps/web/ui/shared/empty-state.tsx b/apps/web/ui/shared/empty-state.tsxindex 67e9085aed..08b66daba2 100644--- a/apps/web/ui/shared/empty-state.tsx+++ b/apps/web/ui/shared/empty-state.tsx@@ -1,42 +1,19 @@+import { EmptyState as EmptyStateBlock } from "@dub/blocks";import { buttonVariants } from "@dub/ui";import { cn } from "@dub/utils";import Link from "next/link";+import { ComponentProps } from "react";export default function EmptyState({- icon: Icon,- title,- description,- learnMore,buttonText,buttonLink,+ ...rest}: {- icon: React.ElementType;- title: string;- description?: string;- learnMore?: string;buttonText?: string;buttonLink?: string;-}) {+} & Omit<ComponentProps<typeof EmptyStateBlock>, "children">) {return (- <div className="flex flex-col items-center justify-center gap-y-4">- <div className="flex h-16 w-16 items-center justify-center rounded-2xl border border-gray-200 bg-gray-50">- <Icon className="h-8 w-8 text-black" strokeWidth={0.75} />- </div>- <p className="text-center text-base font-medium text-gray-950">{title}</p>- {description && (- <p className="max-w-sm text-center text-sm text-gray-500">- {description}{" "}- {learnMore && (- <a- href={learnMore}- target="_blank"- className="underline underline-offset-2 hover:text-gray-800"- >- Learn more ↗- </a>- )}- </p>- )}+ <EmptyStateBlock {...rest}>{buttonText && buttonLink && (<Linkhref={buttonLink}@@ -51,6 +28,6 @@ export default function EmptyState({</span></Link>)}- </div>+ </EmptyStateBlock>);}diff --git a/packages/blocks/src/empty-state.tsx b/packages/blocks/src/empty-state.tsxnew file mode 100644index 0000000000..60a04f6a67--- /dev/null+++ b/packages/blocks/src/empty-state.tsx@@ -0,0 +1,40 @@+import { PropsWithChildren, ReactNode } from "react";++export type EmptyStateProps = PropsWithChildren<{+ icon: React.ElementType;+ title: string;+ description?: ReactNode;+ learnMore?: string;+}>;++export function EmptyState({+ icon: Icon,+ title,+ description,+ learnMore,+ children,+}: EmptyStateProps) {+ return (+ <div className="flex flex-col items-center justify-center gap-y-4">+ <div className="flex h-16 w-16 items-center justify-center rounded-2xl border border-gray-200 bg-gray-50">+ <Icon className="h-8 w-8 text-black" strokeWidth={0.75} />+ </div>+ <p className="text-center text-base font-medium text-gray-950">{title}</p>+ {description && (+ <p className="max-w-sm text-center text-sm text-gray-500">+ {description}{" "}+ {learnMore && (+ <a+ href={learnMore}+ target="_blank"+ className="underline underline-offset-2 hover:text-gray-800"+ >+ Learn more ↗+ </a>+ )}+ </p>+ )}+ {children}+ </div>+ );+}diff --git a/packages/blocks/src/event-list.tsx b/packages/blocks/src/event-list.tsxindex 7ae72f0c9f..de05ae0b5b 100644--- a/packages/blocks/src/event-list.tsx+++ b/packages/blocks/src/event-list.tsx@@ -2,11 +2,13 @@import { usePagination } from "@dub/ui";import { PropsWithChildren, ReactNode } from "react";+import { EmptyState, EmptyStateProps } from "./empty-state";import { PaginationControls } from "./pagination-controls";export type EventListProps = PropsWithChildren<{events: { icon: ReactNode; content: ReactNode; right?: ReactNode }[];totalEvents: number;+ emptyState: EmptyStateProps;}>;const buttonClassName = [@@ -15,35 +17,43 @@ const buttonClassName = ["disabled:cursor-not-allowed disabled:border-gray-200 disabled:text-gray-400 disabled:bg-white",].join(" ");-export function EventList({ events, totalEvents }: EventListProps) {+export function EventList({ events, totalEvents, emptyState }: EventListProps) {const { pagination, setPagination } = usePagination();return (<div className="rounded-xl border border-gray-200">- <div className="flex flex-col divide-y divide-gray-200">- {events.map((event, index) => (- <div- key={index}- className="flex items-center justify-between gap-5 px-3.5 py-4"- >- <div className="flex items-center gap-2.5 text-gray-500">- <div>{event.icon}</div>- <div className="text-xs">{event.content}</div>- </div>- {event.right !== undefined && (- <div className="text-xs text-gray-400">{event.right}</div>- )}+ {totalEvents === 0 ? (+ <div className="px-4 py-8">+ <EmptyState {...emptyState} />+ </div>+ ) : (+ <>+ <div className="flex flex-col divide-y divide-gray-200">+ {events.map((event, index) => (+ <div+ key={index}+ className="flex items-center justify-between gap-5 px-3.5 py-4"+ >+ <div className="flex items-center gap-2.5 text-gray-500">+ <div>{event.icon}</div>+ <div className="text-xs">{event.content}</div>+ </div>+ {event.right !== undefined && (+ <div className="text-xs text-gray-400">{event.right}</div>+ )}+ </div>+ ))}</div>- ))}- </div>- <div className="sticky bottom-0 rounded-b-[inherit] border-t border-gray-200 bg-white px-3.5 py-2">- <PaginationControls- pagination={pagination}- setPagination={setPagination}- totalCount={totalEvents}- unit={(p) => `event${p ? "s" : ""}`}- />- </div>+ <div className="sticky bottom-0 rounded-b-[inherit] border-t border-gray-200 bg-white px-3.5 py-2">+ <PaginationControls+ pagination={pagination}+ setPagination={setPagination}+ totalCount={totalEvents}+ unit={(p) => `event${p ? "s" : ""}`}+ />+ </div>+ </>+ )}</div>);}diff --git a/packages/blocks/src/index.tsx b/packages/blocks/src/index.tsxindex 456086cade..03dcbf38e1 100644--- a/packages/blocks/src/index.tsx+++ b/packages/blocks/src/index.tsx@@ -1,5 +1,6 @@// stylesimport "./styles.css";+export * from "./empty-state";export * from "./event-list";export * from "./pagination-controls";diff --git a/packages/ui/src/icons/nucleo/chart-activity2.tsx b/packages/ui/src/icons/nucleo/chart-activity2.tsxnew file mode 100644index 0000000000..6a154d9799--- /dev/null+++ b/packages/ui/src/icons/nucleo/chart-activity2.tsx@@ -0,0 +1,24 @@+import { SVGProps } from "react";++export function ChartActivity2(props: SVGProps<SVGSVGElement>) {+ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ {...props}+ >+ <g fill="currentColor">+ <path+ d="M16.25,8.75h-2.297c-.422,0-.798,.265-.941,.661l-1.647,4.575c-.12,.334-.594,.328-.706-.008L7.341,4.022c-.112-.336-.586-.342-.706-.008l-1.647,4.575c-.143,.397-.519,.661-.941,.661H1.75"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ </g>+ </svg>+ );+}diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.tsindex 11f448892d..1ff38292c3 100644--- a/packages/ui/src/icons/nucleo/index.ts+++ b/packages/ui/src/icons/nucleo/index.ts@@ -8,6 +8,7 @@ export * from "./book2";export * from "./box-archive";export * from "./bullet-list";export * from "./cards";+export * from "./chart-activity2";export * from "./chart-line";export * from "./check";export * from "./circle-check";