feat(inputs): ✨ Add Set variable step
This commit is contained in:
@ -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}
|
||||
|
Reference in New Issue
Block a user