2
0

feat(inputs): Add Set variable step

This commit is contained in:
Baptiste Arnaud
2022-01-14 07:49:24 +01:00
parent 13f72f5ff7
commit 4ccb7bca49
55 changed files with 1024 additions and 223 deletions

View File

@ -1,8 +1,9 @@
import { PublicTypebot } from 'models'
import React, { createContext, ReactNode, useContext } from 'react'
import React, { createContext, ReactNode, useContext, useState } from 'react'
const typebotContext = createContext<{
typebot: PublicTypebot
updateVariableValue: (variableId: string, value: string) => void
//@ts-ignore
}>({})
@ -13,10 +14,25 @@ export const TypebotContext = ({
children: ReactNode
typebot: PublicTypebot
}) => {
const [localTypebot, setLocalTypebot] = useState<PublicTypebot>(typebot)
const updateVariableValue = (variableId: string, value: string) => {
setLocalTypebot((typebot) => ({
...typebot,
variables: {
...typebot.variables,
byId: {
...typebot.variables.byId,
[variableId]: { ...typebot.variables.byId[variableId], value },
},
},
}))
}
return (
<typebotContext.Provider
value={{
typebot,
typebot: localTypebot,
updateVariableValue,
}}
>
{children}