2
0

🦴 Add viewer backbone

This commit is contained in:
Baptiste Arnaud
2021-12-23 16:31:56 +01:00
parent 9a78a341d2
commit d369b4d941
24 changed files with 576 additions and 182 deletions

View File

@ -0,0 +1,35 @@
import { PublicTypebot, Typebot } from 'bot-engine'
import { sendRequest } from './utils'
import shortId from 'short-uuid'
export const parseTypebotToPublicTypebot = (
typebot: Typebot
): PublicTypebot => ({
id: shortId.generate(),
blocks: typebot.blocks,
name: typebot.name,
startBlock: typebot.startBlock,
typebotId: typebot.id,
theme: typebot.theme,
settings: typebot.settings,
publicId: typebot.publicId,
})
export const createPublishedTypebot = async (
typebot: Omit<PublicTypebot, 'id'>
) =>
sendRequest({
url: `/api/publicTypebots`,
method: 'POST',
body: typebot,
})
export const updatePublishedTypebot = async (
id: string,
typebot: Omit<PublicTypebot, 'id'>
) =>
sendRequest({
url: `/api/publicTypebots/${id}`,
method: 'PUT',
body: typebot,
})

View File

@ -3,8 +3,8 @@ import {
StepType,
Block,
TextStep,
PublicTypebot,
TextInputStep,
PublicTypebot,
} from 'bot-engine'
import shortId from 'short-uuid'
import { Typebot } from 'bot-engine'
@ -154,18 +154,16 @@ export const checkIfTypebotsAreEqual = (
}
)
export const parseTypebotToPublicTypebot = (
typebot: Typebot
): PublicTypebot => ({
id: shortId.generate(),
blocks: typebot.blocks,
name: typebot.name,
startBlock: typebot.startBlock,
typebotId: typebot.id,
theme: typebot.theme,
settings: typebot.settings,
publicId: typebot.publicId,
})
export const checkIfPublished = (
typebot: Typebot,
publicTypebot: PublicTypebot
) =>
deepEqual(typebot.blocks, publicTypebot.blocks) &&
deepEqual(typebot.startBlock, publicTypebot.startBlock) &&
typebot.name === publicTypebot.name &&
typebot.publicId === publicTypebot.publicId &&
deepEqual(typebot.settings, publicTypebot.settings) &&
deepEqual(typebot.theme, publicTypebot.theme)
export const parseDefaultPublicId = (name: string, id: string) =>
toKebabCase(`${name}-${id?.slice(0, 5)}`)

View File

@ -71,3 +71,23 @@ export const toKebabCase = (value: string) => {
if (!matched) return ''
return matched.map((x) => x.toLowerCase()).join('-')
}
interface Omit {
// eslint-disable-next-line @typescript-eslint/ban-types
<T extends object, K extends [...(keyof T)[]]>(obj: T, ...keys: K): {
[K2 in Exclude<keyof T, K[number]>]: T[K2]
}
}
export const omit: Omit = (obj, ...keys) => {
const ret = {} as {
[K in keyof typeof obj]: typeof obj[K]
}
let key: keyof typeof obj
for (key in obj) {
if (!keys.includes(key)) {
ret[key] = obj[key]
}
}
return ret
}