From e72934d29af114dfc66d55776833d359a5ebe7af Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Fri, 27 May 2022 10:07:41 -0700 Subject: [PATCH] =?UTF-8?q?fix(engine):=20=F0=9F=90=9B=20Don't=20parse=20"?= =?UTF-8?q?004"=20as=20number=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/bot-engine/src/contexts/TypebotContext.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/bot-engine/src/contexts/TypebotContext.tsx b/packages/bot-engine/src/contexts/TypebotContext.tsx index af760c9b3..4928c34f1 100644 --- a/packages/bot-engine/src/contexts/TypebotContext.tsx +++ b/packages/bot-engine/src/contexts/TypebotContext.tsx @@ -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)