From 07042137fb79ada80b57b1873cdfefd14373ab8d Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Wed, 23 Mar 2022 10:45:15 +0100 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=9B=82=20Make=20sure=20branding?= =?UTF-8?q?=20is=20forced=20on=20file=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../layouts/dashboard/TemplatesContent.tsx | 23 +++++++++++-------- apps/builder/services/typebots/typebots.ts | 18 +++++++++++---- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/apps/builder/layouts/dashboard/TemplatesContent.tsx b/apps/builder/layouts/dashboard/TemplatesContent.tsx index 7f105cf630..fd4691dbdb 100644 --- a/apps/builder/layouts/dashboard/TemplatesContent.tsx +++ b/apps/builder/layouts/dashboard/TemplatesContent.tsx @@ -46,18 +46,21 @@ export const TemplatesContent = () => { setIsLoading(true) const folderId = router.query.folderId?.toString() ?? null const { error, data } = typebot - ? await importTypebot({ - ...typebot, - ownerId: user.id, - folderId, - theme: { - ...defaultTheme, - chat: { - ...defaultTheme.chat, - hostAvatar: { isEnabled: true, url: user.image ?? undefined }, + ? await importTypebot( + { + ...typebot, + ownerId: user.id, + folderId, + theme: { + ...defaultTheme, + chat: { + ...defaultTheme.chat, + hostAvatar: { isEnabled: true, url: user.image ?? undefined }, + }, }, }, - }) + user + ) : await createTypebot({ folderId, }) diff --git a/apps/builder/services/typebots/typebots.ts b/apps/builder/services/typebots/typebots.ts index e2c8af8553..6c89be9ce7 100644 --- a/apps/builder/services/typebots/typebots.ts +++ b/apps/builder/services/typebots/typebots.ts @@ -51,6 +51,7 @@ import { isChoiceInput, isConditionStep, sendRequest, omit } from 'utils' import cuid from 'cuid' import { diff } from 'deep-object-diff' import { duplicateWebhook } from 'services/webhook' +import { Plan, User } from 'db' export type TypebotInDashboard = Pick< Typebot, @@ -94,7 +95,7 @@ export const createTypebot = async ({ }) } -export const importTypebot = async (typebot: Typebot) => { +export const importTypebot = async (typebot: Typebot, user: User) => { const typebotToImport: Omit = omit( { ...typebot, @@ -109,7 +110,7 @@ export const importTypebot = async (typebot: Typebot) => { return sendRequest({ url: `/api/typebots`, method: 'POST', - body: cleanUpTypebot(typebotToImport), + body: cleanUpTypebot(typebotToImport, user), }) } @@ -138,8 +139,9 @@ export const duplicateTypebot = async (typebotId: string) => { } const cleanUpTypebot = ( - typebot: Omit -) => ({ + typebot: Omit, + user: User +): Omit => ({ ...typebot, blocks: typebot.blocks.map((b) => ({ ...b, @@ -147,6 +149,14 @@ const cleanUpTypebot = ( isWebhookStep(s) ? { ...s, webhookId: cuid() } : s ), })), + settings: + typebot.settings.general.isBrandingEnabled === false && + user.plan === Plan.FREE + ? { + ...typebot.settings, + general: { ...typebot.settings.general, isBrandingEnabled: true }, + } + : typebot.settings, }) const cleanAndDuplicateWebhooks = async (