Skip to content

Commit

Permalink
fix(editor): 🚑️ Step id duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 24, 2022
1 parent e502413 commit b8019f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion apps/builder/contexts/TypebotContext/actions/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Block,
DraggableStep,
DraggableStepType,
IntegrationStepType,
StepIndices,
Typebot,
} from 'models'
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions apps/builder/contexts/TypebotContext/actions/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DraggableStep,
DraggableStepType,
StepIndices,
IntegrationStepType,
} from 'models'
import { parseNewStep } from 'services/typebots/typebots'
import { removeEmptyBlocks } from './blocks'
Expand Down Expand Up @@ -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)
})
),
Expand Down

3 comments on commit b8019f3

@vercel
Copy link

@vercel vercel bot commented on b8019f3 Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on b8019f3 Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
app.typebot.io
builder-v2-typebot-io.vercel.app

Please sign in to comment.