Skip to content

Commit

Permalink
feat: ♿️ Remove branding automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jun 20, 2022
1 parent f676166 commit 3e7b34c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions apps/builder/pages/api/typebots.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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({
Expand All @@ -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),
})
Expand Down
10 changes: 9 additions & 1 deletion apps/builder/services/typebots/typebots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -443,7 +445,13 @@ export const parseNewTypebot = ({
hostAvatar: { isEnabled: true, url: ownerAvatarUrl },
},
},
settings: defaultSettings,
settings: {
...defaultSettings,
general: {
...defaultSettings.general,
isBrandingEnabled,
},
},
}
}

Expand Down

0 comments on commit 3e7b34c

Please sign in to comment.