From b8019f3732779cc57e8c89a74a04221c775cc3b3 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Thu, 24 Mar 2022 09:44:04 +0100 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=F0=9F=9A=91=EF=B8=8F=20Step=20i?= =?UTF-8?q?d=20duplication?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contexts/TypebotContext/actions/blocks.ts | 7 ++++++- .../contexts/TypebotContext/actions/steps.ts | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/apps/builder/contexts/TypebotContext/actions/blocks.ts b/apps/builder/contexts/TypebotContext/actions/blocks.ts index e81737efd..5e58e2162 100644 --- a/apps/builder/contexts/TypebotContext/actions/blocks.ts +++ b/apps/builder/contexts/TypebotContext/actions/blocks.ts @@ -6,6 +6,7 @@ import { Block, DraggableStep, DraggableStepType, + IntegrationStepType, StepIndices, Typebot, } from 'models' @@ -65,7 +66,11 @@ const blocksActions = (setTypebot: SetTypebot): BlocksActions => ({ ...block, title: `${block.title} copy`, id, - steps: block.steps.map((s) => ({ ...s, blockId: id })), + steps: block.steps.map((s) => + s.type === IntegrationStepType.WEBHOOK + ? { ...s, blockId: id, id: cuid(), webhookId: cuid() } + : { ...s, blockId: id, id: cuid() } + ), graphCoordinates: { x: block.graphCoordinates.x + 200, y: block.graphCoordinates.y + 100, diff --git a/apps/builder/contexts/TypebotContext/actions/steps.ts b/apps/builder/contexts/TypebotContext/actions/steps.ts index 92b2d9cf6..421bdec37 100644 --- a/apps/builder/contexts/TypebotContext/actions/steps.ts +++ b/apps/builder/contexts/TypebotContext/actions/steps.ts @@ -4,6 +4,7 @@ import { DraggableStep, DraggableStepType, StepIndices, + IntegrationStepType, } from 'models' import { parseNewStep } from 'services/typebots/typebots' import { removeEmptyBlocks } from './blocks' @@ -54,10 +55,17 @@ const stepsAction = (setTypebot: SetTypebot): StepsActions => ({ produce(typebot, (typebot) => { const step = typebot.blocks[blockIndex].steps[stepIndex] const id = cuid() - const newStep: Step = { - ...step, - id, - } + const newStep: Step = + step.type === IntegrationStepType.WEBHOOK + ? { + ...step, + id, + webhookId: cuid(), + } + : { + ...step, + id, + } typebot.blocks[blockIndex].steps.splice(stepIndex + 1, 0, newStep) }) ),