2023-03-03 15:03:31 +01:00
|
|
|
import { createId } from '@paralleldrive/cuid2'
|
2023-03-15 08:35:16 +01:00
|
|
|
import { SessionState, Edge } from '@typebot.io/schemas'
|
2023-03-03 15:03:31 +01:00
|
|
|
|
|
|
|
export const addEdgeToTypebot = (
|
|
|
|
state: SessionState,
|
|
|
|
edge: Edge
|
|
|
|
): SessionState => ({
|
|
|
|
...state,
|
2023-08-24 07:48:30 +02:00
|
|
|
typebotsQueue: state.typebotsQueue.map((typebot, index) =>
|
|
|
|
index === 0
|
|
|
|
? {
|
|
|
|
...typebot,
|
|
|
|
typebot: {
|
|
|
|
...typebot.typebot,
|
|
|
|
edges: [...typebot.typebot.edges, edge],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: typebot
|
|
|
|
),
|
2023-03-03 15:03:31 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
export const createPortalEdge = ({ to }: Pick<Edge, 'to'>) => ({
|
2024-05-15 14:24:55 +02:00
|
|
|
id: 'virtual-' + createId(),
|
2023-03-03 15:03:31 +01:00
|
|
|
from: { blockId: '', groupId: '' },
|
|
|
|
to,
|
|
|
|
})
|