The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improve useDomains
Steven Tey8f33d77fe2c5
diff --git a/apps/web/lib/swr/use-domains.ts b/apps/web/lib/swr/use-domains.tsindex e877885158..777579efa4 100644--- a/apps/web/lib/swr/use-domains.ts+++ b/apps/web/lib/swr/use-domains.ts@@ -3,9 +3,11 @@ import { useRouterStuff } from "@dub/ui";import {DUB_DOMAINS,DUB_WORKSPACE_ID,+ PREMIUM_SHORT_DOMAIN,SHORT_DOMAIN,fetcher,} from "@dub/utils";+import { useMemo } from "react";import useSWR from "swr";import useDefaultDomains from "./use-default-domains";import useWorkspace from "./use-workspace";@@ -51,11 +53,19 @@ export default function useDomains({...(workspaceId === `ws_${DUB_WORKSPACE_ID}` ? [] : activeDefaultDomains),];- const primaryDomain =- activeWorkspaceDomains && activeWorkspaceDomains.length > 0- ? activeWorkspaceDomains.find((domain) => domain.primary)?.slug ||+ const primaryDomain = useMemo(() => {+ if (activeWorkspaceDomains && activeWorkspaceDomains.length > 0) {+ return (+ activeWorkspaceDomains.find(({ primary }) => primary)?.slug ||activeWorkspaceDomains[0].slug- : SHORT_DOMAIN;+ );+ } else if (+ activeDefaultDomains.find(({ slug }) => slug === PREMIUM_SHORT_DOMAIN)+ ) {+ return PREMIUM_SHORT_DOMAIN;+ }+ return SHORT_DOMAIN;+ }, [activeDefaultDomains, activeWorkspaceDomains]);return {activeWorkspaceDomains, // active workspace domainsdiff --git a/packages/utils/src/constants/dub-domains.ts b/packages/utils/src/constants/dub-domains.tsindex c055c901f4..c3b7d65ad2 100644--- a/packages/utils/src/constants/dub-domains.ts+++ b/packages/utils/src/constants/dub-domains.ts@@ -18,7 +18,7 @@ export const DUB_DOMAINS = [id: "clxp3lfsb00011na8tfs7t0lx",slug: "dub.link",verified: true,- primary: false,+ primary: true,archived: false,placeholder: "https://dub.co/help/article/what-is-dub",allowedHostnames: [],diff --git a/packages/utils/src/constants/main.ts b/packages/utils/src/constants/main.tsindex c26b521b8f..ffb0e86588 100644--- a/packages/utils/src/constants/main.ts+++ b/packages/utils/src/constants/main.ts@@ -3,6 +3,8 @@ export const APP_NAME = process.env.NEXT_PUBLIC_APP_NAME || "Dub.co";export const SHORT_DOMAIN =process.env.NEXT_PUBLIC_APP_SHORT_DOMAIN || "dub.sh";+export const PREMIUM_SHORT_DOMAIN = "dub.link";+export const HOME_DOMAIN = `https://${process.env.NEXT_PUBLIC_APP_DOMAIN}`;export const APP_HOSTNAMES = new Set([