Skip to content

Commit

Permalink
fix(engine): 🐛 Number var
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 27, 2022
1 parent d02f267 commit d6b5568
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions packages/bot-engine/src/contexts/TypebotContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/bot-engine/src/services/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

4 comments on commit d6b5568

@vercel
Copy link

@vercel vercel bot commented on d6b5568 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 d6b5568 May 27, 2022

@vercel
Copy link

@vercel vercel bot commented on d6b5568 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 d6b5568 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

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

Please sign in to comment.