2
0

feat(inputs): Add number input

This commit is contained in:
Baptiste Arnaud
2022-01-08 07:40:55 +01:00
parent 2a040308db
commit d54ebc0cbe
33 changed files with 467 additions and 207 deletions

View File

@ -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

View File

@ -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

View File

@ -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
)