From cd879eee5fafdfb2f3790b1cb75dae5abca8fef3 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Sat, 9 Apr 2022 17:47:29 -0500 Subject: [PATCH] =?UTF-8?q?fix(dashboard):=20=F0=9F=90=9B=20Typebot=20impo?= =?UTF-8?q?rt=20with=20items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/builder/services/typebots/typebots.ts | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/apps/builder/services/typebots/typebots.ts b/apps/builder/services/typebots/typebots.ts index f826c7a48..5e946403e 100644 --- a/apps/builder/services/typebots/typebots.ts +++ b/apps/builder/services/typebots/typebots.ts @@ -35,6 +35,8 @@ import { defaultConditionContent, defaultSendEmailOptions, defaultEmbedBubbleContent, + ChoiceInputStep, + ConditionStep, } from 'models' import { Typebot } from 'models' import useSWR from 'swr' @@ -42,6 +44,7 @@ import { fetcher, toKebabCase } from '../utils' import { isBubbleStepType, isWebhookStep, + stepHasItems, stepTypeHasItems, stepTypeHasOption, stepTypeHasWebhook, @@ -53,6 +56,7 @@ import cuid from 'cuid' import { diff } from 'deep-object-diff' import { duplicateWebhook } from 'services/webhook' import { Plan } from 'db' +import { isDefined } from '@chakra-ui/utils' export type TypebotInDashboard = Pick< Typebot, @@ -129,6 +133,29 @@ const duplicateTypebot = async ( ? edgeIdsMapping.get(s.outgoingEdgeId) : 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)) { const newWebhook = await duplicateWebhook(s.webhookId) return {