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, + }, + }, } }