2
0

fix(engine): 🐛 Don't parse "004" as number 4

This commit is contained in:
Baptiste Arnaud
2022-05-27 10:07:41 -07:00
parent 2cb8330790
commit e72934d29a

View File

@ -67,9 +67,7 @@ export const TypebotContext = ({
}, [typebot.theme, typebot.settings])
const updateVariableValue = (variableId: string, value: string) => {
const formattedValue: string | number = isNaN(Number(value))
? value
: Number(value)
const formattedValue = formatIncomingVariableValue(value)
setLocalTypebot((typebot) => ({
...typebot,
variables: typebot.variables.map((v) =>
@ -136,4 +134,10 @@ export const TypebotContext = ({
)
}
const formatIncomingVariableValue = (value: string): string | number => {
// This first check avoid to parse 004 as the number 4.
if (value.startsWith('0') && value.length > 1) return value
return isNaN(Number(value)) ? value : Number(value)
}
export const useTypebot = () => useContext(typebotContext)