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.

re-arrange slack integrations

Kiran K6d3519ba231b
diff --git a/apps/web/app/api/slack/slash-commands/route.ts b/apps/web/app/api/slack/slash-commands/route.ts
index 0427d1e9a2..b9642dbdb4 100644
--- a/apps/web/app/api/slack/slash-commands/route.ts
+++ b/apps/web/app/api/slack/slash-commands/route.ts
@@ -1,4 +1,4 @@
-import { handleSlashCommand } from "@/lib/integrations/slack/slash-commands";
+import { handleSlashCommand } from "@/lib/integrations/slack/commands";
import { NextResponse } from "next/server";
// Slack will send an HTTP POST request information to this URL when a user run the slash command
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 f1f43fbbce..58d3d7b979 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
@@ -1,8 +1,8 @@
"use client";
import { getIntegrationInstallUrl } from "@/lib/actions/get-integration-install-url";
-import { SegmentSettings } from "@/lib/integrations/segment/components/settings";
-import { SlackSettings } from "@/lib/integrations/slack/components/settings";
+import { SegmentSettings } from "@/lib/integrations/segment/ui/settings";
+import { SlackSettings } from "@/lib/integrations/slack/ui/settings";
import useWorkspace from "@/lib/swr/use-workspace";
import { InstalledIntegrationInfoProps } from "@/lib/types";
import { useUninstallIntegrationModal } from "@/ui/modals/uninstall-integration-modal";
diff --git a/apps/web/lib/integrations/segment/components/configure-webhook.tsx b/apps/web/lib/integrations/common/ui/configure-webhook.tsx
similarity index 96%
rename from apps/web/lib/integrations/segment/components/configure-webhook.tsx
rename to apps/web/lib/integrations/common/ui/configure-webhook.tsx
index 7eb2471de0..f4c4a7a03d 100644
--- a/apps/web/lib/integrations/segment/components/configure-webhook.tsx
+++ b/apps/web/lib/integrations/common/ui/configure-webhook.tsx
@@ -2,7 +2,7 @@
import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
-import { WebhookProps } from "@/lib/types";
+import { WebhookProps, WebhookTrigger } from "@/lib/types";
import {
LINK_LEVEL_WEBHOOK_TRIGGERS,
WEBHOOK_TRIGGER_DESCRIPTIONS,
@@ -16,9 +16,14 @@ import { cn } from "@dub/utils/src/functions";
import { FormEvent, useEffect, useState } from "react";
import { toast } from "sonner";
import useSWR, { mutate } from "swr";
-import { supportedEvents } from "../utils";
-export function ConfigureWebhook({ webhookId }: { webhookId: string }) {
+export function ConfigureWebhook({
+ webhookId,
+ supportedEvents,
+}: {
+ webhookId: string;
+ supportedEvents: WebhookTrigger[]; // Not all integrations support all events.
+}) {
const [saving, setSaving] = useState(false);
const { id: workspaceId, role } = useWorkspace();
diff --git a/apps/web/lib/integrations/segment/components/set-write-key.tsx b/apps/web/lib/integrations/segment/ui/set-write-key.tsx
similarity index 100%
rename from apps/web/lib/integrations/segment/components/set-write-key.tsx
rename to apps/web/lib/integrations/segment/ui/set-write-key.tsx
diff --git a/apps/web/lib/integrations/segment/components/settings.tsx b/apps/web/lib/integrations/segment/ui/settings.tsx
similarity index 62%
rename from apps/web/lib/integrations/segment/components/settings.tsx
rename to apps/web/lib/integrations/segment/ui/settings.tsx
index ba470c5af0..057b6b6b90 100644
--- a/apps/web/lib/integrations/segment/components/settings.tsx
+++ b/apps/web/lib/integrations/segment/ui/settings.tsx
@@ -4,7 +4,8 @@ import {
InstalledIntegrationInfoProps,
SegmentIntegrationCredentials,
} from "@/lib/types";
-import { ConfigureWebhook } from "./configure-webhook";
+import { ConfigureWebhook } from "../../common/ui/configure-webhook";
+import { supportedEvents } from "../utils";
import { SetWriteKey } from "./set-write-key";
export const SegmentSettings = (props: InstalledIntegrationInfoProps) => {
@@ -16,7 +17,12 @@ export const SegmentSettings = (props: InstalledIntegrationInfoProps) => {
installed={!!installed?.id}
credentials={credentials as SegmentIntegrationCredentials}
/>
- {installed && webhookId && <ConfigureWebhook webhookId={webhookId} />}
+ {installed && webhookId && (
+ <ConfigureWebhook
+ webhookId={webhookId}
+ supportedEvents={supportedEvents}
+ />
+ )}
</>
);
};
diff --git a/apps/web/lib/integrations/segment/components/types.ts b/apps/web/lib/integrations/segment/ui/types.ts
similarity index 100%
rename from apps/web/lib/integrations/segment/components/types.ts
rename to apps/web/lib/integrations/segment/ui/types.ts
diff --git a/apps/web/lib/integrations/segment/utils.ts b/apps/web/lib/integrations/segment/utils.ts
index 19b22b3dd1..2567cf3153 100644
--- a/apps/web/lib/integrations/segment/utils.ts
+++ b/apps/web/lib/integrations/segment/utils.ts
@@ -4,7 +4,6 @@ export const createSegmentBasicAuthHeader = (writeKey: string) => {
return `Basic ${Buffer.from(`${writeKey}:`).toString("base64")}`;
};
-// supported workspace level events
export const supportedEvents: WebhookTrigger[] = [
"lead.created",
"sale.created",
diff --git a/apps/web/lib/integrations/slack/slash-commands.ts b/apps/web/lib/integrations/slack/commands.ts
similarity index 100%
rename from apps/web/lib/integrations/slack/slash-commands.ts
rename to apps/web/lib/integrations/slack/commands.ts
diff --git a/apps/web/lib/integrations/slack/components/settings.tsx b/apps/web/lib/integrations/slack/components/settings.tsx
deleted file mode 100644
index a56c60d29c..0000000000
--- a/apps/web/lib/integrations/slack/components/settings.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-"use client";
-
-import useWorkspace from "@/lib/swr/use-workspace";
-import { InstalledIntegrationInfoProps } from "@/lib/types";
-import { Button, Webhook } from "@dub/ui";
-import Link from "next/link";
-
-type SlackSettingsProps = InstalledIntegrationInfoProps & {
- credentials: {
- webhookId?: string;
- };
-};
-
-export const SlackSettings = ({
- installed,
- credentials,
-}: SlackSettingsProps) => {
- const { slug } = useWorkspace();
-
- if (!installed || !credentials) {
- return null;
- }
-
- const { webhookId } = credentials;
-
- return (
- <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">
- <Webhook className="size-4" />
- <p className="text-sm font-medium text-gray-700">Configure webhook</p>
- </div>
-
- <div className="flex items-center justify-between p-6">
- <p className="text-sm leading-normal text-gray-600">
- Customize your Slack notifications by configuring webhook settings.
- You can choose which events to send to Slack and disable the
- notifications.
- </p>
-
- <Link href={`/${slug}/settings/webhooks/${webhookId}/edit`}>
- <Button className="w-fit" text="Update" variant="secondary" />
- </Link>
- </div>
- </div>
- );
-};
diff --git a/apps/web/lib/webhook/slack-templates.ts b/apps/web/lib/integrations/slack/transform.ts
similarity index 96%
rename from apps/web/lib/webhook/slack-templates.ts
rename to apps/web/lib/integrations/slack/transform.ts
index 03cf508cf3..5807cb028d 100644
--- a/apps/web/lib/webhook/slack-templates.ts
+++ b/apps/web/lib/integrations/slack/transform.ts
@@ -1,13 +1,13 @@
import { APP_DOMAIN } from "@dub/utils";
import { LinkWebhookEvent } from "dub/models/components";
import { z } from "zod";
-import { WebhookTrigger } from "../types";
-import { webhookPayloadSchema } from "./schemas";
+import { WebhookTrigger } from "../../types";
+import { webhookPayloadSchema } from "../../webhook/schemas";
import {
ClickEventWebhookData,
LeadEventWebhookData,
SaleEventWebhookData,
-} from "./types";
+} from "../../webhook/types";
const createLinkTemplate = ({
data,
@@ -208,7 +208,7 @@ const slackTemplates: Record<WebhookTrigger, any> = {
"link.clicked": clickLinkTemplate,
};
-export const generateSlackMessage = (
+export const formatEventForSlack = (
payload: z.infer<typeof webhookPayloadSchema>,
) => {
const { event, data } = payload;
diff --git a/apps/web/lib/integrations/slack/ui/settings.tsx b/apps/web/lib/integrations/slack/ui/settings.tsx
new file mode 100644
index 0000000000..08dc8ebf0c
--- /dev/null
+++ b/apps/web/lib/integrations/slack/ui/settings.tsx
@@ -0,0 +1,20 @@
+"use client";
+
+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;
+
+ return (
+ <>
+ {installed && webhookId && (
+ <ConfigureWebhook
+ webhookId={webhookId}
+ supportedEvents={supportedEvents}
+ />
+ )}
+ </>
+ );
+};
diff --git a/apps/web/lib/integrations/slack/utils.ts b/apps/web/lib/integrations/slack/utils.ts
new file mode 100644
index 0000000000..3de6104d7a
--- /dev/null
+++ b/apps/web/lib/integrations/slack/utils.ts
@@ -0,0 +1,9 @@
+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/webhook/qstash.ts b/apps/web/lib/webhook/qstash.ts
index c5f9106d4b..5a47ea1d90 100644
--- a/apps/web/lib/webhook/qstash.ts
+++ b/apps/web/lib/webhook/qstash.ts
@@ -4,10 +4,10 @@ import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";
import { Webhook, WebhookReceiver } from "@prisma/client";
import { formatEventForSegment } from "../integrations/segment/transform";
import { createSegmentBasicAuthHeader } from "../integrations/segment/utils";
+import { formatEventForSlack } from "../integrations/slack/transform";
import { WebhookTrigger } from "../types";
import z from "../zod";
import { createWebhookSignature } from "./signature";
-import { generateSlackMessage } from "./slack-templates";
import { prepareWebhookPayload } from "./transform";
import { EventDataProps } from "./types";
import { identifyWebhookReceiver } from "./utils";
@@ -77,7 +77,7 @@ const publishWebhookEventToQStash = async ({
return response;
};
-// Transform the payload for the receiver
+// Transform the payload based on the integration
const transformPayload = ({
payload,
receiver,
@@ -87,7 +87,7 @@ const transformPayload = ({
}) => {
switch (receiver) {
case "slack":
- return generateSlackMessage(payload);
+ return formatEventForSlack(payload);
case "segment":
return formatEventForSegment(payload);
default: