2
0

fix(engine): 🐛 Number var

This commit is contained in:
Baptiste Arnaud
2022-05-27 11:14:02 -07:00
parent d02f267588
commit d6b5568e03
2 changed files with 7 additions and 4 deletions

View File

@ -66,7 +66,7 @@ export const TypebotContext = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [typebot.theme, typebot.settings])
const updateVariableValue = (variableId: string, value: string) => {
const updateVariableValue = (variableId: string, value: string | number) => {
const formattedValue = formatIncomingVariableValue(value)
setLocalTypebot((typebot) => ({
...typebot,
@ -134,9 +134,12 @@ export const TypebotContext = ({
)
}
const formatIncomingVariableValue = (value: string): string | number => {
const formatIncomingVariableValue = (
value: string | number
): string | number => {
// This first check avoid to parse 004 as the number 4.
if (value.startsWith('0') && value.length > 1) return value
if (typeof value === 'string' && value.startsWith('0') && value.length > 1)
return value
return isNaN(Number(value)) ? value : Number(value)
}

View File

@ -22,7 +22,7 @@ export const parseVariables =
if (!variable) return ''
if (options.fieldToParse === 'id') return variable.id
const { value } = variable
if (!value) return ''
if (isNotDefined(value)) return ''
if (options.escapeLineBreaks)
return value.toString().replace(/\n/g, '\\n')
return value.toString()