2
0

fix(editor): 🚑️ Step id duplication

This commit is contained in:
Baptiste Arnaud
2022-03-24 09:44:04 +01:00
parent e502413ecf
commit b8019f3732
2 changed files with 18 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import {
Block, Block,
DraggableStep, DraggableStep,
DraggableStepType, DraggableStepType,
IntegrationStepType,
StepIndices, StepIndices,
Typebot, Typebot,
} from 'models' } from 'models'
@ -65,7 +66,11 @@ const blocksActions = (setTypebot: SetTypebot): BlocksActions => ({
...block, ...block,
title: `${block.title} copy`, title: `${block.title} copy`,
id, 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: { graphCoordinates: {
x: block.graphCoordinates.x + 200, x: block.graphCoordinates.x + 200,
y: block.graphCoordinates.y + 100, y: block.graphCoordinates.y + 100,

View File

@ -4,6 +4,7 @@ import {
DraggableStep, DraggableStep,
DraggableStepType, DraggableStepType,
StepIndices, StepIndices,
IntegrationStepType,
} from 'models' } from 'models'
import { parseNewStep } from 'services/typebots/typebots' import { parseNewStep } from 'services/typebots/typebots'
import { removeEmptyBlocks } from './blocks' import { removeEmptyBlocks } from './blocks'
@ -54,10 +55,17 @@ const stepsAction = (setTypebot: SetTypebot): StepsActions => ({
produce(typebot, (typebot) => { produce(typebot, (typebot) => {
const step = typebot.blocks[blockIndex].steps[stepIndex] const step = typebot.blocks[blockIndex].steps[stepIndex]
const id = cuid() const id = cuid()
const newStep: Step = { const newStep: Step =
...step, step.type === IntegrationStepType.WEBHOOK
id, ? {
} ...step,
id,
webhookId: cuid(),
}
: {
...step,
id,
}
typebot.blocks[blockIndex].steps.splice(stepIndex + 1, 0, newStep) typebot.blocks[blockIndex].steps.splice(stepIndex + 1, 0, newStep)
}) })
), ),