mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-06 22:01:00 -06:00
feat: support for make and n8n integration states (#1568)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
committed by
GitHub
parent
b691a74369
commit
b28f6f4bb2
@@ -7,7 +7,7 @@ import WebhookLogo from "@/images/webhook.png";
|
||||
import ZapierLogo from "@/images/zapier-small.png";
|
||||
import { Card } from "@formbricks/ui/Card";
|
||||
import Image from "next/image";
|
||||
import { getCountOfWebhooksBasedOnSource } from "@formbricks/lib/webhook/service";
|
||||
import { getWebhookCountBySource } from "@formbricks/lib/webhook/service";
|
||||
import { getEnvironment } from "@formbricks/lib/environment/service";
|
||||
import { getIntegrations } from "@formbricks/lib/integration/service";
|
||||
import { getTeamByEnvironmentId } from "@formbricks/lib/team/service";
|
||||
@@ -20,13 +20,24 @@ import { ErrorComponent } from "@formbricks/ui/ErrorComponent";
|
||||
export default async function IntegrationsPage({ params }) {
|
||||
const environmentId = params.environmentId;
|
||||
|
||||
const [environment, integrations, userWebhooks, zapierWebhooks, team, session] = await Promise.all([
|
||||
const [
|
||||
environment,
|
||||
integrations,
|
||||
team,
|
||||
session,
|
||||
userWebhookCount,
|
||||
zapierWebhookCount,
|
||||
makeWebhookCount,
|
||||
n8nwebhookCount,
|
||||
] = await Promise.all([
|
||||
getEnvironment(environmentId),
|
||||
getIntegrations(environmentId),
|
||||
getCountOfWebhooksBasedOnSource(environmentId, "user"),
|
||||
getCountOfWebhooksBasedOnSource(environmentId, "zapier"),
|
||||
getTeamByEnvironmentId(params.environmentId),
|
||||
getServerSession(authOptions),
|
||||
getWebhookCountBySource(environmentId, "user"),
|
||||
getWebhookCountBySource(environmentId, "zapier"),
|
||||
getWebhookCountBySource(environmentId, "make"),
|
||||
getWebhookCountBySource(environmentId, "n8n"),
|
||||
]);
|
||||
|
||||
if (!session) {
|
||||
@@ -67,9 +78,13 @@ export default async function IntegrationsPage({ params }) {
|
||||
label: "Zapier",
|
||||
description: "Integrate Formbricks with 5000+ apps via Zapier",
|
||||
icon: <Image src={ZapierLogo} alt="Zapier Logo" />,
|
||||
connected: zapierWebhooks > 0,
|
||||
connected: zapierWebhookCount > 0,
|
||||
statusText:
|
||||
zapierWebhooks === 1 ? "1 zap" : zapierWebhooks === 0 ? "Not Connected" : `${zapierWebhooks} zaps`,
|
||||
zapierWebhookCount === 1
|
||||
? "1 zap"
|
||||
: zapierWebhookCount === 0
|
||||
? "Not Connected"
|
||||
: `${zapierWebhookCount} zaps`,
|
||||
},
|
||||
{
|
||||
connectHref: `/environments/${params.environmentId}/integrations/webhooks`,
|
||||
@@ -81,9 +96,13 @@ export default async function IntegrationsPage({ params }) {
|
||||
label: "Webhooks",
|
||||
description: "Trigger Webhooks based on actions in your surveys",
|
||||
icon: <Image src={WebhookLogo} alt="Webhook Logo" />,
|
||||
connected: userWebhooks > 0,
|
||||
connected: userWebhookCount > 0,
|
||||
statusText:
|
||||
userWebhooks === 1 ? "1 webhook" : userWebhooks === 0 ? "Not Connected" : `${userWebhooks} webhooks`,
|
||||
userWebhookCount === 1
|
||||
? "1 webhook"
|
||||
: userWebhookCount === 0
|
||||
? "Not Connected"
|
||||
: `${userWebhookCount} webhooks`,
|
||||
},
|
||||
{
|
||||
connectHref: `/environments/${params.environmentId}/integrations/google-sheets`,
|
||||
@@ -121,6 +140,13 @@ export default async function IntegrationsPage({ params }) {
|
||||
label: "n8n",
|
||||
description: "Integrate Formbricks with 350+ apps via n8n",
|
||||
icon: <Image src={n8nLogo} alt="n8n Logo" />,
|
||||
connected: n8nwebhookCount > 0,
|
||||
statusText:
|
||||
n8nwebhookCount === 1
|
||||
? "1 integration"
|
||||
: n8nwebhookCount === 0
|
||||
? "Not Connected"
|
||||
: `${n8nwebhookCount} integrations`,
|
||||
},
|
||||
{
|
||||
docsHref: "https://formbricks.com/docs/integrations/make",
|
||||
@@ -132,6 +158,13 @@ export default async function IntegrationsPage({ params }) {
|
||||
label: "Make.com",
|
||||
description: "Integrate Formbricks with 1000+ apps via Make",
|
||||
icon: <Image src={MakeLogo} alt="Make Logo" />,
|
||||
connected: makeWebhookCount > 0,
|
||||
statusText:
|
||||
makeWebhookCount === 1
|
||||
? "1 integration"
|
||||
: makeWebhookCount === 0
|
||||
? "Not Connected"
|
||||
: `${makeWebhookCount} integration`,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
-- 1. Rename the existing ENUM type.
|
||||
ALTER TYPE "WehbhookSource" RENAME TO "TempWebhookSource";
|
||||
|
||||
-- 2. Create the new ENUM type.
|
||||
CREATE TYPE "WebhookSource" AS ENUM ('user', 'zapier', 'make', 'n8n');
|
||||
|
||||
-- 3. Remove the default.
|
||||
ALTER TABLE "Webhook" ALTER COLUMN "source" DROP DEFAULT;
|
||||
|
||||
-- 4. Change the column type using the USING clause for casting.
|
||||
ALTER TABLE "Webhook"
|
||||
ALTER COLUMN "source" TYPE "WebhookSource" USING "source"::text::"WebhookSource";
|
||||
|
||||
-- 5. Add the default back.
|
||||
ALTER TABLE "Webhook" ALTER COLUMN "source" SET DEFAULT 'user';
|
||||
|
||||
-- Optionally, if you want to drop the old ENUM type after verifying everything works:
|
||||
DROP TYPE "TempWebhookSource";
|
||||
@@ -31,9 +31,11 @@ enum PipelineTriggers {
|
||||
responseFinished
|
||||
}
|
||||
|
||||
enum WehbhookSource {
|
||||
enum WebhookSource {
|
||||
user
|
||||
zapier
|
||||
make
|
||||
n8n
|
||||
}
|
||||
|
||||
model Webhook {
|
||||
@@ -42,7 +44,7 @@ model Webhook {
|
||||
createdAt DateTime @default(now()) @map(name: "created_at")
|
||||
updatedAt DateTime @updatedAt @map(name: "updated_at")
|
||||
url String
|
||||
source WehbhookSource @default(user)
|
||||
source WebhookSource @default(user)
|
||||
environment Environment @relation(fields: [environmentId], references: [id], onDelete: Cascade)
|
||||
environmentId String
|
||||
triggers PipelineTriggers[]
|
||||
|
||||
@@ -36,7 +36,7 @@ export const getWebhooks = async (environmentId: string, page?: number): Promise
|
||||
}
|
||||
)();
|
||||
|
||||
export const getCountOfWebhooksBasedOnSource = async (
|
||||
export const getWebhookCountBySource = async (
|
||||
environmentId: string,
|
||||
source: TWebhookInput["source"]
|
||||
): Promise<number> =>
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { z } from "zod";
|
||||
import { ZPipelineTrigger } from "./pipelines";
|
||||
|
||||
export const ZWebhookSource = z.enum(["user", "zapier", "make", "n8n"]);
|
||||
|
||||
export const ZWebhook = z.object({
|
||||
id: z.string().cuid2(),
|
||||
name: z.string().nullish(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
url: z.string().url(),
|
||||
source: z.enum(["user", "zapier"]),
|
||||
source: ZWebhookSource,
|
||||
environmentId: z.string().cuid2(),
|
||||
triggers: z.array(ZPipelineTrigger),
|
||||
surveyIds: z.array(z.string().cuid2()),
|
||||
@@ -19,7 +21,7 @@ export const ZWebhookInput = z.object({
|
||||
url: z.string().url(),
|
||||
name: z.string().nullish(),
|
||||
triggers: z.array(ZPipelineTrigger),
|
||||
source: z.enum(["user", "zapier"]).optional(),
|
||||
source: ZWebhookSource.optional(),
|
||||
surveyIds: z.array(z.string().cuid2()).optional(),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user