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

281 lines
7.2 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,
2022-06-11 07:27:38 +02:00
ConditionBlock,
InputBlockType,
IntegrationBlockType,
LogicBlockType,
Block,
BlockOptions,
BlockWithOptions,
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 { FileInputSettings } from './bodies/FileInputSettings'
import { GoogleAnalyticsSettings } from './bodies/GoogleAnalyticsSettings'
import { GoogleSheetsSettingsBody } from './bodies/GoogleSheetsSettingsBody'
2022-05-24 14:25:15 -07:00
import { PaymentSettings } from './bodies/PaymentSettings'
import { PhoneNumberSettingsBody } from './bodies/PhoneNumberSettingsBody'
2022-06-07 19:09:08 +02:00
import { RatingInputSettings } from './bodies/RatingInputSettingsBody'
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-06-11 07:27:38 +02:00
block: BlockWithOptions | ConditionBlock
webhook?: Webhook
2022-01-19 09:44:21 +01:00
onExpandClick: () => void
2022-06-11 07:27:38 +02:00
onBlockChange: (updates: Partial<Block>) => 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"
>
2022-06-11 07:27:38 +02:00
<BlockSettings {...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
)
}
2022-06-11 07:27:38 +02:00
export const BlockSettings = ({
block,
onBlockChange,
}: {
2022-06-11 07:27:38 +02:00
block: BlockWithOptions | ConditionBlock
webhook?: Webhook
2022-06-11 07:27:38 +02:00
onBlockChange: (block: Partial<Block>) => void
2022-06-07 19:09:08 +02:00
}): JSX.Element => {
2022-06-11 07:27:38 +02:00
const handleOptionsChange = (options: BlockOptions) => {
onBlockChange({ options } as Partial<Block>)
}
const handleItemChange = (updates: Partial<ConditionItem>) => {
2022-06-11 07:27:38 +02:00
onBlockChange({
items: [{ ...(block as ConditionBlock).items[0], ...updates }],
} as Partial<Block>)
}
2022-06-11 07:27:38 +02:00
switch (block.type) {
case InputBlockType.TEXT: {
2022-01-06 16:54:23 +01:00
return (
<TextInputSettingsBody
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
2022-01-06 16:54:23 +01:00
/>
)
}
2022-06-11 07:27:38 +02:00
case InputBlockType.NUMBER: {
2022-01-08 07:40:55 +01:00
return (
<NumberInputSettingsBody
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
2022-01-08 07:40:55 +01:00
/>
)
}
2022-06-11 07:27:38 +02:00
case InputBlockType.EMAIL: {
2022-01-08 08:20:54 +01:00
return (
<EmailInputSettingsBody
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
2022-01-08 08:20:54 +01:00
/>
)
}
2022-06-11 07:27:38 +02:00
case InputBlockType.URL: {
2022-01-09 07:36:29 +01:00
return (
<UrlInputSettingsBody
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
2022-01-09 07:36:29 +01:00
/>
)
}
2022-06-11 07:27:38 +02:00
case InputBlockType.DATE: {
2022-01-10 08:05:03 +01:00
return (
<DateInputSettingsBody
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
2022-01-10 08:05:03 +01:00
/>
)
}
2022-06-11 07:27:38 +02:00
case InputBlockType.PHONE: {
return (
<PhoneNumberSettingsBody
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-06-11 07:27:38 +02:00
case InputBlockType.CHOICE: {
2022-01-12 09:10:59 +01:00
return (
<ChoiceInputSettingsBody
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
2022-01-12 09:10:59 +01:00
/>
)
}
2022-06-11 07:27:38 +02:00
case InputBlockType.PAYMENT: {
2022-05-24 14:25:15 -07:00
return (
<PaymentSettings
2022-06-11 07:27:38 +02:00
options={block.options}
2022-05-24 14:25:15 -07:00
onOptionsChange={handleOptionsChange}
/>
)
}
2022-06-11 07:27:38 +02:00
case InputBlockType.RATING: {
2022-06-07 19:09:08 +02:00
return (
<RatingInputSettings
2022-06-11 07:27:38 +02:00
options={block.options}
2022-06-07 19:09:08 +02:00
onOptionsChange={handleOptionsChange}
/>
)
}
case InputBlockType.FILE: {
return (
<FileInputSettings
options={block.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-06-11 07:27:38 +02:00
case LogicBlockType.SET_VARIABLE: {
return (
<SetVariableSettings
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-06-11 07:27:38 +02:00
case LogicBlockType.CONDITION: {
2022-01-15 17:30:20 +01:00
return (
2022-06-11 07:27:38 +02:00
<ConditionSettingsBody block={block} onItemChange={handleItemChange} />
2022-01-15 17:30:20 +01:00
)
}
2022-06-11 07:27:38 +02:00
case LogicBlockType.REDIRECT: {
2022-01-20 07:21:08 +01:00
return (
<RedirectSettings
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
2022-03-07 17:39:57 +01:00
/>
)
}
2022-06-11 07:27:38 +02:00
case LogicBlockType.CODE: {
2022-03-07 17:39:57 +01:00
return (
<CodeSettings
2022-06-11 07:27:38 +02:00
options={block.options}
2022-03-07 17:39:57 +01:00
onOptionsChange={handleOptionsChange}
2022-01-20 07:21:08 +01:00
/>
)
}
2022-06-11 07:27:38 +02:00
case LogicBlockType.TYPEBOT_LINK: {
2022-03-09 15:12:00 +01:00
return (
<TypebotLinkSettingsForm
2022-06-11 07:27:38 +02:00
options={block.options}
2022-03-09 15:12:00 +01:00
onOptionsChange={handleOptionsChange}
/>
)
}
2022-06-11 07:27:38 +02:00
case IntegrationBlockType.GOOGLE_SHEETS: {
return (
<GoogleSheetsSettingsBody
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
2022-06-11 07:27:38 +02:00
blockId={block.id}
/>
)
}
2022-06-11 07:27:38 +02:00
case IntegrationBlockType.GOOGLE_ANALYTICS: {
return (
<GoogleAnalyticsSettings
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-06-11 07:27:38 +02:00
case IntegrationBlockType.ZAPIER: {
return <ZapierSettings block={block} />
2022-02-22 08:03:38 +01:00
}
2022-06-11 07:27:38 +02:00
case IntegrationBlockType.MAKE_COM: {
return (
<WebhookSettings
2022-06-11 07:27:38 +02:00
block={block}
onOptionsChange={handleOptionsChange}
provider={{
name: 'Make.com',
url: 'https://eu1.make.com/app/invite/43fa76a621f67ea27f96cffc3a2477e1',
}}
/>
)
}
2022-06-11 07:27:38 +02:00
case IntegrationBlockType.PABBLY_CONNECT: {
return (
<WebhookSettings
2022-06-11 07:27:38 +02:00
block={block}
onOptionsChange={handleOptionsChange}
provider={{
name: 'Pabbly Connect',
url: 'https://www.pabbly.com/connect/integrations/typebot/',
}}
/>
)
}
2022-06-11 07:27:38 +02:00
case IntegrationBlockType.WEBHOOK: {
2022-01-22 18:24:57 +01:00
return (
2022-06-11 07:27:38 +02:00
<WebhookSettings block={block} onOptionsChange={handleOptionsChange} />
2022-01-22 18:24:57 +01:00
)
}
2022-06-11 07:27:38 +02:00
case IntegrationBlockType.EMAIL: {
return (
<SendEmailSettings
2022-06-11 07:27:38 +02:00
options={block.options}
onOptionsChange={handleOptionsChange}
/>
)
}
2022-01-06 16:54:23 +01:00
}
}