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.

update defaultWorkspace when workspace slug updates

Steven Tey0d1aac2e25bb
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
index 5fe0714a32..eacb30fe72 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
@@ -43,8 +43,8 @@ export const GET = withWorkspace(async ({ workspace, headers }) => {
);
});
-// PUT /api/workspaces/[idOrSlug] – update a specific workspace by id or slug
-export const PUT = withWorkspace(
+// PATCH /api/workspaces/[idOrSlug] – update a specific workspace by id or slug
+export const PATCH = withWorkspace(
async ({ req, workspace }) => {
try {
const { name, slug } = await updateWorkspaceSchema.parseAsync(
@@ -60,6 +60,18 @@ export const PUT = withWorkspace(
...(slug && { slug }),
},
});
+
+ if (slug !== workspace.slug) {
+ await prisma.user.updateMany({
+ where: {
+ defaultWorkspace: workspace.slug,
+ },
+ data: {
+ defaultWorkspace: slug,
+ },
+ });
+ }
+
return NextResponse.json(response);
} catch (error) {
if (error.code === "P2002") {
@@ -77,6 +89,8 @@ export const PUT = withWorkspace(
},
);
+export const PUT = PATCH;
+
// DELETE /api/workspaces/[idOrSlug] – delete a specific project
export const DELETE = withWorkspace(
async ({ workspace }) => {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx
index 5a2a40a221..a6880833b8 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx
@@ -31,7 +31,7 @@ export default function WorkspaceSettingsClient() {
})}
handleSubmit={(updateData) =>
fetch(`/api/workspaces/${id}`, {
- method: "PUT",
+ method: "PATCH",
headers: {
"Content-Type": "application/json",
},
@@ -67,7 +67,7 @@ export default function WorkspaceSettingsClient() {
})}
handleSubmit={(data) =>
fetch(`/api/workspaces/${id}`, {
- method: "PUT",
+ method: "PATCH",
headers: {
"Content-Type": "application/json",
},