⚡ (numberInput) Variabalize min, max, step
This commit is contained in:
@ -14,9 +14,11 @@ export const NumberInputSettings = ({ options, onOptionsChange }: Props) => {
|
|||||||
onOptionsChange({ ...options, labels: { ...options.labels, placeholder } })
|
onOptionsChange({ ...options, labels: { ...options.labels, placeholder } })
|
||||||
const handleButtonLabelChange = (button: string) =>
|
const handleButtonLabelChange = (button: string) =>
|
||||||
onOptionsChange({ ...options, labels: { ...options.labels, button } })
|
onOptionsChange({ ...options, labels: { ...options.labels, button } })
|
||||||
const handleMinChange = (min?: number) => onOptionsChange({ ...options, min })
|
const handleMinChange = (min?: NumberInputOptions['min']) =>
|
||||||
const handleMaxChange = (max?: number) => onOptionsChange({ ...options, max })
|
onOptionsChange({ ...options, min })
|
||||||
const handleStepChange = (step?: number) =>
|
const handleMaxChange = (max?: NumberInputOptions['max']) =>
|
||||||
|
onOptionsChange({ ...options, max })
|
||||||
|
const handleStepChange = (step?: NumberInputOptions['step']) =>
|
||||||
onOptionsChange({ ...options, step })
|
onOptionsChange({ ...options, step })
|
||||||
const handleVariableChange = (variable?: Variable) => {
|
const handleVariableChange = (variable?: Variable) => {
|
||||||
onOptionsChange({ ...options, variableId: variable?.id })
|
onOptionsChange({ ...options, variableId: variable?.id })
|
||||||
@ -38,19 +40,16 @@ export const NumberInputSettings = ({ options, onOptionsChange }: Props) => {
|
|||||||
label="Min:"
|
label="Min:"
|
||||||
defaultValue={options.min}
|
defaultValue={options.min}
|
||||||
onValueChange={handleMinChange}
|
onValueChange={handleMinChange}
|
||||||
withVariableButton={false}
|
|
||||||
/>
|
/>
|
||||||
<NumberInput
|
<NumberInput
|
||||||
label="Max:"
|
label="Max:"
|
||||||
defaultValue={options.max}
|
defaultValue={options.max}
|
||||||
onValueChange={handleMaxChange}
|
onValueChange={handleMaxChange}
|
||||||
withVariableButton={false}
|
|
||||||
/>
|
/>
|
||||||
<NumberInput
|
<NumberInput
|
||||||
label="Step:"
|
label="Step:"
|
||||||
defaultValue={options.step}
|
defaultValue={options.step}
|
||||||
onValueChange={handleStepChange}
|
onValueChange={handleStepChange}
|
||||||
withVariableButton={false}
|
|
||||||
/>
|
/>
|
||||||
<Stack>
|
<Stack>
|
||||||
<FormLabel mb="0" htmlFor="variable">
|
<FormLabel mb="0" htmlFor="variable">
|
||||||
|
@ -14,6 +14,7 @@ import {
|
|||||||
isInputBlock,
|
isInputBlock,
|
||||||
isIntegrationBlock,
|
isIntegrationBlock,
|
||||||
isLogicBlock,
|
isLogicBlock,
|
||||||
|
isNotEmpty,
|
||||||
} from '@typebot.io/lib'
|
} from '@typebot.io/lib'
|
||||||
import { executeLogic } from './executeLogic'
|
import { executeLogic } from './executeLogic'
|
||||||
import { getNextGroup } from './getNextGroup'
|
import { getNextGroup } from './getNextGroup'
|
||||||
@ -195,6 +196,29 @@ const parseInput =
|
|||||||
state.typebot.variables
|
state.typebot.variables
|
||||||
)(block)
|
)(block)
|
||||||
}
|
}
|
||||||
|
case InputBlockType.NUMBER: {
|
||||||
|
const parsedBlock = deepParseVariables(state.typebot.variables)({
|
||||||
|
...block,
|
||||||
|
prefilledValue: getPrefilledInputValue(state.typebot.variables)(
|
||||||
|
block
|
||||||
|
),
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
...parsedBlock,
|
||||||
|
options: {
|
||||||
|
...parsedBlock.options,
|
||||||
|
min: isNotEmpty(parsedBlock.options.min as string)
|
||||||
|
? Number(parsedBlock.options.min)
|
||||||
|
: undefined,
|
||||||
|
max: isNotEmpty(parsedBlock.options.max as string)
|
||||||
|
? Number(parsedBlock.options.max)
|
||||||
|
: undefined,
|
||||||
|
step: isNotEmpty(parsedBlock.options.step as string)
|
||||||
|
? Number(parsedBlock.options.step)
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
return deepParseVariables(state.typebot.variables)({
|
return deepParseVariables(state.typebot.variables)({
|
||||||
...block,
|
...block,
|
||||||
|
@ -3,14 +3,15 @@ import { optionBaseSchema, blockBaseSchema } from '../baseSchemas'
|
|||||||
import { defaultButtonLabel } from './constants'
|
import { defaultButtonLabel } from './constants'
|
||||||
import { InputBlockType } from './enums'
|
import { InputBlockType } from './enums'
|
||||||
import { textInputOptionsBaseSchema } from './text'
|
import { textInputOptionsBaseSchema } from './text'
|
||||||
|
import { variableStringSchema } from '../../utils'
|
||||||
|
|
||||||
export const numberInputOptionsSchema = optionBaseSchema
|
export const numberInputOptionsSchema = optionBaseSchema
|
||||||
.merge(textInputOptionsBaseSchema)
|
.merge(textInputOptionsBaseSchema)
|
||||||
.merge(
|
.merge(
|
||||||
z.object({
|
z.object({
|
||||||
min: z.number().optional(),
|
min: z.number().or(variableStringSchema).optional(),
|
||||||
max: z.number().optional(),
|
max: z.number().or(variableStringSchema).optional(),
|
||||||
step: z.number().optional(),
|
step: z.number().or(variableStringSchema).optional(),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user