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.

enable & disable the status

Kiran K3c23e2e684b1
diff --git a/apps/web/app/api/webhooks/[webhookId]/route.ts b/apps/web/app/api/webhooks/[webhookId]/route.ts
index da30b155db..24a7e65052 100644
--- a/apps/web/app/api/webhooks/[webhookId]/route.ts
+++ b/apps/web/app/api/webhooks/[webhookId]/route.ts
@@ -63,6 +63,24 @@ export const DELETE = withWorkspace(
},
});
+ const webhooksCount = await prisma.webhook.count({
+ where: {
+ projectId: workspace.id,
+ },
+ });
+
+ // Disable webhooks for the workspace if there are no more webhooks
+ if (webhooksCount === 0) {
+ await prisma.project.update({
+ where: {
+ id: workspace.id,
+ },
+ data: {
+ webhookEnabled: false,
+ },
+ });
+ }
+
return NextResponse.json({
id: webhookId,
});
diff --git a/apps/web/app/api/webhooks/route.ts b/apps/web/app/api/webhooks/route.ts
index 5c6111325d..40d647dcc5 100644
--- a/apps/web/app/api/webhooks/route.ts
+++ b/apps/web/app/api/webhooks/route.ts
@@ -41,7 +41,20 @@ export const POST = withWorkspace(
},
});
+ // Enable webhooks for the workspace
+ if (webhook) {
+ await prisma.project.update({
+ where: {
+ id: workspace.id,
+ },
+ data: {
+ webhookEnabled: true,
+ },
+ });
+ }
+
waitUntil(
+ // Inform the workspace user that the webhook was added
sendEmail({
email: session.user.email,
subject: "New webhook added",