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.

Show the Webhook settings section on the `Slack` & `Zapier` integration pages

Kiran K9c9adbf43b45
diff --git a/apps/web/app/api/webhooks/route.ts b/apps/web/app/api/webhooks/route.ts
index 19c0ab48a8..3ad4946558 100644
--- a/apps/web/app/api/webhooks/route.ts
+++ b/apps/web/app/api/webhooks/route.ts
@@ -7,6 +7,7 @@ import { transformWebhook } from "@/lib/webhook/transform";
import { updateWebhookStatusForWorkspace } from "@/lib/webhook/update-webhook";
import { identifyWebhookReceiver } from "@/lib/webhook/utils";
import { createWebhookSchema } from "@/lib/zod/schemas/webhooks";
+import { ZAPIER_INTEGRATION_ID } from "@dub/utils/src/constants";
import { WebhookReceiver } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { sendEmail } from "emails";
@@ -102,6 +103,18 @@ export const POST = withWorkspace(
const isZapierWebhook =
identifyWebhookReceiver(url) === WebhookReceiver.zapier;
+ const zapierInstallation = isZapierWebhook
+ ? await prisma.installedIntegration.findFirst({
+ where: {
+ projectId: workspace.id,
+ integrationId: ZAPIER_INTEGRATION_ID,
+ },
+ select: {
+ id: true,
+ },
+ })
+ : undefined;
+
const webhook = await createWebhook({
name,
url,
@@ -110,6 +123,7 @@ export const POST = withWorkspace(
linkIds,
secret,
workspaceId: workspace.id,
+ installationId: zapierInstallation ? zapierInstallation.id : undefined,
});
waitUntil(
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page-client.tsx
index 58d3d7b979..277b33ed9e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page-client.tsx
@@ -3,6 +3,7 @@
import { getIntegrationInstallUrl } from "@/lib/actions/get-integration-install-url";
import { SegmentSettings } from "@/lib/integrations/segment/ui/settings";
import { SlackSettings } from "@/lib/integrations/slack/ui/settings";
+import { ZapierSettings } from "@/lib/integrations/zapier/ui/settings";
import useWorkspace from "@/lib/swr/use-workspace";
import { InstalledIntegrationInfoProps } from "@/lib/types";
import { useUninstallIntegrationModal } from "@/ui/modals/uninstall-integration-modal";
@@ -36,6 +37,7 @@ import {
SEGMENT_INTEGRATION_ID,
SLACK_INTEGRATION_ID,
STRIPE_INTEGRATION_ID,
+ ZAPIER_INTEGRATION_ID,
} from "@dub/utils";
import { BookOpenText, ChevronLeft, Trash, Webhook } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
@@ -44,6 +46,12 @@ import { useState } from "react";
import Markdown from "react-markdown";
import { toast } from "sonner";
+const integrationSettings = {
+ [ZAPIER_INTEGRATION_ID]: ZapierSettings,
+ [SLACK_INTEGRATION_ID]: SlackSettings,
+ [SEGMENT_INTEGRATION_ID]: SegmentSettings,
+};
+
export default function IntegrationPageClient({
integration,
}: {
@@ -70,11 +78,6 @@ export default function IntegrationPageClient({
integration,
});
- const integrationSettings = {
- [SLACK_INTEGRATION_ID]: SlackSettings,
- [SEGMENT_INTEGRATION_ID]: SegmentSettings,
- };
-
const SettingsComponent = integrationSettings[integration.id] || null;
return (
diff --git a/apps/web/lib/integrations/common/ui/configure-webhook.tsx b/apps/web/lib/integrations/common/ui/configure-webhook.tsx
index f4c4a7a03d..723f4397ed 100644
--- a/apps/web/lib/integrations/common/ui/configure-webhook.tsx
+++ b/apps/web/lib/integrations/common/ui/configure-webhook.tsx
@@ -217,6 +217,7 @@ export function ConfigureWebhook({
disabledTooltip: permissionsError,
})}
disabled={!canManageWebhook || isLoading}
+ className="h-8"
/>
</div>
</div>
diff --git a/apps/web/lib/integrations/segment/ui/set-write-key.tsx b/apps/web/lib/integrations/segment/ui/set-write-key.tsx
index c6b8b31bc7..de52336e8f 100644
--- a/apps/web/lib/integrations/segment/ui/set-write-key.tsx
+++ b/apps/web/lib/integrations/segment/ui/set-write-key.tsx
@@ -51,7 +51,7 @@ export function SetWriteKey({
<div className="w-full rounded-lg border border-gray-200 bg-white">
<div className="flex items-center gap-x-2 border-b border-gray-200 px-6 py-4">
<Lock className="size-4" />
- <p className="text-sm font-medium text-gray-700">Segment write key</p>
+ <p className="text-sm font-medium text-gray-700">Write key</p>
</div>
<div className="p-4">
@@ -89,8 +89,8 @@ export function SetWriteKey({
<Button
type="submit"
variant="primary"
- text="Enable Segment"
- className="w-fit"
+ text="Save changes"
+ className="h-8 w-fit"
loading={isExecuting}
disabled={installed || !writeKey}
/>
diff --git a/apps/web/lib/integrations/segment/ui/settings.tsx b/apps/web/lib/integrations/segment/ui/settings.tsx
index 057b6b6b90..687f3c352d 100644
--- a/apps/web/lib/integrations/segment/ui/settings.tsx
+++ b/apps/web/lib/integrations/segment/ui/settings.tsx
@@ -5,7 +5,6 @@ import {
SegmentIntegrationCredentials,
} from "@/lib/types";
import { ConfigureWebhook } from "../../common/ui/configure-webhook";
-import { supportedEvents } from "../utils";
import { SetWriteKey } from "./set-write-key";
export const SegmentSettings = (props: InstalledIntegrationInfoProps) => {
@@ -20,7 +19,7 @@ export const SegmentSettings = (props: InstalledIntegrationInfoProps) => {
{installed && webhookId && (
<ConfigureWebhook
webhookId={webhookId}
- supportedEvents={supportedEvents}
+ supportedEvents={["lead.created", "sale.created"]}
/>
)}
</>
diff --git a/apps/web/lib/integrations/segment/utils.ts b/apps/web/lib/integrations/segment/utils.ts
index 2567cf3153..888faf8e8c 100644
--- a/apps/web/lib/integrations/segment/utils.ts
+++ b/apps/web/lib/integrations/segment/utils.ts
@@ -1,10 +1,3 @@
-import { WebhookTrigger } from "@/lib/types";
-
export const createSegmentBasicAuthHeader = (writeKey: string) => {
return `Basic ${Buffer.from(`${writeKey}:`).toString("base64")}`;
};
-
-export const supportedEvents: WebhookTrigger[] = [
- "lead.created",
- "sale.created",
-];
diff --git a/apps/web/lib/integrations/slack/ui/settings.tsx b/apps/web/lib/integrations/slack/ui/settings.tsx
index 08dc8ebf0c..45b596de95 100644
--- a/apps/web/lib/integrations/slack/ui/settings.tsx
+++ b/apps/web/lib/integrations/slack/ui/settings.tsx
@@ -2,7 +2,6 @@
import { InstalledIntegrationInfoProps } from "@/lib/types";
import { ConfigureWebhook } from "../../common/ui/configure-webhook";
-import { supportedEvents } from "../utils";
export const SlackSettings = (props: InstalledIntegrationInfoProps) => {
const { installed, webhookId } = props;
@@ -12,7 +11,13 @@ export const SlackSettings = (props: InstalledIntegrationInfoProps) => {
{installed && webhookId && (
<ConfigureWebhook
webhookId={webhookId}
- supportedEvents={supportedEvents}
+ supportedEvents={[
+ "link.created",
+ "link.updated",
+ "link.deleted",
+ "lead.created",
+ "sale.created",
+ ]}
/>
)}
</>
diff --git a/apps/web/lib/integrations/slack/utils.ts b/apps/web/lib/integrations/slack/utils.ts
deleted file mode 100644
index 3de6104d7a..0000000000
--- a/apps/web/lib/integrations/slack/utils.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { WebhookTrigger } from "@/lib/types";
-
-export const supportedEvents: WebhookTrigger[] = [
- "link.created",
- "link.updated",
- "link.deleted",
- "lead.created",
- "sale.created",
-];
diff --git a/apps/web/lib/integrations/zapier/ui/settings.tsx b/apps/web/lib/integrations/zapier/ui/settings.tsx
new file mode 100644
index 0000000000..b807a0ceec
--- /dev/null
+++ b/apps/web/lib/integrations/zapier/ui/settings.tsx
@@ -0,0 +1,20 @@
+"use client";
+
+import { InstalledIntegrationInfoProps } from "@/lib/types";
+import { WORKSPACE_LEVEL_WEBHOOK_TRIGGERS } from "@/lib/webhook/constants";
+import { ConfigureWebhook } from "../../common/ui/configure-webhook";
+
+export const ZapierSettings = (props: InstalledIntegrationInfoProps) => {
+ const { installed, webhookId } = props;
+
+ return (
+ <>
+ {installed && webhookId && (
+ <ConfigureWebhook
+ webhookId={webhookId}
+ supportedEvents={Object.values(WORKSPACE_LEVEL_WEBHOOK_TRIGGERS)}
+ />
+ )}
+ </>
+ );
+};
diff --git a/packages/utils/src/constants/integrations.ts b/packages/utils/src/constants/integrations.ts
index 755df9105e..42d6d53a2a 100644
--- a/packages/utils/src/constants/integrations.ts
+++ b/packages/utils/src/constants/integrations.ts
@@ -1,3 +1,4 @@
export const SLACK_INTEGRATION_ID = "clzu59rx9000110bm5fnlzwuj";
export const STRIPE_INTEGRATION_ID = "clzra1ya60001wnj4a89zcg9h";
export const SEGMENT_INTEGRATION_ID = "cm481uged0001eh6uotzmcphy";
+export const ZAPIER_INTEGRATION_ID = "cl7pj5kq4006835rbjlt2ofka";
\ No newline at end of file