2
0
Files
bot/apps/builder/components/shared/Graph/Nodes/StepNode/SettingsPopoverContent/SettingsPopoverContent.tsx

233 lines
5.8 KiB
TypeScript
Raw Normal View History

2022-01-15 17:30:20 +01:00
import {
PopoverContent,
PopoverArrow,
PopoverBody,
useEventListener,
Portal,
2022-01-19 09:44:21 +01:00
IconButton,
2022-01-15 17:30:20 +01:00
} from '@chakra-ui/react'
2022-01-19 09:44:21 +01:00
import { ExpandIcon } from 'assets/icons'
2022-01-12 09:10:59 +01:00
import {
ConditionItem,
ConditionStep,
2022-01-12 09:10:59 +01:00
InputStepType,
IntegrationStepType,
LogicStepType,
Step,
StepOptions,
2022-01-20 16:14:47 +01:00
TextBubbleStep,
2022-01-22 18:24:57 +01:00
Webhook,
2022-01-12 09:10:59 +01:00
} from 'models'
2022-01-15 17:30:20 +01:00
import { useRef } from 'react'
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'
2022-03-07 17:39:57 +01:00
import { CodeSettings } from './bodies/CodeSettings'
2022-01-15 17:30:20 +01:00
import { ConditionSettingsBody } from './bodies/ConditionSettingsBody'
import { GoogleAnalyticsSettings } from './bodies/GoogleAnalyticsSettings'
import { GoogleSheetsSettingsBody } from './bodies/GoogleSheetsSettingsBody'
import { PhoneNumberSettingsBody } from './bodies/PhoneNumberSettingsBody'
2022-01-20 07:21:08 +01:00
import { RedirectSettings } from './bodies/RedirectSettings'
2022-03-09 15:12:00 +01:00
import { SendEmailSettings } from './bodies/SendEmailSettings'
import { SetVariableSettings } from './bodies/SetVariableSettings'
2022-03-09 15:12:00 +01:00
import { TypebotLinkSettingsForm } from './bodies/TypebotLinkSettingsForm'
2022-01-22 18:24:57 +01:00
import { WebhookSettings } from './bodies/WebhookSettings'
2022-02-22 08:03:38 +01:00
import { ZapierSettings } from './bodies/ZapierSettings'
2022-01-06 16:54:23 +01:00
type Props = {
2022-01-20 16:14:47 +01:00
step: Exclude<Step, TextBubbleStep>
webhook?: Webhook
2022-01-19 09:44:21 +01:00
onExpandClick: () => void
onStepChange: (updates: Partial<Step>) => void
2022-01-06 16:54:23 +01:00
}
export const SettingsPopoverContent = ({ onExpandClick, ...props }: Props) => {
2022-01-15 17:30:20 +01:00
const ref = useRef<HTMLDivElement | null>(null)
2022-01-06 16:54:23 +01:00
const handleMouseDown = (e: React.MouseEvent) => e.stopPropagation()
2022-01-15 17:30:20 +01:00
const handleMouseWheel = (e: WheelEvent) => {
e.stopPropagation()
}
useEventListener('wheel', handleMouseWheel, ref.current)
2022-01-06 16:54:23 +01:00
return (
<Portal>
<PopoverContent onMouseDown={handleMouseDown} pos="relative">
<PopoverArrow />
2022-01-19 09:44:21 +01:00
<PopoverBody
pt="10"
pb="6"
2022-01-19 09:44:21 +01:00
overflowY="scroll"
maxH="400px"
ref={ref}
shadow="lg"
>
<StepSettings {...props} />
</PopoverBody>
<IconButton
pos="absolute"
top="5px"
right="5px"
aria-label="expand"
icon={<ExpandIcon />}
size="xs"
onClick={onExpandClick}
/>
</PopoverContent>
</Portal>
2022-01-06 16:54:23 +01:00
)
}
export const StepSettings = ({
step,
onStepChange,
}: {
step: Step
webhook?: Webhook
onStepChange: (step: Partial<Step>) => void
}) => {
const handleOptionsChange = (options: StepOptions) => {
onStepChange({ options } as Partial<Step>)
}
const handleItemChange = (updates: Partial<ConditionItem>) => {
onStepChange({
items: [{ ...(step as ConditionStep).items[0], ...updates }],
} as Partial<Step>)
}
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-06 16:54:23 +01:00
/>
)
}
2022-01-08 07:40:55 +01:00
case InputStepType.NUMBER: {
return (
<NumberInputSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
2022-01-08 07:40:55 +01:00
/>
)
}
2022-01-08 08:20:54 +01:00
case InputStepType.EMAIL: {
return (
<EmailInputSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
2022-01-08 08:20:54 +01:00
/>
)
}
2022-01-09 07:36:29 +01:00
case InputStepType.URL: {
return (
<UrlInputSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
2022-01-09 07:36:29 +01:00
/>
)
}
2022-01-10 08:05:03 +01:00
case InputStepType.DATE: {
return (
<DateInputSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
2022-01-10 08:05:03 +01:00
/>
)
}
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}
2022-01-12 09:10:59 +01:00
/>
)
}
case LogicStepType.SET_VARIABLE: {
return (
<SetVariableSettings
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-01-15 17:30:20 +01:00
case LogicStepType.CONDITION: {
return (
<ConditionSettingsBody step={step} onItemChange={handleItemChange} />
2022-01-15 17:30:20 +01:00
)
}
2022-01-20 07:21:08 +01:00
case LogicStepType.REDIRECT: {
return (
<RedirectSettings
options={step.options}
onOptionsChange={handleOptionsChange}
2022-03-07 17:39:57 +01:00
/>
)
}
case LogicStepType.CODE: {
return (
<CodeSettings
options={step.options}
onOptionsChange={handleOptionsChange}
2022-01-20 07:21:08 +01:00
/>
)
}
2022-03-09 15:12:00 +01:00
case LogicStepType.TYPEBOT_LINK: {
return (
<TypebotLinkSettingsForm
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
case IntegrationStepType.GOOGLE_SHEETS: {
return (
<GoogleSheetsSettingsBody
options={step.options}
onOptionsChange={handleOptionsChange}
stepId={step.id}
/>
)
}
case IntegrationStepType.GOOGLE_ANALYTICS: {
return (
<GoogleAnalyticsSettings
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-02-22 08:03:38 +01:00
case IntegrationStepType.ZAPIER: {
return <ZapierSettings step={step} />
}
2022-01-22 18:24:57 +01:00
case IntegrationStepType.WEBHOOK: {
return (
2022-03-09 15:12:00 +01:00
<WebhookSettings step={step} onOptionsChange={handleOptionsChange} />
2022-01-22 18:24:57 +01:00
)
}
case IntegrationStepType.EMAIL: {
return (
<SendEmailSettings
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-01-06 16:54:23 +01:00
default: {
return <></>
}
}
}