From 3e7b34c7214d96002463a37c865139cd3d30b336 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Mon, 20 Jun 2022 11:28:18 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=99=BF=EF=B8=8F=20Remove=20branding?= =?UTF-8?q?=20automatically?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/builder/pages/api/typebots.ts | 10 ++++++++-- apps/builder/services/typebots/typebots.ts | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/builder/pages/api/typebots.ts b/apps/builder/pages/api/typebots.ts index 7d2a17161..c931b9e5a 100644 --- a/apps/builder/pages/api/typebots.ts +++ b/apps/builder/pages/api/typebots.ts @@ -1,10 +1,10 @@ import { withSentry } from '@sentry/nextjs' -import { Prisma, WorkspaceRole } from 'db' +import { Plan, Prisma, WorkspaceRole } from 'db' import prisma from 'libs/prisma' import { NextApiRequest, NextApiResponse } from 'next' import { getAuthenticatedUser } from 'services/api/utils' import { parseNewTypebot } from 'services/typebots/typebots' -import { badRequest, methodNotAllowed, notAuthenticated } from 'utils' +import { badRequest, methodNotAllowed, notAuthenticated, notFound } from 'utils' const handler = async (req: NextApiRequest, res: NextApiResponse) => { const user = await getAuthenticatedUser(req) @@ -74,6 +74,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { return res.send({ typebots }) } if (req.method === 'POST') { + const workspace = await prisma.workspace.findFirst({ + where: { id: req.body.workspaceId }, + select: { plan: true }, + }) + if (!workspace) return notFound(res, "Couldn't find workspace") const data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body const typebot = await prisma.typebot.create({ @@ -82,6 +87,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { ? data : (parseNewTypebot({ ownerAvatarUrl: user.image, + isBrandingEnabled: workspace.plan === Plan.FREE, ...data, }) as Prisma.TypebotUncheckedCreateInput), }) diff --git a/apps/builder/services/typebots/typebots.ts b/apps/builder/services/typebots/typebots.ts index cc1087686..400296e3b 100644 --- a/apps/builder/services/typebots/typebots.ts +++ b/apps/builder/services/typebots/typebots.ts @@ -400,11 +400,13 @@ export const parseNewTypebot = ({ name, ownerAvatarUrl, workspaceId, + isBrandingEnabled = true, }: { folderId: string | null workspaceId: string name: string ownerAvatarUrl?: string + isBrandingEnabled?: boolean }): Omit< Typebot, | 'createdAt' @@ -443,7 +445,13 @@ export const parseNewTypebot = ({ hostAvatar: { isEnabled: true, url: ownerAvatarUrl }, }, }, - settings: defaultSettings, + settings: { + ...defaultSettings, + general: { + ...defaultSettings.general, + isBrandingEnabled, + }, + }, } }