2
0

🐛 Fix default webhook body with multi inputs groups

This commit is contained in:
Baptiste Arnaud
2023-11-27 14:51:50 +01:00
parent 2c203f3b6d
commit 880ded97d1

View File

@ -261,9 +261,7 @@ const saveAnswer =
? state.typebotsQueue[0].typebot.variables.find(
(variable) => variable.id === block.options?.variableId
)?.name
: state.typebotsQueue[0].typebot.groups.find((group) =>
group.blocks.find((blockInGroup) => blockInGroup.id === block.id)
)?.title
: parseGroupKey(block.id, { state })
return setNewAnswerInState(state)({
key: key ?? block.id,
@ -271,6 +269,21 @@ const saveAnswer =
})
}
const parseGroupKey = (blockId: string, { state }: { state: SessionState }) => {
const group = state.typebotsQueue[0].typebot.groups.find((group) =>
group.blocks.find((b) => b.id === blockId)
)
if (!group) return
const inputBlockNumber = group.blocks
.filter(isInputBlock)
.findIndex((b) => b.id === blockId)
return inputBlockNumber > 0
? `${group.title} (${inputBlockNumber})`
: group?.title
}
const setNewAnswerInState =
(state: SessionState) => (newAnswer: AnswerInSessionState) => {
const answers = state.typebotsQueue[0].answers