2
0

fix(dashboard): 🐛 Typebot import with items

This commit is contained in:
Baptiste Arnaud
2022-04-09 17:47:29 -05:00
parent f7e779b066
commit cd879eee5f

View File

@ -35,6 +35,8 @@ import {
defaultConditionContent, defaultConditionContent,
defaultSendEmailOptions, defaultSendEmailOptions,
defaultEmbedBubbleContent, defaultEmbedBubbleContent,
ChoiceInputStep,
ConditionStep,
} from 'models' } from 'models'
import { Typebot } from 'models' import { Typebot } from 'models'
import useSWR from 'swr' import useSWR from 'swr'
@ -42,6 +44,7 @@ import { fetcher, toKebabCase } from '../utils'
import { import {
isBubbleStepType, isBubbleStepType,
isWebhookStep, isWebhookStep,
stepHasItems,
stepTypeHasItems, stepTypeHasItems,
stepTypeHasOption, stepTypeHasOption,
stepTypeHasWebhook, stepTypeHasWebhook,
@ -53,6 +56,7 @@ 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 } from 'db' import { Plan } from 'db'
import { isDefined } from '@chakra-ui/utils'
export type TypebotInDashboard = Pick< export type TypebotInDashboard = Pick<
Typebot, Typebot,
@ -129,6 +133,29 @@ const duplicateTypebot = async (
? edgeIdsMapping.get(s.outgoingEdgeId) ? edgeIdsMapping.get(s.outgoingEdgeId)
: undefined, : undefined,
} }
if (
s.type === LogicStepType.TYPEBOT_LINK &&
s.options.typebotId === 'current' &&
isDefined(s.options.blockId)
)
return {
...s,
options: {
...s.options,
blockId: blockIdsMapping.get(s.options.blockId as string),
},
}
if (stepHasItems(s))
return {
...s,
items: s.items.map((item) => ({
...item,
outgoingEdgeId: item.outgoingEdgeId
? (edgeIdsMapping.get(item.outgoingEdgeId) as string)
: undefined,
})),
...newIds,
} as ChoiceInputStep | ConditionStep
if (isWebhookStep(s)) { if (isWebhookStep(s)) {
const newWebhook = await duplicateWebhook(s.webhookId) const newWebhook = await duplicateWebhook(s.webhookId)
return { return {