chore: 🛂 Make sure branding is forced on file import
This commit is contained in:
@ -46,18 +46,21 @@ export const TemplatesContent = () => {
|
|||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
const folderId = router.query.folderId?.toString() ?? null
|
const folderId = router.query.folderId?.toString() ?? null
|
||||||
const { error, data } = typebot
|
const { error, data } = typebot
|
||||||
? await importTypebot({
|
? await importTypebot(
|
||||||
...typebot,
|
{
|
||||||
ownerId: user.id,
|
...typebot,
|
||||||
folderId,
|
ownerId: user.id,
|
||||||
theme: {
|
folderId,
|
||||||
...defaultTheme,
|
theme: {
|
||||||
chat: {
|
...defaultTheme,
|
||||||
...defaultTheme.chat,
|
chat: {
|
||||||
hostAvatar: { isEnabled: true, url: user.image ?? undefined },
|
...defaultTheme.chat,
|
||||||
|
hostAvatar: { isEnabled: true, url: user.image ?? undefined },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
user
|
||||||
|
)
|
||||||
: await createTypebot({
|
: await createTypebot({
|
||||||
folderId,
|
folderId,
|
||||||
})
|
})
|
||||||
|
@ -51,6 +51,7 @@ import { isChoiceInput, isConditionStep, sendRequest, omit } from 'utils'
|
|||||||
import cuid from 'cuid'
|
import cuid from 'cuid'
|
||||||
import { diff } from 'deep-object-diff'
|
import { diff } from 'deep-object-diff'
|
||||||
import { duplicateWebhook } from 'services/webhook'
|
import { duplicateWebhook } from 'services/webhook'
|
||||||
|
import { Plan, User } from 'db'
|
||||||
|
|
||||||
export type TypebotInDashboard = Pick<
|
export type TypebotInDashboard = Pick<
|
||||||
Typebot,
|
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<Typebot, 'id' | 'updatedAt' | 'createdAt'> = omit(
|
const typebotToImport: Omit<Typebot, 'id' | 'updatedAt' | 'createdAt'> = omit(
|
||||||
{
|
{
|
||||||
...typebot,
|
...typebot,
|
||||||
@ -109,7 +110,7 @@ export const importTypebot = async (typebot: Typebot) => {
|
|||||||
return sendRequest<Typebot>({
|
return sendRequest<Typebot>({
|
||||||
url: `/api/typebots`,
|
url: `/api/typebots`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: cleanUpTypebot(typebotToImport),
|
body: cleanUpTypebot(typebotToImport, user),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,8 +139,9 @@ export const duplicateTypebot = async (typebotId: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cleanUpTypebot = (
|
const cleanUpTypebot = (
|
||||||
typebot: Omit<Typebot, 'id' | 'updatedAt' | 'createdAt'>
|
typebot: Omit<Typebot, 'id' | 'updatedAt' | 'createdAt'>,
|
||||||
) => ({
|
user: User
|
||||||
|
): Omit<Typebot, 'id' | 'updatedAt' | 'createdAt'> => ({
|
||||||
...typebot,
|
...typebot,
|
||||||
blocks: typebot.blocks.map((b) => ({
|
blocks: typebot.blocks.map((b) => ({
|
||||||
...b,
|
...b,
|
||||||
@ -147,6 +149,14 @@ const cleanUpTypebot = (
|
|||||||
isWebhookStep(s) ? { ...s, webhookId: cuid() } : 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 (
|
const cleanAndDuplicateWebhooks = async (
|
||||||
|
Reference in New Issue
Block a user