The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add new library empty states
Tim Wilsonad0767d7864c
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/library-empty-state.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/library-empty-state.tsxnew file mode 100644index 0000000000..7931c9b023--- /dev/null+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/library-empty-state.tsx@@ -0,0 +1,60 @@+import { buttonVariants } from "@dub/ui";+import { cn } from "@dub/utils";+import Link from "next/link";+import { CSSProperties, PropsWithChildren, ReactNode } from "react";++export function LibraryEmptyState({+ title,+ description,+ cardContent,+ addButton,+ learnMoreHref,+}: {+ title: string;+ description: string;+ cardContent: ReactNode;+ addButton: ReactNode;+ learnMoreHref?: string;+}) {+ return (+ <div className="mt-6 flex flex-col items-center justify-center gap-6 rounded-lg border border-gray-200 px-4 py-10 md:min-h-[500px]">+ <div className="animate-fade-in h-36 w-64 max-w-full overflow-hidden px-4 [mask-image:linear-gradient(transparent,black_10%,black_90%,transparent)]">+ <div+ style={{ "--scroll": "-50%" } as CSSProperties}+ className="animate-infinite-scroll-y flex flex-col [animation-duration:10s]"+ >+ {[...Array(6)].map((_, idx) => (+ <Card key={idx}>{cardContent}</Card>+ ))}+ </div>+ </div>+ <div className="text-center">+ <span className="text-base font-medium text-neutral-900">{title}</span>+ <p className="mt-2 text-sm text-neutral-500">{description}</p>+ </div>+ <div className="flex items-center gap-2">+ {addButton}+ {learnMoreHref && (+ <Link+ href={learnMoreHref}+ target="_blank"+ className={cn(+ buttonVariants({ variant: "secondary" }),+ "flex h-9 items-center rounded-lg border px-4 text-sm",+ )}+ >+ Learn more+ </Link>+ )}+ </div>+ </div>+ );+}++function Card({ children }: PropsWithChildren) {+ return (+ <div className="mt-4 flex items-center gap-3 rounded-lg border border-neutral-200 bg-white px-5 py-4 shadow-[0_4px_12px_0_#0000000D]">+ {children}+ </div>+ );+}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/tags/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/tags/page-client.tsxindex e7631d9ae1..2c9bc7c1e9 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/tags/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/tags/page-client.tsx@@ -6,12 +6,17 @@ import useTagsCount from "@/lib/swr/use-tags-count";import useWorkspace from "@/lib/swr/use-workspace";import { TAGS_MAX_PAGE_SIZE } from "@/lib/zod/schemas/tags";import { useAddEditTagModal } from "@/ui/modals/add-edit-tag-modal";-import EmptyState from "@/ui/shared/empty-state";import { SearchBoxPersisted } from "@/ui/shared/search-box";import { PaginationControls } from "@dub/blocks";-import { CardList, usePagination, useRouterStuff } from "@dub/ui";-import { Tag } from "@dub/ui/src/icons";-import { Dispatch, SetStateAction, createContext, useState } from "react";+import { CardList, Tag, usePagination, useRouterStuff } from "@dub/ui";+import {+ createContext,+ Dispatch,+ SetStateAction,+ useEffect,+ useState,+} from "react";+import { LibraryEmptyState } from "../library-empty-state";import { TagCard } from "./tag-card";import { TagCardPlaceholder } from "./tag-card-placeholder";@@ -48,53 +53,87 @@ export default function WorkspaceTagsClient() {showArchived: true,});+ // Whether the initial tags have already loaded, for some loading states like the search box+ const [initiallyLoaded, setInitiallyLoaded] = useState(false);+ useEffect(() => {+ if (!loading && tags) setInitiallyLoaded(true);+ }, [tags, loading]);+const [openMenuTagId, setOpenMenuTagId] = useState<string | null>(null);return (<><div className="grid gap-4 pb-10">- <div className="flex w-full flex-wrap items-center justify-between gap-3 gap-6 sm:w-auto">- <SearchBoxPersisted- loading={loading}- onChangeDebounced={(t) => {- if (t) {- queryParams({ set: { search: t }, del: "page" });- } else {- queryParams({ del: "search" });- }- }}- />- <AddTagButton />- </div>{workspaceId && <AddEditTagModal />}-{loading || tags?.length ? (- <TagsListContext.Provider value={{ openMenuTagId, setOpenMenuTagId }}>- <CardList variant="compact" loading={loading}>- {tags?.length- ? tags.map((tag) => (- <TagCard key={tag.id} tag={tag} tagsCount={tagLinksCount} />- ))- : Array.from({ length: 6 }).map((_, idx) => (- <TagCardPlaceholder key={idx} />- ))}- </CardList>- </TagsListContext.Provider>- ) : (- <div className="flex flex-col items-center gap-4 rounded-xl border border-gray-200 py-10">- <EmptyState icon={Tag} title="No tags found for this workspace" />- <AddTagButton />- </div>- )}+ <>+ <div className="flex w-full flex-wrap items-center justify-between gap-3 gap-6 sm:w-auto">+ {initiallyLoaded ? (+ <>+ <SearchBoxPersisted+ loading={loading}+ onChangeDebounced={(t) => {+ if (t) {+ queryParams({ set: { search: t }, del: "page" });+ } else {+ queryParams({ del: "search" });+ }+ }}+ />+ <AddTagButton />+ </>+ ) : (+ <>+ <div className="h-[38px] w-20 animate-pulse rounded-md bg-gray-100 md:w-60" />+ <div className="h-9 w-24 animate-pulse rounded-md bg-gray-100" />+ </>+ )}+ </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={tagsCount || 0}- unit={(p) => `tag${p ? "s" : ""}`}+ <TagsListContext.Provider+ value={{ openMenuTagId, setOpenMenuTagId }}+ >+ <CardList variant="compact" loading={loading}>+ {tags?.length+ ? tags.map((tag) => (+ <TagCard+ key={tag.id}+ tag={tag}+ tagsCount={tagLinksCount}+ />+ ))+ : Array.from({ length: 6 }).map((_, idx) => (+ <TagCardPlaceholder key={idx} />+ ))}+ </CardList>+ </TagsListContext.Provider>+ {initiallyLoaded && (+ <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={tagsCount || 0}+ unit={(p) => `tag${p ? "s" : ""}`}+ />+ </div>+ )}+ </>+ ) : (+ <LibraryEmptyState+ title="No tags"+ description="Create tags to organize your links"+ cardContent={+ <>+ <div className="flex size-7 items-center justify-center rounded-md border border-neutral-200 bg-neutral-50">+ <Tag className="size-4 text-neutral-700" />+ </div>+ <div className="h-2.5 w-28 min-w-0 rounded-sm bg-neutral-200" />+ </>+ }+ addButton={<AddTagButton />}+ learnMoreHref="https://dub.co/help/article/how-to-use-tags"/>- </div>+ )}</div></>);diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/utm/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/utm/page-client.tsxindex d1922ada51..2712c55753 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/utm/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/utm/page-client.tsx@@ -3,12 +3,18 @@import useWorkspace from "@/lib/swr/use-workspace";import { UtmTemplateWithUserProps } from "@/lib/types";import { useAddEditUtmTemplateModal } from "@/ui/modals/add-edit-utm-template.modal";-import EmptyState from "@/ui/shared/empty-state";import { CardList } from "@dub/ui";-import { DiamondTurnRight } from "@dub/ui/src";+import { DiamondTurnRight, Flag6, GlobePointer } from "@dub/ui/src";import { fetcher } from "@dub/utils";-import { Dispatch, SetStateAction, createContext, useState } from "react";+import {+ Dispatch,+ SetStateAction,+ createContext,+ useEffect,+ useState,+} from "react";import useSWR from "swr";+import { LibraryEmptyState } from "../library-empty-state";import { TemplateCard } from "./template-card";import { TemplateCardPlaceholder } from "./template-card-placeholder";@@ -31,6 +37,12 @@ export default function WorkspaceUtmTemplatesClient() {},);+ // Whether the initial tags have already loaded, for some loading states like the search box+ const [initiallyLoaded, setInitiallyLoaded] = useState(false);+ useEffect(() => {+ if (!isLoading && templates) setInitiallyLoaded(true);+ }, [templates, isLoading]);+const [openMenuTemplateId, setOpenMenuTemplateId] = useState<string | null>(null,);@@ -41,33 +53,50 @@ export default function WorkspaceUtmTemplatesClient() {return (<><div className="grid gap-4">- <div className="flex justify-end gap-6">- <AddUtmTemplateButton />- </div>{workspaceId && <AddEditUtmTemplateModal />}{isLoading || templates?.length ? (- <TemplatesListContext.Provider- value={{ openMenuTemplateId, setOpenMenuTemplateId }}- >- <CardList variant="compact" loading={isLoading}>- {templates?.length- ? templates.map((template) => (- <TemplateCard key={template.id} template={template} />- ))- : Array.from({ length: 6 }).map((_, idx) => (- <TemplateCardPlaceholder key={idx} />- ))}- </CardList>- </TemplatesListContext.Provider>+ <>+ <div className="flex justify-end gap-6">+ {initiallyLoaded ? (+ <AddUtmTemplateButton />+ ) : (+ <div className="h-9 w-32 animate-pulse rounded-md bg-gray-100" />+ )}+ </div>+ <TemplatesListContext.Provider+ value={{ openMenuTemplateId, setOpenMenuTemplateId }}+ >+ <CardList variant="compact" loading={isLoading}>+ {templates?.length+ ? templates.map((template) => (+ <TemplateCard key={template.id} template={template} />+ ))+ : Array.from({ length: 6 }).map((_, idx) => (+ <TemplateCardPlaceholder key={idx} />+ ))}+ </CardList>+ </TemplatesListContext.Provider>+ </>) : (- <div className="flex flex-col items-center gap-4 rounded-xl border border-gray-200 py-10">- <EmptyState- icon={DiamondTurnRight}- title="No templates found for this workspace"- />- <AddUtmTemplateButton />- </div>+ <LibraryEmptyState+ title="No UTM Templates"+ description="Create templates for quicker link tracking"+ cardContent={+ <>+ <div className="flex size-7 items-center justify-center rounded-md border border-neutral-200 bg-neutral-50">+ <DiamondTurnRight className="size-4 text-neutral-700" />+ </div>+ <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />+ <div className="hidden grow items-center justify-end gap-1.5 text-gray-500 sm:flex">+ <GlobePointer className="size-3.5" />+ <Flag6 className="size-3.5" />+ </div>+ </>+ }+ addButton={<AddUtmTemplateButton />}+ learnMoreHref="https://dub.co/help/article/utm-builder" // TODO: Update with template-specific link+ />)}</div></>diff --git a/apps/web/tailwind.config.ts b/apps/web/tailwind.config.tsindex 3ec52ee87c..4c9f07f408 100644--- a/apps/web/tailwind.config.ts+++ b/apps/web/tailwind.config.ts@@ -19,6 +19,7 @@ const config: Pick<Config, "presets"> = {...sharedConfig?.theme?.extend?.animation,// Infinite scroll animation"infinite-scroll": "infinite-scroll 22s linear infinite",+ "infinite-scroll-y": "infinite-scroll-y 22s linear infinite",// Text appear animation"text-appear": "text-appear 0.15s ease",// Table pinned column shadow animation@@ -37,6 +38,10 @@ const config: Pick<Config, "presets"> = {"0%": { transform: "translateX(0)" },"100%": { transform: "translateX(-150%)" },},+ "infinite-scroll-y": {+ "0%": { transform: "translateY(0)" },+ "100%": { transform: "translateY(var(--scroll, -150%))" },+ },// Text appear animation"text-appear": {"0%": {