Skip to content

Commit

Permalink
fix(engine): 🐛 Don't parse "004" as number 4
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 27, 2022
1 parent 2cb8330 commit e72934d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/bot-engine/src/contexts/TypebotContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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)

4 comments on commit e72934d

@vercel
Copy link

@vercel vercel bot commented on e72934d May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on e72934d May 27, 2022

@vercel
Copy link

@vercel vercel bot commented on e72934d May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on e72934d May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.