Skip to content

Commit

Permalink
chore: 🛂 Make sure branding is forced on file import
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 23, 2022
1 parent f4e6f63 commit 0704213
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
23 changes: 13 additions & 10 deletions apps/builder/layouts/dashboard/TemplatesContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
18 changes: 14 additions & 4 deletions apps/builder/services/typebots/typebots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Typebot, 'id' | 'updatedAt' | 'createdAt'> = omit(
{
...typebot,
Expand All @@ -109,7 +110,7 @@ export const importTypebot = async (typebot: Typebot) => {
return sendRequest<Typebot>({
url: `/api/typebots`,
method: 'POST',
body: cleanUpTypebot(typebotToImport),
body: cleanUpTypebot(typebotToImport, user),
})
}

Expand Down Expand Up @@ -138,15 +139,24 @@ export const duplicateTypebot = async (typebotId: string) => {
}

const cleanUpTypebot = (
typebot: Omit<Typebot, 'id' | 'updatedAt' | 'createdAt'>
) => ({
typebot: Omit<Typebot, 'id' | 'updatedAt' | 'createdAt'>,
user: User
): Omit<Typebot, 'id' | 'updatedAt' | 'createdAt'> => ({
...typebot,
blocks: typebot.blocks.map((b) => ({
...b,
steps: b.steps.map((s) =>
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 (
Expand Down

3 comments on commit 0704213

@vercel
Copy link

@vercel vercel bot commented on 0704213 Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 0704213 Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.