diff --git a/apps/web/app/api/utm-templates/[id]/route.ts b/apps/web/app/api/utm/[id]/route.ts similarity index 91% rename from apps/web/app/api/utm-templates/[id]/route.ts rename to apps/web/app/api/utm/[id]/route.ts index 039ce7aedd..d58ec51b09 100644 --- a/apps/web/app/api/utm-templates/[id]/route.ts +++ b/apps/web/app/api/utm/[id]/route.ts @@ -1,10 +1,10 @@ import { DubApiError } from "@/lib/api/errors"; import { withWorkspace } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; -import { updateUTMTemplateBodySchema } from "@/lib/zod/schemas/utm-templates"; +import { updateUTMTemplateBodySchema } from "@/lib/zod/schemas/utm"; import { NextResponse } from "next/server"; -// PATCH /api/utm-templates/[id] – update a UTM template +// PATCH /api/utm/[id] – update a UTM template export const PATCH = withWorkspace( async ({ req, params, workspace }) => { const { id } = params; @@ -52,9 +52,7 @@ export const PATCH = withWorkspace( }, ); -export const PUT = PATCH; - -// DELETE /api/utm-templates/[id] – delete a UTM template for a workspace +// DELETE /api/utm/[id] – delete a UTM template for a workspace export const DELETE = withWorkspace( async ({ params, workspace }) => { const { id } = params; diff --git a/apps/web/app/api/utm-templates/route.ts b/apps/web/app/api/utm/route.ts similarity index 90% rename from apps/web/app/api/utm-templates/route.ts rename to apps/web/app/api/utm/route.ts index 0a4057b3f9..49f5e22f08 100644 --- a/apps/web/app/api/utm-templates/route.ts +++ b/apps/web/app/api/utm/route.ts @@ -1,10 +1,10 @@ import { DubApiError } from "@/lib/api/errors"; import { withWorkspace } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; -import { createUTMTemplateBodySchema } from "@/lib/zod/schemas/utm-templates"; +import { createUTMTemplateBodySchema } from "@/lib/zod/schemas/utm"; import { NextResponse } from "next/server"; -// GET /api/utm-templates - get all UTM templates for a workspace +// GET /api/utm - get all UTM templates for a workspace export const GET = withWorkspace( async ({ workspace, headers }) => { const templates = await prisma.utmTemplate.findMany({ @@ -27,7 +27,7 @@ export const GET = withWorkspace( }, ); -// POST /api/utm-templates - create or update a UTM template for a workspace +// POST /api/utm - create a new UTM template for a workspace export const POST = withWorkspace( async ({ req, workspace, session, headers }) => { const props = createUTMTemplateBodySchema.parse(await req.json()); 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.tsx index d05a832b5a..d1922ada51 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 @@ -24,7 +24,7 @@ export default function WorkspaceUtmTemplatesClient() { const { id: workspaceId } = useWorkspace(); const { data: templates, isLoading } = useSWR( - workspaceId && `/api/utm-templates?workspaceId=${workspaceId}`, + workspaceId && `/api/utm?workspaceId=${workspaceId}`, fetcher, { dedupingInterval: 60000, diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/utm/template-card.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/utm/template-card.tsx index 03c32c532f..c555884b86 100644 --- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/utm/template-card.tsx +++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/utm/template-card.tsx @@ -49,12 +49,12 @@ export function TemplateCard({ if (!confirm("Are you sure you want to delete this template?")) return; setProcessing(true); - fetch(`/api/utm-templates/${template.id}?workspaceId=${id}`, { + fetch(`/api/utm/${template.id}?workspaceId=${id}`, { method: "DELETE", }) .then(async (res) => { if (res.ok) { - await mutate(`/api/utm-templates?workspaceId=${id}`); + await mutate(`/api/utm?workspaceId=${id}`); toast.success("Template deleted"); } else { const { error } = await res.json(); diff --git a/apps/web/lib/zod/schemas/utm-templates.ts b/apps/web/lib/zod/schemas/utm.ts similarity index 100% rename from apps/web/lib/zod/schemas/utm-templates.ts rename to apps/web/lib/zod/schemas/utm.ts diff --git a/apps/web/ui/modals/add-edit-utm-template.modal.tsx b/apps/web/ui/modals/add-edit-utm-template.modal.tsx index 2523eec883..1dd2924326 100644 --- a/apps/web/ui/modals/add-edit-utm-template.modal.tsx +++ b/apps/web/ui/modals/add-edit-utm-template.modal.tsx @@ -56,12 +56,12 @@ function AddEditUtmTemplateModal({ id ? { method: "PATCH", - url: `/api/utm-templates/${id}?workspaceId=${workspaceId}`, + url: `/api/utm/${id}?workspaceId=${workspaceId}`, successMessage: "Successfully updated template!", } : { method: "POST", - url: `/api/utm-templates?workspaceId=${workspaceId}`, + url: `/api/utm?workspaceId=${workspaceId}`, successMessage: "Successfully added template!", }, [id], @@ -97,7 +97,7 @@ function AddEditUtmTemplateModal({ utmTemplateName: data.name, }, ); - await mutate(`/api/utm-templates?workspaceId=${workspaceId}`); + await mutate(`/api/utm?workspaceId=${workspaceId}`); toast.success(endpoint.successMessage); setShowAddEditUtmTemplateModal(false); } catch (e) { diff --git a/apps/web/ui/modals/archive-domain-modal.tsx b/apps/web/ui/modals/archive-domain-modal.tsx index 542b43d1a7..d9852c5626 100644 --- a/apps/web/ui/modals/archive-domain-modal.tsx +++ b/apps/web/ui/modals/archive-domain-modal.tsx @@ -64,9 +64,11 @@ function ArchiveDomainModal({ } await mutate( - (key) => - typeof key === "string" && - key.startsWith(`/api/domains?workspaceId=${workspaceId}`), + (key) => typeof key === "string" && key.startsWith("/api/domains"), + undefined, + { + revalidate: true, + }, ); setShowArchiveDomainModal(false); toastWithUndo({ @@ -89,9 +91,9 @@ function ArchiveDomainModal({ error: "Failed to roll back changes. An error occurred.", success: async () => { await mutate( - (key) => - typeof key === "string" && - key.startsWith(`/api/domains?workspaceId=${workspaceId}`), + (key) => typeof key === "string" && key.startsWith("/api/domains"), + undefined, + { revalidate: true }, ); return "Undo successful! Changes reverted."; }, diff --git a/apps/web/ui/modals/link-builder/index.tsx b/apps/web/ui/modals/link-builder/index.tsx index 1a01235d76..fa4749ee11 100644 --- a/apps/web/ui/modals/link-builder/index.tsx +++ b/apps/web/ui/modals/link-builder/index.tsx @@ -273,6 +273,15 @@ function LinkBuilderInner({ ), // Mutate workspace to update usage stats mutate(`/api/workspaces/${slug}`), + // if updating root domain link, mutate domains as well + key === "_root" && + mutate( + (key) => + typeof key === "string" && + key.startsWith("/api/domains"), + undefined, + { revalidate: true }, + ), ]); const data = await res.json(); posthog.capture( diff --git a/apps/web/ui/modals/link-builder/utm-templates-button.tsx b/apps/web/ui/modals/link-builder/utm-templates-button.tsx index 32a908890e..aa7cf70015 100644 --- a/apps/web/ui/modals/link-builder/utm-templates-button.tsx +++ b/apps/web/ui/modals/link-builder/utm-templates-button.tsx @@ -23,7 +23,7 @@ export function UTMTemplatesButton({ const { id: workspaceId } = useWorkspace(); const { data, isLoading } = useSWR( - workspaceId && `/api/utm-templates?workspaceId=${workspaceId}`, + workspaceId && `/api/utm?workspaceId=${workspaceId}`, fetcher, { dedupingInterval: 60000, diff --git a/apps/web/ui/modals/link-builder/utm-templates-combo.tsx b/apps/web/ui/modals/link-builder/utm-templates-combo.tsx index 9d494aca23..fcd7a989f0 100644 --- a/apps/web/ui/modals/link-builder/utm-templates-combo.tsx +++ b/apps/web/ui/modals/link-builder/utm-templates-combo.tsx @@ -22,7 +22,7 @@ export function UTMTemplatesCombo({ const { setValue, getValues } = useFormContext(); const { data } = useSWR( - workspaceId && `/api/utm-templates?workspaceId=${workspaceId}`, + workspaceId && `/api/utm?workspaceId=${workspaceId}`, fetcher, { dedupingInterval: 60000, @@ -89,23 +89,20 @@ export function UTMTemplatesCombo({ createLabel={(search) => `Save new template: "${search}"`} onCreate={async (search) => { try { - const res = await fetch( - `/api/utm-templates?workspaceId=${workspaceId}`, - { - method: "POST", - body: JSON.stringify({ - name: search, - ...getParamsFromURL(getValues("url")), - }), - }, - ); + const res = await fetch(`/api/utm?workspaceId=${workspaceId}`, { + method: "POST", + body: JSON.stringify({ + name: search, + ...getParamsFromURL(getValues("url")), + }), + }); if (!res.ok) { const { error } = await res.json(); toast.error(error.message); return false; } - mutate(`/api/utm-templates?workspaceId=${workspaceId}`); + mutate(`/api/utm?workspaceId=${workspaceId}`); toast.success("Template saved successfully"); return true; } catch (e) {