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.

Refactor `/[domain]/**` pages (#3630)

Steven Tey5cc70ed7dcb9
diff --git a/apps/web/app/(external)/[domain]/page.tsx b/apps/web/app/(external)/[domain]/page.tsx
deleted file mode 100644
index d0fc8cd2eb..0000000000
--- a/apps/web/app/(external)/[domain]/page.tsx
+++ /dev/null
@@ -1,25 +0,0 @@
-import { constructMetadata } from "@dub/utils";
-import PlaceholderContent from "./placeholder";
-
-export const revalidate = false; // cache indefinitely
-
-export async function generateMetadata(props: {
- params: Promise<{ domain: string }>;
-}) {
- const params = await props.params;
- const title = `${params.domain.toUpperCase()} - A ${
- process.env.NEXT_PUBLIC_APP_NAME
- } Custom Domain`;
- const description = `${params.domain.toUpperCase()} is a custom domain on ${
- process.env.NEXT_PUBLIC_APP_NAME
- } - an open-source link management tool for modern marketing teams to create, share, and track short links.`;
-
- return constructMetadata({
- title,
- description,
- });
-}
-
-export default function CustomDomainPage() {
- return <PlaceholderContent />;
-}
diff --git a/apps/web/app/inspect/[domain]/[key]/card.tsx b/apps/web/app/[domain]/[key]/inspect/card.tsx
similarity index 96%
rename from apps/web/app/inspect/[domain]/[key]/card.tsx
rename to apps/web/app/[domain]/[key]/inspect/card.tsx
index e7e1b36282..95eaee6dd6 100644
--- a/apps/web/app/inspect/[domain]/[key]/card.tsx
+++ b/apps/web/app/[domain]/[key]/inspect/card.tsx
@@ -15,7 +15,7 @@ export default function LinkInspectorCard({
const key = _key;
const apexDomain = getApexDomain(url);
return (
- <div className="flex w-full items-center justify-between rounded-md border border-neutral-300 bg-white p-3">
+ <div className="flex w-full items-center justify-between rounded-lg border border-neutral-200 bg-white p-3 shadow-sm">
<div className="flex items-center space-x-3">
<LinkLogo apexDomain={apexDomain} />
<div>
diff --git a/apps/web/app/[domain]/[key]/inspect/page.tsx b/apps/web/app/[domain]/[key]/inspect/page.tsx
new file mode 100644
index 0000000000..856abde743
--- /dev/null
+++ b/apps/web/app/[domain]/[key]/inspect/page.tsx
@@ -0,0 +1,98 @@
+import { getLinkViaEdge } from "@/lib/planetscale";
+import { Hero } from "@/ui/placeholders/hero";
+import { LinkPreview, LinkPreviewPlaceholder } from "@dub/ui";
+import {
+ GOOGLE_FAVICON_URL,
+ cn,
+ constructMetadata,
+ getApexDomain,
+} from "@dub/utils";
+import { unescape } from "html-escaper";
+import { notFound } from "next/navigation";
+import { Suspense } from "react";
+import LinkInspectorCard from "./card";
+
+export const runtime = "edge";
+
+export async function generateMetadata(props: {
+ params: Promise<{ domain: string; key: string }>;
+}) {
+ const params = await props.params;
+ const domain = params.domain;
+ const key = decodeURIComponent(params.key);
+
+ const data = await getLinkViaEdge({ domain, key });
+
+ if (!data) {
+ return;
+ }
+
+ const apexDomain = getApexDomain(data.url);
+
+ return constructMetadata({
+ title: unescape(data.title || ""),
+ description: unescape(data.description || ""),
+ image: data.image,
+ icons: `${GOOGLE_FAVICON_URL}${apexDomain}`,
+ noIndex: true,
+ });
+}
+
+export default async function InspectPage(props: {
+ params: Promise<{ domain: string; key: string }>;
+}) {
+ const params = await props.params;
+ const domain = params.domain;
+ const key = decodeURIComponent(params.key);
+
+ const data = await getLinkViaEdge({ domain, key });
+
+ // if the link doesn't exist
+ if (!data) {
+ notFound();
+ }
+
+ return (
+ <Hero className="sm:p-8">
+ <div className="relative mx-auto flex w-full max-w-lg flex-col items-center">
+ <h1
+ className={cn(
+ "font-display mt-10 text-center text-4xl font-medium text-neutral-900 sm:text-5xl sm:leading-[1.15]",
+ "animate-slide-up-fade motion-reduce:animate-fade-in [--offset:20px] [animation-duration:1s] [animation-fill-mode:both]",
+ )}
+ >
+ Link Inspector
+ </h1>
+ <p
+ className={cn(
+ "mt-5 text-pretty text-base text-neutral-700 sm:text-xl",
+ "animate-slide-up-fade motion-reduce:animate-fade-in [--offset:10px] [animation-delay:200ms] [animation-duration:1s] [animation-fill-mode:both]",
+ )}
+ >
+ Inspect a short link on Dub to make sure it&apos;s safe to click on.
+ If you think this link is malicious, please report it.
+ </p>
+ </div>
+
+ <div
+ className={cn(
+ "relative mx-auto mt-10 flex w-full max-w-lg flex-col items-center gap-5 px-2.5 sm:px-0",
+ "animate-slide-up-fade motion-reduce:animate-fade-in [--offset:5px] [animation-delay:300ms] [animation-duration:1s] [animation-fill-mode:both]",
+ )}
+ >
+ <LinkInspectorCard domain={domain} _key={key} url={data.url} />
+ <Suspense fallback={<LinkPreviewPlaceholder />}>
+ <LinkPreview defaultUrl={data.url} />
+ </Suspense>
+ <a
+ href="https://dub.co/tools/inspector"
+ rel="noreferrer"
+ target="_blank"
+ className="flex items-center justify-center gap-2 text-sm text-neutral-600 transition-colors hover:text-neutral-900"
+ >
+ Inspect another short link →
+ </a>
+ </div>
+ </Hero>
+ );
+}
diff --git a/apps/web/app/proxy/[domain]/[key]/page.tsx b/apps/web/app/[domain]/[key]/proxy/page.tsx
similarity index 97%
rename from apps/web/app/proxy/[domain]/[key]/page.tsx
rename to apps/web/app/[domain]/[key]/proxy/page.tsx
index ced86c5554..d1d2efb7bf 100644
--- a/apps/web/app/proxy/[domain]/[key]/page.tsx
+++ b/apps/web/app/[domain]/[key]/proxy/page.tsx
@@ -8,8 +8,6 @@ import {
import { unescape } from "html-escaper";
import { notFound, redirect } from "next/navigation";
-export const revalidate = false; // cache indefinitely
-
export async function generateMetadata(props: {
params: Promise<{ domain: string; key: string }>;
}) {
diff --git a/apps/web/app/(external)/[domain]/stats/[key]/page.tsx b/apps/web/app/[domain]/[key]/stats/page.tsx
similarity index 82%
rename from apps/web/app/(external)/[domain]/stats/[key]/page.tsx
rename to apps/web/app/[domain]/[key]/stats/page.tsx
index b2bf11c5b1..209b225e44 100644
--- a/apps/web/app/(external)/[domain]/stats/[key]/page.tsx
+++ b/apps/web/app/[domain]/[key]/stats/page.tsx
@@ -6,11 +6,14 @@ export default async function OldStatsPage(props: {
params: Promise<{ domain: string; key: string }>;
}) {
const params = await props.params;
+ const domain = params.domain;
+ const key = decodeURIComponent(params.key);
+
const link = await prisma.link.findUnique({
where: {
domain_key: {
- domain: params.domain,
- key: params.key,
+ domain,
+ key,
},
},
select: {
diff --git a/apps/web/app/(external)/static/banned/page.tsx b/apps/web/app/[domain]/banned/page.tsx
similarity index 97%
rename from apps/web/app/(external)/static/banned/page.tsx
rename to apps/web/app/[domain]/banned/page.tsx
index 23e6363198..09d2319915 100644
--- a/apps/web/app/(external)/static/banned/page.tsx
+++ b/apps/web/app/[domain]/banned/page.tsx
@@ -20,6 +20,10 @@ const UTM_PARAMS = {
utm_medium: "Banned Link Page",
};
+export function generateStaticParams() {
+ return [];
+}
+
export default async function BannedPage() {
return (
<div>
diff --git a/apps/web/app/(external)/[domain]/browser-graphic.tsx b/apps/web/app/[domain]/browser-graphic.tsx
similarity index 67%
rename from apps/web/app/(external)/[domain]/browser-graphic.tsx
rename to apps/web/app/[domain]/browser-graphic.tsx
index 37a155841a..d450c97e0c 100644
--- a/apps/web/app/(external)/[domain]/browser-graphic.tsx
+++ b/apps/web/app/[domain]/browser-graphic.tsx
@@ -1,8 +1,11 @@
"use client";
import { cn } from "@dub/utils";
+import { useParams } from "next/navigation";
+
+export function BrowserGraphic() {
+ const { domain } = useParams() as { domain: string };
-export function BrowserGraphic({ domain }: { domain: string }) {
return (
<div className="w-full p-1 [mask-image:linear-gradient(black_50%,transparent_90%)]">
<div className="w-full rounded-t-lg border border-neutral-300 ring ring-black/5">
@@ -18,9 +21,13 @@ export function BrowserGraphic({ domain }: { domain: string }) {
/>
))}
</div>
- <div className="relative min-w-0 grow truncate rounded-lg bg-[radial-gradient(60%_80%_at_50%_0%,#ddd,#f5f5f5)] px-4 py-2 text-sm font-medium leading-none">
+ <div className="relative flex h-8 w-full max-w-xs grow items-center justify-center truncate rounded-lg bg-[radial-gradient(60%_80%_at_50%_0%,#ddd,#f5f5f5)]">
<div className="absolute inset-x-0 top-0 h-px bg-[linear-gradient(90deg,transparent,#0001,transparent)]" />
- {domain}
+ {domain && (
+ <span className="animate-slide-up-fade motion-reduce:animate-fade-in text-sm font-medium">
+ {domain}
+ </span>
+ )}
</div>
<div className="hidden grow basis-0 sm:block" />
</div>
diff --git a/apps/web/app/(external)/[domain]/expired/page.tsx b/apps/web/app/[domain]/expired/page.tsx
similarity index 98%
rename from apps/web/app/(external)/[domain]/expired/page.tsx
rename to apps/web/app/[domain]/expired/page.tsx
index afd94a554e..63522ad033 100644
--- a/apps/web/app/(external)/[domain]/expired/page.tsx
+++ b/apps/web/app/[domain]/expired/page.tsx
@@ -23,6 +23,10 @@ const UTM_PARAMS = {
utm_medium: "Expired Link Page",
};
+export function generateStaticParams() {
+ return [];
+}
+
export default async function ExpiredLinkPage(props: {
params: Promise<{ domain: string }>;
}) {
diff --git a/apps/web/app/(external)/layout.tsx b/apps/web/app/[domain]/layout.tsx
similarity index 89%
rename from apps/web/app/(external)/layout.tsx
rename to apps/web/app/[domain]/layout.tsx
index 470fc44937..158627ebd7 100644
--- a/apps/web/app/(external)/layout.tsx
+++ b/apps/web/app/[domain]/layout.tsx
@@ -1,6 +1,6 @@
import { Footer, Nav, NavMobile } from "@dub/ui";
-export default function CustomDomainLayout({
+export default function ExternalPagesLayout({
children,
}: {
children: React.ReactNode;
diff --git a/apps/web/app/(external)/static/notfound/page.tsx b/apps/web/app/[domain]/notfound/page.tsx
similarity index 97%
rename from apps/web/app/(external)/static/notfound/page.tsx
rename to apps/web/app/[domain]/notfound/page.tsx
index 26c593431e..6e82cd5306 100644
--- a/apps/web/app/(external)/static/notfound/page.tsx
+++ b/apps/web/app/[domain]/notfound/page.tsx
@@ -22,6 +22,10 @@ const UTM_PARAMS = {
utm_medium: "Link Not Found Page",
};
+export function generateStaticParams() {
+ return [];
+}
+
export default async function NotFoundLinkPage() {
return (
<main className="flex min-h-screen flex-col justify-between">
diff --git a/apps/web/app/(external)/[domain]/placeholder.tsx b/apps/web/app/[domain]/page.tsx
similarity index 72%
rename from apps/web/app/(external)/[domain]/placeholder.tsx
rename to apps/web/app/[domain]/page.tsx
index f609fd9f5f..ee340b2ad9 100644
--- a/apps/web/app/(external)/[domain]/placeholder.tsx
+++ b/apps/web/app/[domain]/page.tsx
@@ -1,24 +1,38 @@
-"use client";
-
import { ButtonLink } from "@/ui/placeholders/button-link";
import { CTA } from "@/ui/placeholders/cta";
import { FeaturesSection } from "@/ui/placeholders/features-section";
import { Hero } from "@/ui/placeholders/hero";
import { LearnMoreButton } from "@/ui/placeholders/learn-more-button";
import { Logo } from "@dub/ui";
-import { cn } from "@dub/utils";
-import { useParams } from "next/navigation";
-import { BubbleIcon } from "../../../ui/placeholders/bubble-icon";
+import { cn, constructMetadata } from "@dub/utils";
+import { BubbleIcon } from "../../ui/placeholders/bubble-icon";
import { BrowserGraphic } from "./browser-graphic";
+export const revalidate = false; // cache indefinitely
+
+export async function generateMetadata(props: {
+ params: Promise<{ domain: string }>;
+}) {
+ const params = await props.params;
+ const title = `${params.domain.toUpperCase()} - A Dub Custom Domain`;
+ const description = `${params.domain.toUpperCase()} is a custom domain on Dub - the modern link attribution platform for short links, conversion tracking, and affiliate programs.`;
+
+ return constructMetadata({
+ title,
+ description,
+ });
+}
+// @see: https://nextjs.org/docs/app/api-reference/functions/generate-static-params#all-paths-at-runtime
+export function generateStaticParams() {
+ return [];
+}
+
const UTM_PARAMS = {
utm_source: "Custom Domain",
utm_medium: "Welcome Page",
};
-export default function PlaceholderContent() {
- const { domain } = useParams() as { domain: string };
-
+export default function CustomDomainPage() {
return (
<div>
<Hero>
@@ -27,7 +41,7 @@ export default function PlaceholderContent() {
<Logo className="size-10" />
</BubbleIcon>
<div className="mt-16 w-full">
- <BrowserGraphic domain={domain} />
+ <BrowserGraphic />
</div>
<h1
className={cn(
diff --git a/apps/web/app/custom-uri-scheme/[url]/page.tsx b/apps/web/app/custom-uri-scheme/[url]/page.tsx
index 660b860c6a..a207d5a854 100644
--- a/apps/web/app/custom-uri-scheme/[url]/page.tsx
+++ b/apps/web/app/custom-uri-scheme/[url]/page.tsx
@@ -1,5 +1,9 @@
export const revalidate = false; // cache indefinitely
+export function generateStaticParams() {
+ return [];
+}
+
export default async function CustomURISchemePage(props: {
params: Promise<{ url: string }>;
}) {
diff --git a/apps/web/app/inspect/[domain]/[key]/page.tsx b/apps/web/app/inspect/[domain]/[key]/page.tsx
deleted file mode 100644
index ca254f4a0d..0000000000
--- a/apps/web/app/inspect/[domain]/[key]/page.tsx
+++ /dev/null
@@ -1,92 +0,0 @@
-import { getLinkViaEdge } from "@/lib/planetscale";
-import {
- Background,
- Footer,
- LinkPreview,
- LinkPreviewPlaceholder,
- Nav,
- NavMobile,
-} from "@dub/ui";
-import {
- GOOGLE_FAVICON_URL,
- constructMetadata,
- getApexDomain,
-} from "@dub/utils";
-import { unescape } from "html-escaper";
-import { notFound } from "next/navigation";
-import { Suspense } from "react";
-import LinkInspectorCard from "./card";
-
-export const runtime = "edge";
-
-export async function generateMetadata(props: {
- params: Promise<{ domain: string; key: string }>;
-}) {
- const params = await props.params;
- const domain = params.domain;
- const key = decodeURIComponent(params.key).slice(0, -1);
-
- const data = await getLinkViaEdge({ domain, key });
-
- if (!data) {
- return;
- }
-
- const apexDomain = getApexDomain(data.url);
-
- return constructMetadata({
- title: unescape(data.title || ""),
- description: unescape(data.description || ""),
- image: data.image,
- icons: `${GOOGLE_FAVICON_URL}${apexDomain}`,
- noIndex: true,
- });
-}
-
-export default async function InspectPage(props: {
- params: Promise<{ domain: string; key: string }>;
-}) {
- const params = await props.params;
- const domain = params.domain;
- const key = decodeURIComponent(params.key).slice(0, -1);
-
- const data = await getLinkViaEdge({ domain, key });
-
- // if the link doesn't exist
- if (!data) {
- notFound();
- }
-
- return (
- <>
- <main className="flex min-h-screen flex-col justify-between">
- <NavMobile />
- <Nav />
- <div className="z-10 mx-2 my-10 flex max-w-md flex-col space-y-5 px-2.5 text-center sm:mx-auto sm:max-w-lg sm:px-0 lg:mb-16">
- <h1 className="font-display text-5xl font-extrabold leading-[1.15] text-black sm:text-6xl sm:leading-[1.15]">
- Link Inspector
- </h1>
- <h2 className="text-lg text-neutral-600 sm:text-xl">
- Inspect a short link on Dub to make sure it's safe to click on. If
- you think this link is malicious, please report it.
- </h2>
-
- <LinkInspectorCard domain={domain} _key={key} url={data.url} />
- <Suspense fallback={<LinkPreviewPlaceholder />}>
- <LinkPreview defaultUrl={data.url} />
- </Suspense>
- <a
- href="https://dub.co/tools/inspector"
- rel="noreferrer"
- target="_blank"
- className="mx-auto mt-2 flex items-center justify-center space-x-2 text-sm text-neutral-500 transition-all hover:text-black"
- >
- Inspect another short link →
- </a>
- </div>
- <Footer />
- <Background />
- </main>
- </>
- );
-}
diff --git a/apps/web/lib/api/links/cache.ts b/apps/web/lib/api/links/cache.ts
index 59710c93ec..081e483f55 100644
--- a/apps/web/lib/api/links/cache.ts
+++ b/apps/web/lib/api/links/cache.ts
@@ -111,7 +111,7 @@ class LinkCache {
key,
});
if (!linkData) {
- // if no link found (and Redis fails), throw a 404 error (don't rewrite to /static/notfound since it's expensive)
+ // if no link found (and Redis fails), throw a 404 error (don't rewrite to /${domain}/notfound since it's expensive)
throw new Error("Link not found.");
}
// else, format the link and cache it both in LRU cache and Vercel cache
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 236c63023d..0a2d9f4503 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -158,7 +158,7 @@ export async function LinkMiddleware(req: NextRequest, ev: NextFetchEvent) {
// only show inspect modal if the link is not password protected
if (inspectMode && !password) {
return NextResponse.rewrite(
- new URL(`/inspect/${domain}/${encodeURIComponent(key)}+`, req.url),
+ new URL(`/${domain}/${encodeURIComponent(key)}/inspect`, req.url),
{
headers: {
...DUB_HEADERS,
@@ -195,7 +195,7 @@ export async function LinkMiddleware(req: NextRequest, ev: NextFetchEvent) {
// if the link is banned
if (workspaceId === LEGAL_WORKSPACE_ID) {
- return NextResponse.rewrite(new URL("/static/banned", req.url), {
+ return NextResponse.rewrite(new URL(`/${domain}/banned`, req.url), {
headers: {
...DUB_HEADERS,
...(!shouldIndex && { "X-Robots-Tag": "googlebot: noindex" }),
@@ -301,11 +301,11 @@ export async function LinkMiddleware(req: NextRequest, ev: NextFetchEvent) {
? geolocation(req)
: LOCALHOST_GEO_DATA;
- // rewrite to proxy page (/proxy/[domain]/[key]) if it's a bot and proxy is enabled
+ // rewrite to proxy page ([domain]/[key]/proxy) if it's a bot and proxy is enabled
if (isBot && proxy) {
return createResponseWithCookies(
NextResponse.rewrite(
- new URL(`/proxy/${domain}/${encodeURIComponent(key)}`, req.url),
+ new URL(`/${domain}/${encodeURIComponent(key)}/proxy`, req.url),
{
headers: {
...DUB_HEADERS,
diff --git a/apps/web/lib/middleware/utils/handle-not-found-link.ts b/apps/web/lib/middleware/utils/handle-not-found-link.ts
index 2bfb8bb27d..12ddeb1952 100644
--- a/apps/web/lib/middleware/utils/handle-not-found-link.ts
+++ b/apps/web/lib/middleware/utils/handle-not-found-link.ts
@@ -21,7 +21,7 @@ export const handleNotFoundLink = async (req: NextRequest) => {
status: 302,
});
} else {
- response = NextResponse.rewrite(new URL("/static/notfound", req.url), {
+ response = NextResponse.rewrite(new URL(`/${domain}/notfound`, req.url), {
headers: DUB_HEADERS,
});
}
diff --git a/apps/web/middleware.ts b/apps/web/middleware.ts
index 6a97cd8e63..952f48eb82 100644
--- a/apps/web/middleware.ts
+++ b/apps/web/middleware.ts
@@ -49,9 +49,14 @@ export default async function middleware(req: NextRequest, ev: NextFetchEvent) {
return ApiMiddleware(req);
}
- // for public stats pages (e.g. d.to/stats/try)
+ // for public stats pages (e.g. d.to/stats/try -> rewrite to [/domain]/[key]/stats)
if (path.startsWith("/stats/")) {
- return NextResponse.rewrite(new URL(`/${domain}${path}`, req.url));
+ return NextResponse.rewrite(
+ new URL(
+ `/${domain}/${encodeURIComponent(path.replace("/stats/", ""))}/stats`,
+ req.url,
+ ),
+ );
}
// for .well-known routes
diff --git a/apps/web/ui/placeholders/cta.tsx b/apps/web/ui/placeholders/cta.tsx
index 4635d28986..b2a37cd0e5 100644
--- a/apps/web/ui/placeholders/cta.tsx
+++ b/apps/web/ui/placeholders/cta.tsx
@@ -3,7 +3,8 @@
import { Grid } from "@dub/ui";
import { cn, createHref, UTMTags } from "@dub/utils";
import { Star, StarHalf } from "lucide-react";
-import { ReactNode, useEffect, useState } from "react";
+import { useParams } from "next/navigation";
+import { ReactNode } from "react";
import { ButtonLink } from "./button-link";
import Logos from "./logos";
@@ -39,10 +40,7 @@ export function CTA({
subtitle?: ReactNode;
className?: string;
}) {
- const [domain, setDomain] = useState("");
- useEffect(() => {
- setDomain(window.location.hostname);
- }, []);
+ const { domain } = useParams() as { domain: string };
return (
<div
className={cn(
diff --git a/apps/web/ui/placeholders/features-section.tsx b/apps/web/ui/placeholders/features-section.tsx
index d43f1ddbeb..3acd5a2598 100644
--- a/apps/web/ui/placeholders/features-section.tsx
+++ b/apps/web/ui/placeholders/features-section.tsx
@@ -3,7 +3,8 @@
import { ExpandingArrow } from "@dub/ui";
import { cn, createHref, UTMTags } from "@dub/utils";
import Link from "next/link";
-import { PropsWithChildren, useEffect, useState } from "react";
+import { useParams } from "next/navigation";
+import { PropsWithChildren } from "react";
import Markdown from "react-markdown";
import { Analytics } from "./feature-graphics/analytics";
import { Collaboration } from "./feature-graphics/collaboration";
@@ -16,10 +17,7 @@ export function FeaturesSection({
}: {
utmParams: Partial<Record<(typeof UTMTags)[number], string>>;
}) {
- const [domain, setDomain] = useState("");
- useEffect(() => {
- setDomain(window.location.hostname);
- }, []);
+ const { domain } = useParams() as { domain: string };
return (
<div className="mt-20">
<div className="mx-auto w-full max-w-xl px-4 text-center">
diff --git a/apps/web/ui/placeholders/hero.tsx b/apps/web/ui/placeholders/hero.tsx
index fea63d278c..fcf5218aa8 100644
--- a/apps/web/ui/placeholders/hero.tsx
+++ b/apps/web/ui/placeholders/hero.tsx
@@ -1,4 +1,5 @@
import { Grid } from "@dub/ui";
+import { cn } from "@dub/utils";
import { PropsWithChildren } from "react";
const HERO_GRADIENT = `radial-gradient(77% 116% at 37% 67%, #EEA5BA, rgba(238, 165, 186, 0) 50%),
@@ -8,9 +9,17 @@ const HERO_GRADIENT = `radial-gradient(77% 116% at 37% 67%, #EEA5BA, rgba(238, 1
radial-gradient(90% 136% at 52% 100%, #FD3A4E, rgba(253, 58, 78, 0) 50%),
radial-gradient(102% 143% at 92% 7%, #72FE7D, rgba(114, 254, 125, 0) 50%)`;
-export function Hero({ children }: PropsWithChildren) {
+export function Hero({
+ className,
+ children,
+}: PropsWithChildren<{ className?: string }>) {
return (
- <div className="relative mx-auto mt-4 w-full max-w-screen-lg overflow-hidden rounded-2xl bg-neutral-50 p-6 text-center sm:p-20 sm:px-0">
+ <div
+ className={cn(
+ "relative mx-auto mt-4 w-full max-w-screen-lg overflow-hidden rounded-2xl bg-neutral-50 p-6 text-center sm:p-20 sm:px-0",
+ className,
+ )}
+ >
<Grid
cellSize={80}
patternOffset={[1, -58]}
diff --git a/apps/web/ui/placeholders/learn-more-button.tsx b/apps/web/ui/placeholders/learn-more-button.tsx
index b379fa2610..c488ff23c6 100644
--- a/apps/web/ui/placeholders/learn-more-button.tsx
+++ b/apps/web/ui/placeholders/learn-more-button.tsx
@@ -1,7 +1,7 @@
"use client";
import { createHref } from "@dub/utils";
-import { useEffect, useState } from "react";
+import { useParams } from "next/navigation";
import { ButtonLink } from "./button-link";
export function LearnMoreButton({
@@ -9,10 +9,7 @@ export function LearnMoreButton({
}: {
utmParams: Record<string, string>;
}) {
- const [domain, setDomain] = useState("");
- useEffect(() => {
- setDomain(window.location.hostname);
- }, []);
+ const { domain } = useParams() as { domain: string };
return (
<ButtonLink
variant="secondary"
diff --git a/packages/ui/src/link-preview.tsx b/packages/ui/src/link-preview.tsx
index 3dc301a5a0..6249743954 100644
--- a/packages/ui/src/link-preview.tsx
+++ b/packages/ui/src/link-preview.tsx
@@ -61,9 +61,9 @@ export function LinkPreview({ defaultUrl }: { defaultUrl?: string }) {
</div>
)}
- <div className="relative overflow-hidden rounded-md border border-neutral-300 bg-neutral-50">
+ <div className="relative w-full overflow-hidden rounded-lg border border-neutral-200 bg-neutral-50 shadow-sm">
{isValidating && (
- <div className="absolute flex h-[250px] w-full flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
+ <div className="absolute flex h-[250px] flex-col items-center justify-center space-y-4 border-b border-neutral-300 bg-neutral-50">
<LoadingCircle />
</div>
)}
diff --git a/packages/ui/src/nav/content/product-content.tsx b/packages/ui/src/nav/content/product-content.tsx
index b08b25606e..607b6c1e4e 100644
--- a/packages/ui/src/nav/content/product-content.tsx
+++ b/packages/ui/src/nav/content/product-content.tsx
@@ -8,7 +8,7 @@ import { DubAnalyticsIcon, DubLinksIcon, DubPartnersIcon } from "../../icons";
import { AnalyticsGraphic } from "./graphics/analytics-graphic";
import { LinksGraphic } from "./graphics/links-graphic";
import { PartnersGraphic } from "./graphics/partners-graphic";
-import { getUtmParams } from "./shared";
+import { NAV_UTM_PARAMS } from "./shared";
const products = [
{
@@ -97,11 +97,11 @@ export function ProductContent({ domain }: { domain: string }) {
}) => (
<NavigationMenuLink asChild key={title}>
<Link
- href={createHref(
- href,
- domain,
- getUtmParams({ domain, utm_content: title }),
- )}
+ href={createHref(href, domain, {
+ ...NAV_UTM_PARAMS,
+ utm_campaign: domain,
+ utm_content: title,
+ })}
className="group relative flex flex-col overflow-hidden rounded-xl border border-neutral-100 bg-neutral-50 dark:border-white/20 dark:bg-white/10"
>
<Grid
@@ -145,11 +145,11 @@ export function ProductContent({ domain }: { domain: string }) {
{largeLinks.map(({ title, description, href, graphic }) => (
<NavigationMenuLink asChild key={title}>
<Link
- href={createHref(
- href,
- domain,
- getUtmParams({ domain, utm_content: title }),
- )}
+ href={createHref(href, domain, {
+ ...NAV_UTM_PARAMS,
+ utm_campaign: domain,
+ utm_content: title,
+ })}
className="group relative flex flex-col justify-center rounded-xl border border-neutral-100 bg-neutral-50 transition-colors duration-150 hover:bg-neutral-100 active:bg-neutral-200 dark:border-white/20 dark:bg-white/10 dark:hover:bg-white/15 dark:active:bg-white/20"
>
<Grid
diff --git a/packages/ui/src/nav/content/resources-content.tsx b/packages/ui/src/nav/content/resources-content.tsx
index 1cba2fcadd..ba6cefea6e 100644
--- a/packages/ui/src/nav/content/resources-content.tsx
+++ b/packages/ui/src/nav/content/resources-content.tsx
@@ -6,8 +6,8 @@ import { Grid } from "../../grid";
import { Book2Fill, LifeRingFill } from "../../icons";
import {
ContentLinkCard,
+ NAV_UTM_PARAMS,
contentHeadingClassName,
- getUtmParams,
} from "./shared";
const mainLinks = [
@@ -37,11 +37,11 @@ export function ResourcesContent({ domain }: { domain: string }) {
<NavigationMenuLink key={title} asChild>
<Link
key={title}
- href={createHref(
- href,
- domain,
- getUtmParams({ domain, utm_content: title }),
- )}
+ href={createHref(href, domain, {
+ ...NAV_UTM_PARAMS,
+ utm_campaign: domain,
+ utm_content: title,
+ })}
className={cn(
"group relative isolate z-0 flex flex-col justify-between overflow-hidden rounded-xl border border-neutral-100 bg-neutral-50 px-5 py-4 transition-colors duration-75",
"dark:border-white/20 dark:bg-neutral-900",
@@ -86,11 +86,11 @@ export function ResourcesContent({ domain }: { domain: string }) {
<ContentLinkCard
key={href}
className="-mx-2"
- href={createHref(
- href,
- domain,
- getUtmParams({ domain, utm_content: title }),
- )}
+ href={createHref(href, domain, {
+ ...NAV_UTM_PARAMS,
+ utm_campaign: domain,
+ utm_content: title,
+ })}
icon={
<div className="shrink-0 rounded-md border border-neutral-200 bg-white/50 p-2.5 dark:border-white/20 dark:bg-white/10">
<Icon className="size-4 text-neutral-600 transition-colors dark:text-white/60" />
@@ -112,11 +112,11 @@ export function ResourcesContent({ domain }: { domain: string }) {
<ContentLinkCard
key={href}
className="-mx-2"
- href={createHref(
- href,
- domain,
- getUtmParams({ domain, utm_content: title }),
- )}
+ href={createHref(href, domain, {
+ ...NAV_UTM_PARAMS,
+ utm_campaign: domain,
+ utm_content: title,
+ })}
icon={
<div className="shrink-0 rounded-md border border-neutral-200 bg-white/50 p-2.5 dark:border-white/20 dark:bg-white/10">
<Icon className="size-4 text-neutral-600 transition-colors dark:text-white/60" />
diff --git a/packages/ui/src/nav/content/shared.tsx b/packages/ui/src/nav/content/shared.tsx
index 7f10cac4e7..5c4305ca7d 100644
--- a/packages/ui/src/nav/content/shared.tsx
+++ b/packages/ui/src/nav/content/shared.tsx
@@ -10,15 +10,10 @@ export const contentHeadingClassName =
export const contentLinkCardClassName =
"group rounded-[8px] p-2 transition-colors hover:bg-neutral-50 active:bg-neutral-100 dark:hover:bg-white/[0.15] dark:active:bg-white/20";
-export const getUtmParams = ({
- domain,
- ...rest
-}: { domain: string } & Record<string, string>) => ({
+export const NAV_UTM_PARAMS = {
utm_source: "Custom Domain",
utm_medium: "Navbar",
- utm_campaign: domain,
- ...rest,
-});
+};
export function ContentLinkCard({
icon,
diff --git a/packages/ui/src/nav/content/solutions-content.tsx b/packages/ui/src/nav/content/solutions-content.tsx
index df6557cb51..cc06c808b7 100644
--- a/packages/ui/src/nav/content/solutions-content.tsx
+++ b/packages/ui/src/nav/content/solutions-content.tsx
@@ -6,8 +6,8 @@ import { Grid } from "../../grid";
import { DiamondTurnRightFill, MicrophoneFill, UsersFill } from "../../icons";
import {
ContentLinkCard,
+ NAV_UTM_PARAMS,
contentHeadingClassName,
- getUtmParams,
} from "./shared";
const mainLinks = [
@@ -41,11 +41,11 @@ export function SolutionsContent({ domain }: { domain: string }) {
<NavigationMenuLink key={title} asChild>
<Link
key={title}
- href={createHref(
- href,
- domain,
- getUtmParams({ domain, utm_content: title }),
- )}
+ href={createHref(href, domain, {
+ ...NAV_UTM_PARAMS,
+ utm_campaign: domain,
+ utm_content: title,
+ })}
className={cn(
"group relative isolate z-0 flex flex-col justify-between overflow-hidden rounded-xl border border-neutral-100 bg-neutral-50 px-5 py-4 transition-colors duration-75",
"dark:border-white/20 dark:bg-neutral-900",
@@ -87,11 +87,11 @@ export function SolutionsContent({ domain }: { domain: string }) {
<ContentLinkCard
key={href}
className="-mx-2"
- href={createHref(
- href,
- domain,
- getUtmParams({ domain, utm_content: title }),
- )}
+ href={createHref(href, domain, {
+ ...NAV_UTM_PARAMS,
+ utm_campaign: domain,
+ utm_content: title,
+ })}
icon={
<div className="shrink-0 rounded-[10px] border border-neutral-200 bg-white/50 p-1 dark:border-white/20 dark:bg-white/10">
<Icon