2
0
Files
bot/apps/builder/components/board/graph/BlockNode/StepNode/SettingsPopoverContent/SettingsPopoverContent.tsx

116 lines
2.8 KiB
TypeScript
Raw Normal View History

2022-01-06 16:54:23 +01:00
import { PopoverContent, PopoverArrow, PopoverBody } from '@chakra-ui/react'
import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
2022-01-12 09:10:59 +01:00
import {
ChoiceInputOptions,
InputStep,
InputStepType,
LogicStepType,
SetVariableOptions,
Step,
2022-01-12 09:10:59 +01:00
TextInputOptions,
} from 'models'
2022-01-10 08:05:03 +01:00
import {
TextInputSettingsBody,
NumberInputSettingsBody,
EmailInputSettingsBody,
UrlInputSettingsBody,
DateInputSettingsBody,
} from './bodies'
2022-01-12 09:10:59 +01:00
import { ChoiceInputSettingsBody } from './bodies/ChoiceInputSettingsBody'
import { PhoneNumberSettingsBody } from './bodies/PhoneNumberSettingsBody'
import { SetVariableSettingsBody } from './bodies/SetVariableSettingsBody'
2022-01-06 16:54:23 +01:00
type Props = {
step: Step
2022-01-06 16:54:23 +01:00
}
2022-01-06 16:54:23 +01:00
export const SettingsPopoverContent = ({ step }: Props) => {
const handleMouseDown = (e: React.MouseEvent) => e.stopPropagation()
return (
<PopoverContent onMouseDown={handleMouseDown}>
<PopoverArrow />
<PopoverBody p="6">
<SettingsPopoverBodyContent step={step} />
</PopoverBody>
</PopoverContent>
)
}
const SettingsPopoverBodyContent = ({ step }: Props) => {
const { updateStep } = useTypebot()
2022-01-12 09:10:59 +01:00
const handleOptionsChange = (
options: TextInputOptions | ChoiceInputOptions | SetVariableOptions
2022-01-12 09:10:59 +01:00
) => updateStep(step.id, { options } as Partial<InputStep>)
2022-01-06 16:54:23 +01:00
switch (step.type) {
2022-01-08 07:40:55 +01:00
case InputStepType.TEXT: {
2022-01-06 16:54:23 +01:00
return (
<TextInputSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-01-08 07:40:55 +01:00
case InputStepType.NUMBER: {
return (
<NumberInputSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-01-08 08:20:54 +01:00
case InputStepType.EMAIL: {
return (
<EmailInputSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-01-09 07:36:29 +01:00
case InputStepType.URL: {
return (
<UrlInputSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-01-10 08:05:03 +01:00
case InputStepType.DATE: {
return (
<DateInputSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
case InputStepType.PHONE: {
return (
<PhoneNumberSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-01-12 09:10:59 +01:00
case InputStepType.CHOICE: {
return (
<ChoiceInputSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
case LogicStepType.SET_VARIABLE: {
return (
<SetVariableSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-01-06 16:54:23 +01:00
default: {
return <></>
}
}
}