feat(inputs): ✨ Add number input
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
import { InputStep, PublicTypebot, Step, StepType, Typebot } from 'models'
|
||||
import { PublicTypebot, Typebot } from 'models'
|
||||
import { sendRequest } from './utils'
|
||||
import shortId from 'short-uuid'
|
||||
import { HStack, Text } from '@chakra-ui/react'
|
||||
import { CalendarIcon } from 'assets/icons'
|
||||
import { StepIcon } from 'components/board/StepTypesList/StepIcon'
|
||||
import { isInputStep } from 'utils'
|
||||
|
||||
export const parseTypebotToPublicTypebot = (
|
||||
typebot: Typebot
|
||||
@ -59,7 +60,7 @@ export const parseSubmissionsColumns = (
|
||||
.map((blockId) => {
|
||||
const block = typebot.blocks.byId[blockId]
|
||||
const inputStepId = block.stepIds.find((stepId) =>
|
||||
stepIsInput(typebot.steps.byId[stepId])
|
||||
isInputStep(typebot.steps.byId[stepId])
|
||||
)
|
||||
const inputStep = typebot.steps.byId[inputStepId as string]
|
||||
return {
|
||||
@ -80,8 +81,5 @@ const blockContainsInput = (
|
||||
blockId: string
|
||||
) =>
|
||||
typebot.blocks.byId[blockId].stepIds.some((stepId) =>
|
||||
stepIsInput(typebot.steps.byId[stepId])
|
||||
isInputStep(typebot.steps.byId[stepId])
|
||||
)
|
||||
|
||||
export const stepIsInput = (step: Step): step is InputStep =>
|
||||
step.type === StepType.TEXT_INPUT
|
||||
|
@ -1,14 +1,15 @@
|
||||
import {
|
||||
Step,
|
||||
StepType,
|
||||
Block,
|
||||
TextStep,
|
||||
TextInputStep,
|
||||
PublicTypebot,
|
||||
BackgroundType,
|
||||
Settings,
|
||||
StartStep,
|
||||
Theme,
|
||||
BubbleStep,
|
||||
InputStep,
|
||||
BubbleStepType,
|
||||
InputStepType,
|
||||
} from 'models'
|
||||
import shortId from 'short-uuid'
|
||||
import { Typebot } from 'models'
|
||||
@ -104,10 +105,13 @@ export const parseNewBlock = ({
|
||||
}
|
||||
}
|
||||
|
||||
export const parseNewStep = (type: StepType, blockId: string): Step => {
|
||||
export const parseNewStep = (
|
||||
type: BubbleStepType | InputStepType,
|
||||
blockId: string
|
||||
): BubbleStep | InputStep => {
|
||||
const id = `s${shortId.generate()}`
|
||||
switch (type) {
|
||||
case StepType.TEXT: {
|
||||
case BubbleStepType.TEXT: {
|
||||
const textStep: Pick<TextStep, 'type' | 'content'> = {
|
||||
type,
|
||||
content: { html: '', richText: [], plainText: '' },
|
||||
@ -118,22 +122,12 @@ export const parseNewStep = (type: StepType, blockId: string): Step => {
|
||||
...textStep,
|
||||
}
|
||||
}
|
||||
case StepType.TEXT_INPUT: {
|
||||
const textStep: Pick<TextInputStep, 'type'> = {
|
||||
type,
|
||||
}
|
||||
return {
|
||||
id,
|
||||
blockId,
|
||||
...textStep,
|
||||
}
|
||||
}
|
||||
default: {
|
||||
const textStep: Pick<TextStep, 'type' | 'content'> = {
|
||||
type: StepType.TEXT,
|
||||
content: { html: '', richText: [], plainText: '' },
|
||||
return {
|
||||
id,
|
||||
blockId,
|
||||
type,
|
||||
}
|
||||
return { blockId, id, ...textStep }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -180,7 +174,7 @@ export const parseNewTypebot = ({
|
||||
blockId: startBlockId,
|
||||
id: startStepId,
|
||||
label: 'Start',
|
||||
type: StepType.START,
|
||||
type: 'start',
|
||||
}
|
||||
const startBlock: Block = {
|
||||
id: startBlockId,
|
||||
@ -211,6 +205,3 @@ export const parseNewTypebot = ({
|
||||
settings,
|
||||
}
|
||||
}
|
||||
|
||||
export const isStepText = (step: Step): step is TextStep =>
|
||||
step.type === StepType.TEXT
|
||||
|
@ -106,3 +106,12 @@ export const uploadFile = async (file: File, key: string) => {
|
||||
url: upload.ok ? `${url}/${key}` : null,
|
||||
}
|
||||
}
|
||||
|
||||
export const removeUndefinedFields = <T>(obj: T): T =>
|
||||
Object.keys(obj).reduce(
|
||||
(acc, key) =>
|
||||
obj[key as keyof T] === undefined
|
||||
? { ...acc }
|
||||
: { ...acc, [key]: obj[key as keyof T] },
|
||||
{} as T
|
||||
)
|
||||
|
Reference in New Issue
Block a user