The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Improve domains implementation
Steven Tey3c3f51e0151d
diff --git a/apps/web/app/api/domains/[domain]/exists/route.ts b/apps/web/app/api/domains/[domain]/exists/route.tsindex e9b1d5c76c..0e442d6c8d 100644--- a/apps/web/app/api/domains/[domain]/exists/route.ts+++ b/apps/web/app/api/domains/[domain]/exists/route.ts@@ -5,9 +5,6 @@ import { NextResponse } from "next/server";// GET /api/domains/[domain]/exists – check if a domain existsexport const GET = withSession(async ({ params }) => {const { domain } = params;-- // This is used for project creation only, if you add a domain within an existing project,- // use the /api/projects/[slug]/domains/[domain]/exists endpoint insteadconst exists = await domainExists(domain);if (exists) {return NextResponse.json(1);diff --git a/apps/web/app/api/projects/[slug]/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.tssimilarity index 93%rename from apps/web/app/api/projects/[slug]/domains/[domain]/route.tsrename to apps/web/app/api/domains/[domain]/route.tsindex 53107c5e7e..28842f22e1 100644--- a/apps/web/app/api/projects/[slug]/domains/[domain]/route.ts+++ b/apps/web/app/api/domains/[domain]/route.ts@@ -11,7 +11,7 @@ import prisma from "@/lib/prisma";import { DUB_PROJECT_ID, isDubDomain } from "@dub/utils";import { NextResponse } from "next/server";-// GET /api/projects/[slug]/domains/[domain] – get a project's domain+// GET /api/domains/[domain] – get a project's domainexport const GET = withAuth(async ({ domain, project }) => {if (isDubDomain(domain) && project.id !== DUB_PROJECT_ID) {return new Response("Domain does not belong to project.", {@@ -42,7 +42,7 @@ export const GET = withAuth(async ({ domain, project }) => {});});-// PUT /api/projects/[slug]/domains/[domain] – edit a project's domain+// PUT /api/domains/[domain] – edit a project's domainexport const PUT = withAuth(async ({ req, project, domain }) => {const {slug: newDomain,@@ -130,7 +130,7 @@ export const PUT = withAuth(async ({ req, project, domain }) => {return NextResponse.json(response);});-// DELETE /api/projects/[slug]/domains/[domain] - delete a project's domain+// DELETE /api/domains/[domain] - delete a project's domainexport const DELETE = withAuth(async ({ domain, project }) => {if (isDubDomain(domain) && project.id !== DUB_PROJECT_ID) {return new Response("Domain does not belong to project.", {diff --git a/apps/web/app/api/projects/[slug]/domains/[domain]/verify/route.ts b/apps/web/app/api/domains/[domain]/verify/route.tssimilarity index 96%rename from apps/web/app/api/projects/[slug]/domains/[domain]/verify/route.tsrename to apps/web/app/api/domains/[domain]/verify/route.tsindex 54ad42a754..331e9e9a58 100644--- a/apps/web/app/api/projects/[slug]/domains/[domain]/verify/route.ts+++ b/apps/web/app/api/domains/[domain]/verify/route.ts@@ -8,7 +8,7 @@ import prisma from "@/lib/prisma";import { DomainVerificationStatusProps } from "@/lib/types";import { NextResponse } from "next/server";-// GET /api/projects/[slug]/domains/[domain]/verify - get domain verification status+// GET /api/domains/[domain]/verify - get domain verification statusexport const GET = withAuth(async ({ domain }) => {let status: DomainVerificationStatusProps = "Valid Configuration";diff --git a/apps/web/app/api/projects/[slug]/domains/default/route.ts b/apps/web/app/api/domains/default/route.tssimilarity index 91%rename from apps/web/app/api/projects/[slug]/domains/default/route.tsrename to apps/web/app/api/domains/default/route.tsindex 09320c00f7..790dd79a5b 100644--- a/apps/web/app/api/projects/[slug]/domains/default/route.ts+++ b/apps/web/app/api/domains/default/route.ts@@ -4,7 +4,7 @@ import z from "@/lib/zod";import { DUB_DOMAINS_ARRAY } from "@dub/utils";import { NextResponse } from "next/server";-// GET /api/projects/[slug]/domains/default - get default domains+// GET /api/domains/default - get default domainsexport const GET = withAuth(async ({ project }) => {const defaultDomains = await prisma.defaultDomains.findUnique({where: {@@ -36,7 +36,7 @@ const updateDefaultDomainsSchema = z.object({defaultDomains: z.array(z.enum(DUB_DOMAINS_ARRAY as [string, ...string[]])),});-// PUT /api/projects/[slug]/domains/default - edit default domains+// PUT /api/domains/default - edit default domainsexport const PUT = withAuth(async ({ req, project }) => {const { defaultDomains } = await updateDefaultDomainsSchema.parseAsync(await req.json(),diff --git a/apps/web/app/api/projects/[slug]/domains/route.ts b/apps/web/app/api/domains/route.tssimilarity index 80%rename from apps/web/app/api/projects/[slug]/domains/route.tsrename to apps/web/app/api/domains/route.tsindex 109664004a..622d3a28f3 100644--- a/apps/web/app/api/projects/[slug]/domains/route.ts+++ b/apps/web/app/api/domains/route.ts@@ -8,7 +8,7 @@ import { withAuth } from "@/lib/auth";import prisma from "@/lib/prisma";import { NextResponse } from "next/server";-// GET /api/projects/[slug]/domains – get all domains for a project+// GET /api/domains – get all domains for a projectexport const GET = withAuth(async ({ project }) => {const domains = await prisma.domain.findMany({where: {@@ -28,7 +28,7 @@ export const GET = withAuth(async ({ project }) => {return NextResponse.json(domains);});-// POST /api/projects/[slug]/domains - add a domain+// POST /api/domains - add a domainexport const POST = withAuth(async ({ req, project }) => {const { slug: domain, primary, archived, target, type } = await req.json();@@ -52,12 +52,12 @@ export const POST = withAuth(async ({ req, project }) => {return new Response(vercelResponse.error.message, { status: 422 });}/*- If the domain is being added, we need to:- 1. Add the domain to Vercel- 2. If there's a landing page set, update the root domain in Redis- 3. If the domain is being set as the primary domain, set all other domains to not be the primary domain- 4. Add the domain to the database along with its primary status- */+ If the domain is being added, we need to:+ 1. Add the domain to Vercel+ 2. If there's a landing page set, update the root domain in Redis+ 3. If the domain is being set as the primary domain, set all other domains to not be the primary domain+ 4. Add the domain to the database along with its primary status+ */const response = await Promise.all([prisma.domain.create({data: {diff --git a/apps/web/app/api/projects/[slug]/(old)/domains/[domain]/exists/route.ts b/apps/web/app/api/projects/[slug]/(old)/domains/[domain]/exists/route.tsnew file mode 100644index 0000000000..beda147b99--- /dev/null+++ b/apps/web/app/api/projects/[slug]/(old)/domains/[domain]/exists/route.ts@@ -0,0 +1 @@+export * from "../../../../../../domains/[domain]/exists/route";diff --git a/apps/web/app/api/projects/[slug]/(old)/domains/[domain]/route.ts b/apps/web/app/api/projects/[slug]/(old)/domains/[domain]/route.tsnew file mode 100644index 0000000000..4d1b9bf962--- /dev/null+++ b/apps/web/app/api/projects/[slug]/(old)/domains/[domain]/route.ts@@ -0,0 +1 @@+export * from "../../../../../domains/[domain]/route";diff --git a/apps/web/app/api/projects/[slug]/(old)/domains/[domain]/verify/route.ts b/apps/web/app/api/projects/[slug]/(old)/domains/[domain]/verify/route.tsnew file mode 100644index 0000000000..d7fcffda78--- /dev/null+++ b/apps/web/app/api/projects/[slug]/(old)/domains/[domain]/verify/route.ts@@ -0,0 +1 @@+export * from "../../../../../../domains/[domain]/verify/route";diff --git a/apps/web/app/api/projects/[slug]/(old)/domains/default/route.ts b/apps/web/app/api/projects/[slug]/(old)/domains/default/route.tsnew file mode 100644index 0000000000..d638feff0b--- /dev/null+++ b/apps/web/app/api/projects/[slug]/(old)/domains/default/route.ts@@ -0,0 +1 @@+export * from "../../../../../domains/default/route";diff --git a/apps/web/app/api/projects/[slug]/(old)/domains/route.ts b/apps/web/app/api/projects/[slug]/(old)/domains/route.tsnew file mode 100644index 0000000000..d7e2d6901e--- /dev/null+++ b/apps/web/app/api/projects/[slug]/(old)/domains/route.ts@@ -0,0 +1 @@+export * from "../../../../domains/route";diff --git a/apps/web/app/api/projects/[slug]/domains/[domain]/exists/route.ts b/apps/web/app/api/projects/[slug]/domains/[domain]/exists/route.tsdeleted file mode 100644index 34471cef6b..0000000000--- a/apps/web/app/api/projects/[slug]/domains/[domain]/exists/route.ts+++ /dev/null@@ -1,13 +0,0 @@-import { domainExists } from "@/lib/api/domains";-import { withAuth } from "@/lib/auth";-import { NextResponse } from "next/server";--// GET /api/projects/[slug]/domains/[domain]/exists – check if a domain exists-export const GET = withAuth(async ({ domain }) => {- const exists = await domainExists(domain);- if (exists) {- return NextResponse.json(1);- } else {- return NextResponse.json(0);- }-});diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/domains/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/domains/page-client.tsxindex 6006f1a4d8..6386ce5625 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/domains/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/domains/page-client.tsx@@ -25,7 +25,7 @@ export default function ProjectDomainsClient() {const { id: projectId } = useProject();const { AddEditDomainModal, AddDomainButton } = useAddEditDomainModal();- const { projectDomains, archivedProjectDomains } = useDomains();+ const { activeProjectDomains, archivedProjectDomains } = useDomains();const [showArchivedDomains, setShowArchivedDomains] = useState(false);return (@@ -55,10 +55,10 @@ export default function ProjectDomainsClient() {</MaxWidthWrapper></div><MaxWidthWrapper className="py-10">- {projectDomains ? (- projectDomains.length > 0 ? (+ {activeProjectDomains ? (+ activeProjectDomains.length > 0 ? (<ul className="grid grid-cols-1 gap-3">- {projectDomains.map((domain) => (+ {activeProjectDomains.map((domain) => (<li key={domain.slug}><DomainCard props={domain} /></li>@@ -113,7 +113,7 @@ const DefaultDomains = () => {onSubmit={async (e) => {e.preventDefault();setSubmitting(true);- fetch(`/api/projects/${slug}/domains/default`, {+ fetch(`/api/domains/default?projectSlug=${slug}`, {method: "PUT",body: JSON.stringify({ defaultDomains }),}).then(async (res) => {diff --git a/apps/web/lib/swr/use-default-domains.ts b/apps/web/lib/swr/use-default-domains.tsindex b2495fdcf8..ce5be68405 100644--- a/apps/web/lib/swr/use-default-domains.ts+++ b/apps/web/lib/swr/use-default-domains.ts@@ -8,7 +8,7 @@ export default function useDefaultDomains() {};const { data, error, mutate } = useSWR<string[]>(- slug && `/api/projects/${slug}/domains/default`,+ slug && `/api/domains/default?projectSlug=${slug}`,fetcher,{dedupingInterval: 60000,diff --git a/apps/web/lib/swr/use-domains.ts b/apps/web/lib/swr/use-domains.tsindex 49ef000508..c667404bc3 100644--- a/apps/web/lib/swr/use-domains.ts+++ b/apps/web/lib/swr/use-domains.ts@@ -10,53 +10,50 @@ export default function useDomains({ domain }: { domain?: string } = {}) {};const { data, error, mutate } = useSWR<DomainProps[]>(- slug && `/api/projects/${slug}/domains`,+ slug && `/api/domains?projectSlug=${slug}`,fetcher,{dedupingInterval: 60000,},);+ const { defaultDomains: projectDefaultDomains } = useDefaultDomains();const allProjectDomains = data || [];- const projectDomains = data?.filter((domain) => !domain.archived);+ const activeProjectDomains = data?.filter((domain) => !domain.archived);const archivedProjectDomains = data?.filter((domain) => domain.archived);- const { defaultDomains: projectDefaultDomains } = useDefaultDomains();-- const defaultDomains =+ const activeDefaultDomains =(projectDefaultDomains &&DUB_DOMAINS.filter((d) => projectDefaultDomains?.includes(d.slug))) ||DUB_DOMAINS;const allDomains = [- ...(data || []),- ...(slug !== "dub" ? defaultDomains : []),+ ...allProjectDomains,+ ...(slug === "dub" ? [] : DUB_DOMAINS),];const allActiveDomains = [- ...(projectDomains || []),- ...(slug !== "dub" ? defaultDomains : []),+ ...(activeProjectDomains || []),+ ...(slug === "dub" ? [] : activeDefaultDomains),];const primaryDomain =- projectDomains?.find((domain) => domain.primary)?.slug ||- defaultDomains.find((domain) => domain.primary)?.slug ||+ activeProjectDomains?.find((domain) => domain.primary)?.slug ||+ activeDefaultDomains.find((domain) => domain.primary)?.slug ||SHORT_DOMAIN;const verified = domain? // If a domain is passed, check if it's verified- [...allActiveDomains, ...(archivedProjectDomains || [])].find(- (d) => d.slug === domain,- )?.verified+ allDomains.find((d) => d.slug === domain)?.verified: // If no domain is passed, check if any of the project domains are verified- projectDomains?.some((d) => d.verified);+ activeProjectDomains?.some((d) => d.verified);return {- projectDomains,- archivedProjectDomains,- defaultDomains,- allProjectDomains,- allActiveDomains,- allDomains,+ activeProjectDomains, // active project domains+ archivedProjectDomains, // archived project domains+ activeDefaultDomains, // active default Dub domains+ allProjectDomains, // all project domains (active + archived)+ allActiveDomains, // all active domains (active project domains + active default Dub domains)+ allDomains, // all domains (all project domains + all default Dub domains)primaryDomain,verified,loading: !data && !error,diff --git a/apps/web/ui/domains/domain-card.tsx b/apps/web/ui/domains/domain-card.tsxindex fca0a767ad..4996b36c7d 100644--- a/apps/web/ui/domains/domain-card.tsx+++ b/apps/web/ui/domains/domain-card.tsx@@ -35,7 +35,7 @@ export default function DomainCard({ props }: { props: DomainProps }) {}>(slug &&!showLinkQRModal && // Don't fetch if QR modal is open – it'll cause it to re-render- `/api/projects/${slug}/domains/${domain}/verify`,+ `/api/domains/${domain}/verify?projectSlug=${slug}`,fetcher,{revalidateOnMount: true,@@ -111,7 +111,7 @@ export default function DomainCard({ props }: { props: DomainProps }) {variant="secondary"loading={isValidating}onClick={() => {- mutate(`/api/projects/${slug}/domains/${domain}/verify`);+ mutate(`/api/domains/${domain}/verify?projectSlug=${slug}`);}}/><Buttondiff --git a/apps/web/ui/links/link-filters.tsx b/apps/web/ui/links/link-filters.tsxindex 8322cf5742..1ada964d3d 100644--- a/apps/web/ui/links/link-filters.tsx+++ b/apps/web/ui/links/link-filters.tsx@@ -1,8 +1,9 @@+import useDefaultDomains from "@/lib/swr/use-default-domains";import useDomains from "@/lib/swr/use-domains";import useLinks from "@/lib/swr/use-links";import useLinksCount from "@/lib/swr/use-links-count";import useTags from "@/lib/swr/use-tags";-import { TagProps } from "@/lib/types";+import { DomainProps, TagProps } from "@/lib/types";import TagBadge from "@/ui/links/tag-badge";import { useAddEditTagModal } from "@/ui/modals/add-edit-tag-modal";import { Delete, ThreeDots } from "@/ui/shared/icons";@@ -11,19 +12,20 @@ import {Copy,LoadingCircle,LoadingSpinner,- NumberTooltip,Popover,Switch,Tick,useRouterStuff,+ useToastWithUndo,} from "@dub/ui";import {SWIPE_REVEAL_ANIMATION_SETTINGS,+ isDubDomain,nFormatter,truncate,} from "@dub/utils";import { AnimatePresence, motion } from "framer-motion";-import { ChevronRight, Edit3, Search, XCircle } from "lucide-react";+import { Archive, ChevronRight, Edit3, Search, XCircle } from "lucide-react";import { useSession } from "next-auth/react";import {useParams,@@ -187,7 +189,7 @@ const DomainsFilter = () => {const searchParams = useSearchParams();const { queryParams } = useRouterStuff();const { data: domains } = useLinksCount({ groupBy: "domain" });- const { primaryDomain } = useDomains();+ const { allActiveDomains } = useDomains();const [collapsed, setCollapsed] = useState(false);const [showMore, setShowMore] = useState(false);@@ -201,18 +203,13 @@ const DomainsFilter = () => {});const options = useMemo(() => {- return domains?.length === 0- ? [- {- value: primaryDomain,- count: 0,- },- ]- : domains?.map(({ domain, _count }) => ({- value: domain,- count: _count,- })) || [];- }, [domains, primaryDomain]);+ return allActiveDomains+ .map((domain) => ({+ ...domain,+ count: domains.find(({ domain: d }) => d === domain.slug)?._count || 0,+ }))+ .sort((a, b) => b.count - a.count);+ }, [allActiveDomains, domains]);return (<fieldset className="overflow-hidden py-6">@@ -237,42 +234,35 @@ const DomainsFilter = () => {className="mt-4 grid gap-2"{...SWIPE_REVEAL_ANIMATION_SETTINGS}>- {options- .slice(0, showMore ? options.length : 4)- .map(({ value, count }) => (- <div- key={value}- className="relative flex cursor-pointer items-center space-x-3 rounded-md bg-gray-50 transition-all hover:bg-gray-100"+ {options.slice(0, showMore ? options.length : 4).map((domain) => (+ <div+ key={domain.id}+ className="group relative flex cursor-pointer items-center space-x-3 rounded-md bg-gray-50 transition-all hover:bg-gray-100"+ >+ <input+ id={domain.id}+ name={domain.slug}+ checked={searchParams?.get("domain") === domain.slug}+ onChange={() => {+ queryParams({+ set: {+ domain: domain.slug,+ },+ del: "page",+ });+ }}+ type="radio"+ className="ml-3 h-4 w-4 cursor-pointer rounded-full border-gray-300 text-black focus:outline-none focus:ring-0"+ />+ <label+ htmlFor={domain.slug}+ className="flex w-full cursor-pointer justify-between px-3 py-2 pl-0 text-sm font-medium text-gray-700">- <input- id={value}- name={value}- checked={- searchParams?.get("domain") === value ||- domains?.length <= 1- }- onChange={() => {- queryParams({- set: {- domain: value,- },- del: "page",- });- }}- type="radio"- className="ml-3 h-4 w-4 cursor-pointer rounded-full border-gray-300 text-black focus:outline-none focus:ring-0"- />- <label- htmlFor={value}- className="flex w-full cursor-pointer justify-between px-3 py-2 pl-0 text-sm font-medium text-gray-700"- >- <p>{truncate(punycode.toUnicode(value || ""), 24)}</p>- <NumberTooltip value={count} unit="links">- <p className="text-gray-500">{nFormatter(count)}</p>- </NumberTooltip>- </label>- </div>- ))}+ <p>{truncate(punycode.toUnicode(domain.slug || ""), 24)}</p>+ <DomainPopover domain={domain} count={domain.count} />+ </label>+ </div>+ ))}{options.length > 4 && (<buttononClick={() => setShowMore(!showMore)}@@ -288,6 +278,172 @@ const DomainsFilter = () => {);};+const DomainPopover = ({+ domain,+ count,+}: {+ domain: DomainProps;+ count: number;+}) => {+ const { slug } = useParams() as { slug?: string };+ const [openPopover, setOpenPopover] = useState(false);+ const [processing, setProcessing] = useState(false);+ const { mutate: mutateDomains } = useDomains();+ const { defaultDomains, mutate: mutateDefaultDomains } = useDefaultDomains();++ const { AddEditDomainModal, setShowAddEditDomainModal } =+ useAddEditDomainModal({+ props: domain,+ });++ const toastWithUndo = useToastWithUndo();++ const archiveProjectDomain = (archive: boolean) => {+ return fetch(`/api/domains/${domain.slug}?projectSlug=${slug}`, {+ method: "PUT",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ ...domain,+ archived: archive,+ }),+ });+ };++ const archiveDefaultDomain = (archive: boolean) => {+ const newDefaultDomains = archive+ ? defaultDomains?.filter((d) => d !== domain.slug)+ : [...(defaultDomains || []), domain.slug];+ return fetch(`/api/domains/default?projectSlug=${slug}`, {+ method: "PUT",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ defaultDomains: newDefaultDomains,+ }),+ });+ };++ const handleArchiveRequest = async () => {+ setProcessing(true);+ if (isDubDomain(domain.slug)) {+ const res = await archiveDefaultDomain(true);+ if (res.ok) {+ await mutateDefaultDomains();+ toastWithUndo({+ id: "domain-archive-undo-toast",+ message: `Successfully archived domain!`,+ undo: async () => {+ toast.promise(archiveDefaultDomain(false), {+ loading: "Undo in progress...",+ error: "Failed to roll back changes. An error occurred.",+ success: async () => {+ await mutateDefaultDomains();+ return "Undo successful! Changes reverted.";+ },+ });+ },+ duration: 5000,+ });+ } else {+ const { error } = await res.json();+ setProcessing(false);+ toast.error(error.message);+ }+ } else {+ const res = await archiveProjectDomain(true);+ if (res.ok) {+ await mutateDomains();+ toastWithUndo({+ id: "domain-archive-undo-toast",+ message: `Successfully archived domain!`,+ undo: async () => {+ toast.promise(archiveProjectDomain(false), {+ loading: "Undo in progress...",+ error: "Failed to roll back changes. An error occurred.",+ success: async () => {+ await mutateDomains();+ return "Undo successful! Changes reverted.";+ },+ });+ },+ duration: 5000,+ });+ } else {+ const { error } = await res.json();+ setProcessing(false);+ toast.error(error.message);+ }+ }+ };++ return processing ? (+ <div className="flex h-6 items-center justify-center">+ <LoadingCircle />+ </div>+ ) : (+ <>+ <Popover+ content={+ <div className="grid w-full gap-px p-2 sm:w-48">+ {(!isDubDomain(domain.slug) || slug === "dub") && (+ <Button+ type="button"+ text="Edit"+ variant="outline"+ onClick={() => {+ setOpenPopover(false);+ setShowAddEditDomainModal(true);+ }}+ icon={<Edit3 className="h-4 w-4" />}+ className="h-9 w-full justify-start px-2 font-medium"+ />+ )}+ <Button+ type="button"+ text="Archive"+ variant="outline"+ onClick={() => {+ setOpenPopover(false);+ handleArchiveRequest();+ }}+ icon={<Archive className="h-4 w-4" />}+ className="h-9 w-full justify-start px-2 font-medium"+ />+ </div>+ }+ align="end"+ openPopover={openPopover}+ setOpenPopover={setOpenPopover}+ >+ <button+ type="button"+ onClick={() => setOpenPopover(!openPopover)}+ className={`${+ openPopover ? "bg-gray-200" : "hover:bg-gray-200"+ } -mr-1 flex h-6 w-5 items-center justify-center rounded-md transition-colors`}+ >+ <ThreeDots+ className={`h-4 w-4 text-gray-500 ${+ openPopover ? "" : "hidden group-hover:block"+ }`}+ />+ <p+ className={`text-gray-500 ${+ openPopover ? "hidden" : "group-hover:hidden"+ }`}+ >+ {nFormatter(count)}+ </p>+ </button>+ </Popover>+ <AddEditDomainModal />+ </>+ );+};+const TagsFilter = ({tags,tagsCount,diff --git a/apps/web/ui/modals/accept-invite-modal.tsx b/apps/web/ui/modals/accept-invite-modal.tsxindex 755af8c72e..4f47f88b9f 100644--- a/apps/web/ui/modals/accept-invite-modal.tsx+++ b/apps/web/ui/modals/accept-invite-modal.tsx@@ -58,7 +58,7 @@ function AcceptInviteModal({await Promise.all([mutate("/api/projects"),mutate(`/api/projects/${slug}`),- mutate(`/api/projects/${slug}/domains`),+ mutate(`/api/domains?projectSlug=${slug}`),]);setShowAcceptInviteModal(false);toast.success("You now are a part of this project!");diff --git a/apps/web/ui/modals/add-edit-domain-modal/index.tsx b/apps/web/ui/modals/add-edit-domain-modal/index.tsxindex f33ba3d3d1..cd102d3037 100644--- a/apps/web/ui/modals/add-edit-domain-modal/index.tsx+++ b/apps/web/ui/modals/add-edit-domain-modal/index.tsx@@ -91,13 +91,13 @@ function AddEditDomainModal({if (props) {return {method: "PUT",- url: `/api/projects/${slug}/domains/${domain}`,+ url: `/api/domains/${domain}?projectSlug=${slug}`,successMessage: "Successfully updated domain!",};} else {return {method: "POST",- url: `/api/projects/${slug}/domains`,+ url: `/api/domains?projectSlug=${slug}`,successMessage: "Successfully added domain!",};}@@ -105,15 +105,11 @@ function AddEditDomainModal({async function deleteDomain() {setDeleting(true);- fetch(`/api/projects/${slug}/domains/${domain}`, {+ fetch(`/api/domains/${domain}?projectSlug=${slug}`, {method: "DELETE",}).then(async (res) => {if (res.status === 200) {- await mutate(- (key) => typeof key === "string" && key.startsWith(`/api/projects`),- undefined,- { revalidate: true },- );+ await mutate(`/api/domains?projectSlug=${slug}`);setShowAddEditDomainModal(false);toast.success("Successfully deleted domain!");} else {@@ -157,7 +153,7 @@ function AddEditDomainModal({body: JSON.stringify(data),}).then(async (res) => {if (res.status === 200) {- await mutate(`/api/projects/${slug}/domains`);+ await mutate(`/api/domains?projectSlug=${slug}`);setShowAddEditDomainModal(false);toast.success(endpoint.successMessage);if (!props) {diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsxindex 8bd1262cf1..83d534af5d 100644--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx@@ -82,7 +82,7 @@ function AddEditLinkModal({const {allActiveDomains: domains,primaryDomain,- defaultDomains,+ activeDefaultDomains,} = useDomains();const [data, setData] = useState<LinkWithTagsProps>(@@ -116,10 +116,10 @@ function AddEditLinkModal({// when someone pastes a URLif (showAddEditLinkModal && url.length > 0) {// if it's a new link and there are matching default domains, set it as the domain- if (!props && defaultDomains) {+ if (!props && activeDefaultDomains) {const urlDomain = getDomainWithoutWWW(url) || "";- const defaultDomain = defaultDomains.find(({ allowedHostnames }) =>- allowedHostnames.includes(urlDomain),+ const defaultDomain = activeDefaultDomains.find(+ ({ allowedHostnames }) => allowedHostnames.includes(urlDomain),);if (defaultDomain) {setData((prev) => ({ ...prev, domain: defaultDomain.slug }));diff --git a/apps/web/ui/modals/import-bitly-modal.tsx b/apps/web/ui/modals/import-bitly-modal.tsxindex a293bd43c7..a7fa1a8d83 100644--- a/apps/web/ui/modals/import-bitly-modal.tsx+++ b/apps/web/ui/modals/import-bitly-modal.tsx@@ -132,7 +132,7 @@ function ImportBitlyModal({}),}).then(async (res) => {if (res.ok) {- await mutate(`/api/projects/${slug}/domains`);+ await mutate(`/api/domains?projectSlug=${slug}`);router.push(`/${slug}`);} else {setImporting(false);diff --git a/apps/web/ui/modals/import-rebrandly-modal.tsx b/apps/web/ui/modals/import-rebrandly-modal.tsxindex 96b425689b..7bb8a42414 100644--- a/apps/web/ui/modals/import-rebrandly-modal.tsx+++ b/apps/web/ui/modals/import-rebrandly-modal.tsx@@ -140,7 +140,7 @@ function ImportRebrandlyModal({}),}).then(async (res) => {if (res.ok) {- await mutate(`/api/projects/${slug}/domains`);+ await mutate(`/api/domains?projectSlug=${slug}`);router.push(`/${slug}`);} else {setImporting(false);diff --git a/apps/web/ui/modals/import-short-modal.tsx b/apps/web/ui/modals/import-short-modal.tsxindex 2afe63720d..8a09f29144 100644--- a/apps/web/ui/modals/import-short-modal.tsx+++ b/apps/web/ui/modals/import-short-modal.tsx@@ -129,7 +129,7 @@ function ImportShortModal({}),}).then(async (res) => {if (res.ok) {- await mutate(`/api/projects/${slug}/domains`);+ await mutate(`/api/domains?projectSlug=${slug}`);router.push(`/${slug}`);} else {setImporting(false);diff --git a/apps/web/ui/projects/project-card.tsx b/apps/web/ui/projects/project-card.tsxindex 69dee9b013..cc712550bd 100644--- a/apps/web/ui/projects/project-card.tsx+++ b/apps/web/ui/projects/project-card.tsx@@ -33,7 +33,7 @@ export default function ProjectCard({logo,usage,plan,- domains: projectDomains,+ domains: activeProjectDomains,primaryDomain: projectPrimaryDomain,metadata,}: ProjectWithDomainProps) {@@ -52,7 +52,8 @@ export default function ProjectCard({? DUB_DOMAINS.filter((d) => metadata?.defaultDomains?.includes(d.slug)): DUB_DOMAINS;- const domains = projectDomains.length > 0 ? projectDomains : defaultDomains;+ const domains =+ activeProjectDomains.length > 0 ? activeProjectDomains : defaultDomains;const primaryDomain = projectPrimaryDomain || defaultDomains[0];