2
0

🚸 (typebotLink) Make sure variables from child bots are merged if necessary

This commit is contained in:
Baptiste Arnaud
2023-09-18 10:59:56 +02:00
parent 0ccc2efa45
commit 21ad061f7b

View File

@@ -1,6 +1,7 @@
import { byId } from '@typebot.io/lib' import { byId, isNotDefined } from '@typebot.io/lib'
import { Group, SessionState } from '@typebot.io/schemas' import { Group, SessionState, VariableWithValue } from '@typebot.io/schemas'
import { upsertResult } from '../queries/upsertResult' import { upsertResult } from '../queries/upsertResult'
import { isDefined } from '@udecode/plate-common'
export type NextGroup = { export type NextGroup = {
group?: Group group?: Group
@@ -31,15 +32,25 @@ export const getNextGroup =
typebot: isMergingWithParent typebot: isMergingWithParent
? { ? {
...state.typebotsQueue[1].typebot, ...state.typebotsQueue[1].typebot,
variables: state.typebotsQueue[1].typebot.variables.map( variables: state.typebotsQueue[1].typebot.variables
(variable) => ({ .map((variable) => ({
...variable, ...variable,
value: value:
state.typebotsQueue[0].answers.find( state.typebotsQueue[0].answers.find(
(answer) => answer.key === variable.name (answer) => answer.key === variable.name
)?.value ?? variable.value, )?.value ?? variable.value,
}) }))
), .concat(
state.typebotsQueue[0].typebot.variables.filter(
(variable) =>
isDefined(variable.value) &&
isNotDefined(
state.typebotsQueue[1].typebot.variables.find(
(v) => v.name === variable.name
)
)
) as VariableWithValue[]
),
} }
: state.typebotsQueue[1].typebot, : state.typebotsQueue[1].typebot,
answers: isMergingWithParent answers: isMergingWithParent