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.

prevent accidental workspace deletion

Steven Teyfe59928b7f66
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
index 33a89642f0..39bf863019 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
@@ -77,7 +77,7 @@ export const GET = withWorkspace(
// PATCH /api/workspaces/[idOrSlug] – update a specific workspace by id or slug
export const PATCH = withWorkspace(
- async ({ req, workspace, session }) => {
+ async ({ req, workspace }) => {
const {
name,
slug,
@@ -235,6 +235,14 @@ export const PUT = PATCH;
// DELETE /api/workspaces/[idOrSlug] – delete a specific project
export const DELETE = withWorkspace(
async ({ workspace }) => {
+ if (workspace.defaultProgramId) {
+ throw new DubApiError({
+ code: "bad_request",
+ message:
+ "You cannot delete a workspace with an active partner program.",
+ });
+ }
+
await deleteWorkspace(workspace);
return NextResponse.json(workspace);
diff --git a/apps/web/ui/modals/delete-workspace-modal.tsx b/apps/web/ui/modals/delete-workspace-modal.tsx
index 696d65d2be..fd4008f32f 100644
--- a/apps/web/ui/modals/delete-workspace-modal.tsx
+++ b/apps/web/ui/modals/delete-workspace-modal.tsx
@@ -42,8 +42,8 @@ function DeleteWorkspaceModal({
resolve(null);
} else {
setDeleting(false);
- const error = await res.text();
- reject(error);
+ const { error } = await res.json();
+ reject(error.message);
}
});
});