Skip to content

Commit dad8c30

Browse files
committed
update API endpoints
1 parent 68d9e67 commit dad8c30

File tree

10 files changed

+39
-33
lines changed

10 files changed

+39
-33
lines changed

apps/web/app/api/utm-templates/[id]/route.ts renamed to apps/web/app/api/utm/[id]/route.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { DubApiError } from "@/lib/api/errors";
22
import { withWorkspace } from "@/lib/auth";
33
import { prisma } from "@/lib/prisma";
4-
import { updateUTMTemplateBodySchema } from "@/lib/zod/schemas/utm-templates";
4+
import { updateUTMTemplateBodySchema } from "@/lib/zod/schemas/utm";
55
import { NextResponse } from "next/server";
66

7-
// PATCH /api/utm-templates/[id] – update a UTM template
7+
// PATCH /api/utm/[id] – update a UTM template
88
export const PATCH = withWorkspace(
99
async ({ req, params, workspace }) => {
1010
const { id } = params;
@@ -52,9 +52,7 @@ export const PATCH = withWorkspace(
5252
},
5353
);
5454

55-
export const PUT = PATCH;
56-
57-
// DELETE /api/utm-templates/[id] – delete a UTM template for a workspace
55+
// DELETE /api/utm/[id] – delete a UTM template for a workspace
5856
export const DELETE = withWorkspace(
5957
async ({ params, workspace }) => {
6058
const { id } = params;

apps/web/app/api/utm-templates/route.ts renamed to apps/web/app/api/utm/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { DubApiError } from "@/lib/api/errors";
22
import { withWorkspace } from "@/lib/auth";
33
import { prisma } from "@/lib/prisma";
4-
import { createUTMTemplateBodySchema } from "@/lib/zod/schemas/utm-templates";
4+
import { createUTMTemplateBodySchema } from "@/lib/zod/schemas/utm";
55
import { NextResponse } from "next/server";
66

7-
// GET /api/utm-templates - get all UTM templates for a workspace
7+
// GET /api/utm - get all UTM templates for a workspace
88
export const GET = withWorkspace(
99
async ({ workspace, headers }) => {
1010
const templates = await prisma.utmTemplate.findMany({
@@ -27,7 +27,7 @@ export const GET = withWorkspace(
2727
},
2828
);
2929

30-
// POST /api/utm-templates - create or update a UTM template for a workspace
30+
// POST /api/utm - create a new UTM template for a workspace
3131
export const POST = withWorkspace(
3232
async ({ req, workspace, session, headers }) => {
3333
const props = createUTMTemplateBodySchema.parse(await req.json());

apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/utm/page-client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function WorkspaceUtmTemplatesClient() {
2424
const { id: workspaceId } = useWorkspace();
2525

2626
const { data: templates, isLoading } = useSWR<UtmTemplateWithUserProps[]>(
27-
workspaceId && `/api/utm-templates?workspaceId=${workspaceId}`,
27+
workspaceId && `/api/utm?workspaceId=${workspaceId}`,
2828
fetcher,
2929
{
3030
dedupingInterval: 60000,

apps/web/app/app.dub.co/(dashboard)/[slug]/settings/library/utm/template-card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ export function TemplateCard({
4949
if (!confirm("Are you sure you want to delete this template?")) return;
5050

5151
setProcessing(true);
52-
fetch(`/api/utm-templates/${template.id}?workspaceId=${id}`, {
52+
fetch(`/api/utm/${template.id}?workspaceId=${id}`, {
5353
method: "DELETE",
5454
})
5555
.then(async (res) => {
5656
if (res.ok) {
57-
await mutate(`/api/utm-templates?workspaceId=${id}`);
57+
await mutate(`/api/utm?workspaceId=${id}`);
5858
toast.success("Template deleted");
5959
} else {
6060
const { error } = await res.json();

apps/web/ui/modals/add-edit-utm-template.modal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ function AddEditUtmTemplateModal({
5656
id
5757
? {
5858
method: "PATCH",
59-
url: `/api/utm-templates/${id}?workspaceId=${workspaceId}`,
59+
url: `/api/utm/${id}?workspaceId=${workspaceId}`,
6060
successMessage: "Successfully updated template!",
6161
}
6262
: {
6363
method: "POST",
64-
url: `/api/utm-templates?workspaceId=${workspaceId}`,
64+
url: `/api/utm?workspaceId=${workspaceId}`,
6565
successMessage: "Successfully added template!",
6666
},
6767
[id],
@@ -97,7 +97,7 @@ function AddEditUtmTemplateModal({
9797
utmTemplateName: data.name,
9898
},
9999
);
100-
await mutate(`/api/utm-templates?workspaceId=${workspaceId}`);
100+
await mutate(`/api/utm?workspaceId=${workspaceId}`);
101101
toast.success(endpoint.successMessage);
102102
setShowAddEditUtmTemplateModal(false);
103103
} catch (e) {

apps/web/ui/modals/archive-domain-modal.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ function ArchiveDomainModal({
6464
}
6565

6666
await mutate(
67-
(key) =>
68-
typeof key === "string" &&
69-
key.startsWith(`/api/domains?workspaceId=${workspaceId}`),
67+
(key) => typeof key === "string" && key.startsWith("/api/domains"),
68+
undefined,
69+
{
70+
revalidate: true,
71+
},
7072
);
7173
setShowArchiveDomainModal(false);
7274
toastWithUndo({
@@ -89,9 +91,9 @@ function ArchiveDomainModal({
8991
error: "Failed to roll back changes. An error occurred.",
9092
success: async () => {
9193
await mutate(
92-
(key) =>
93-
typeof key === "string" &&
94-
key.startsWith(`/api/domains?workspaceId=${workspaceId}`),
94+
(key) => typeof key === "string" && key.startsWith("/api/domains"),
95+
undefined,
96+
{ revalidate: true },
9597
);
9698
return "Undo successful! Changes reverted.";
9799
},

apps/web/ui/modals/link-builder/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ function LinkBuilderInner({
273273
),
274274
// Mutate workspace to update usage stats
275275
mutate(`/api/workspaces/${slug}`),
276+
// if updating root domain link, mutate domains as well
277+
key === "_root" &&
278+
mutate(
279+
(key) =>
280+
typeof key === "string" &&
281+
key.startsWith("/api/domains"),
282+
undefined,
283+
{ revalidate: true },
284+
),
276285
]);
277286
const data = await res.json();
278287
posthog.capture(

apps/web/ui/modals/link-builder/utm-templates-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function UTMTemplatesButton({
2323
const { id: workspaceId } = useWorkspace();
2424

2525
const { data, isLoading } = useSWR<UtmTemplateProps[]>(
26-
workspaceId && `/api/utm-templates?workspaceId=${workspaceId}`,
26+
workspaceId && `/api/utm?workspaceId=${workspaceId}`,
2727
fetcher,
2828
{
2929
dedupingInterval: 60000,

apps/web/ui/modals/link-builder/utm-templates-combo.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function UTMTemplatesCombo({
2222
const { setValue, getValues } = useFormContext();
2323

2424
const { data } = useSWR<UtmTemplateProps[]>(
25-
workspaceId && `/api/utm-templates?workspaceId=${workspaceId}`,
25+
workspaceId && `/api/utm?workspaceId=${workspaceId}`,
2626
fetcher,
2727
{
2828
dedupingInterval: 60000,
@@ -89,23 +89,20 @@ export function UTMTemplatesCombo({
8989
createLabel={(search) => `Save new template: "${search}"`}
9090
onCreate={async (search) => {
9191
try {
92-
const res = await fetch(
93-
`/api/utm-templates?workspaceId=${workspaceId}`,
94-
{
95-
method: "POST",
96-
body: JSON.stringify({
97-
name: search,
98-
...getParamsFromURL(getValues("url")),
99-
}),
100-
},
101-
);
92+
const res = await fetch(`/api/utm?workspaceId=${workspaceId}`, {
93+
method: "POST",
94+
body: JSON.stringify({
95+
name: search,
96+
...getParamsFromURL(getValues("url")),
97+
}),
98+
});
10299
if (!res.ok) {
103100
const { error } = await res.json();
104101
toast.error(error.message);
105102
return false;
106103
}
107104

108-
mutate(`/api/utm-templates?workspaceId=${workspaceId}`);
105+
mutate(`/api/utm?workspaceId=${workspaceId}`);
109106
toast.success("Template saved successfully");
110107
return true;
111108
} catch (e) {

0 commit comments

Comments
 (0)