The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add free domain banner
Tim Wilson5592db324886
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/page-client.tsxindex 2579af3298..2be052a7c0 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/domains/page-client.tsx@@ -6,6 +6,7 @@ import useDomainsCount from "@/lib/swr/use-domains-count";import useWorkspace from "@/lib/swr/use-workspace";import DomainCard from "@/ui/domains/domain-card";import DomainCardPlaceholder from "@/ui/domains/domain-card-placeholder";+import { FreeDotLinkBanner } from "@/ui/domains/free-dot-link-banner";import { useAddEditDomainModal } from "@/ui/modals/add-edit-domain-modal";import { useRegisterDomainModal } from "@/ui/modals/register-domain";import EmptyState from "@/ui/shared/empty-state";@@ -161,6 +162,8 @@ export default function WorkspaceDomainsClient() {</>)}+ <FreeDotLinkBanner />+<div key={archived} className="animate-fade-in">{!loading ? (allWorkspaceDomains.length > 0 ? (diff --git a/apps/web/lib/swr/use-domains-count.ts b/apps/web/lib/swr/use-domains-count.tsindex f15e99190e..723809cd89 100644--- a/apps/web/lib/swr/use-domains-count.ts+++ b/apps/web/lib/swr/use-domains-count.ts@@ -3,12 +3,26 @@ import { fetcher } from "@dub/utils";import useSWR from "swr";import useWorkspace from "./use-workspace";-export default function useDomainsCount() {+export default function useDomainsCount({+ includeParams = true,+ params,+}: {+ includeParams?: boolean;+ params?: Record<string, string>;+} = {}) {const { id: workspaceId } = useWorkspace();const { getQueryString } = useRouterStuff();const { data, error } = useSWR<number>(- workspaceId && `/api/domains/count${getQueryString({ workspaceId })}`,+ workspaceId &&+ `/api/domains/count${+ includeParams+ ? getQueryString({+ workspaceId,+ ...params,+ })+ : "?" + new URLSearchParams({ workspaceId, ...params }).toString()+ }`,fetcher,{dedupingInterval: 60000,diff --git a/apps/web/ui/domains/free-dot-link-banner.tsx b/apps/web/ui/domains/free-dot-link-banner.tsxnew file mode 100644index 0000000000..9cf7353daf--- /dev/null+++ b/apps/web/ui/domains/free-dot-link-banner.tsx@@ -0,0 +1,64 @@+import useDomainsCount from "@/lib/swr/use-domains-count";+import { Grid, useLocalStorage } from "@dub/ui";+import { LinkBroken } from "@dub/ui/src/icons";+import { useRegisterDomainModal } from "../modals/register-domain";+import { X } from "../shared/icons";++export function FreeDotLinkBanner() {+ const [hide, setHide] = useLocalStorage("free-dot-link-banner-hide", false);++ const { RegisterDomainModal, setShowRegisterDomainModal } =+ useRegisterDomainModal();++ const { data: domainsCount } = useDomainsCount({+ includeParams: false,+ params: {+ search: ".link",+ },+ });++ return hide || domainsCount !== 0 ? null : (+ <>+ <RegisterDomainModal />+ <div className="relative isolate flex flex-col justify-between gap-3 overflow-hidden rounded-lg border border-green-600/15 bg-gradient-to-r from-lime-100/80 to-emerald-100/80 py-3 pl-4 pr-12 sm:flex-row sm:items-center sm:py-2">+ <Grid+ cellSize={13}+ patternOffset={[0, -1]}+ className="text-black/30 mix-blend-overlay [mask-image:linear-gradient(to_right,black,transparent)] md:[mask-image:linear-gradient(to_right,black_60%,transparent)]"+ />++ <div className="flex items-center gap-3">+ <div className="hidden rounded-full border border-green-600/50 bg-white/50 p-1 shadow-[inset_0_0_1px_1px_#fff] sm:block">+ <LinkBroken className="m-px size-4 text-green-800" />+ </div>+ <p className="text-sm text-gray-900">+ Claim a free <span className="font-semibold">.link</span> domain,+ free for one year.{" "}+ <a+ href="https://dub.co/help/article/how-to-add-custom-domain" // TODO: Update link+ target="_blank"+ className="text-gray-700 underline transition-colors hover:text-black"+ >+ Learn more+ </a>+ </p>+ </div>++ <div className="flex items-center sm:-my-1">+ <button+ className="whitespace-nowrap rounded-md border border-green-700/50 px-3 py-1 text-sm text-gray-800 transition-colors hover:bg-green-500/10"+ onClick={() => setShowRegisterDomainModal(true)}+ >+ Claim Domain+ </button>+ </div>+ <button+ className="absolute right-2.5 top-2 p-1 text-sm text-green-700 underline transition-colors hover:text-green-900"+ onClick={() => setHide(true)}+ >+ <X className="size-[18px]" />+ </button>+ </div>+ </>+ );+}diff --git a/packages/ui/src/grid.tsx b/packages/ui/src/grid.tsxnew file mode 100644index 0000000000..097244ba18--- /dev/null+++ b/packages/ui/src/grid.tsx@@ -0,0 +1,43 @@+import { cn } from "@dub/utils";++export function Grid({+ cellSize = 12,+ strokeWidth = 1,+ patternOffset = [0, 0],+ className,+}: {+ cellSize?: number;+ strokeWidth?: number;+ patternOffset?: [number, number];+ className?: string;+}) {+ return (+ <svg+ className={cn(+ "pointer-events-none absolute inset-0 text-black/10",+ className,+ )}+ width="100%"+ height="100%"+ >+ <defs>+ <pattern+ id="grid"+ x={patternOffset[0] - 1}+ y={patternOffset[1] - 1}+ width={cellSize}+ height={cellSize}+ patternUnits="userSpaceOnUse"+ >+ <path+ d={`M ${cellSize} 0 L 0 0 0 ${cellSize}`}+ fill="transparent"+ stroke="currentColor"+ strokeWidth={strokeWidth}+ />+ </pattern>+ </defs>+ <rect fill="url(#grid)" width="100%" height="100%" />+ </svg>+ );+}diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsxindex beade1c169..c34a3e8820 100644--- a/packages/ui/src/index.tsx+++ b/packages/ui/src/index.tsx@@ -14,6 +14,7 @@ export * from "./date-picker";export * from "./file-upload";export * from "./filter";export * from "./form";+export * from "./grid";export * from "./input";export * from "./input-select";export * from "./label";