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

162 lines
4.4 KiB
TypeScript
Raw Normal View History

2022-01-15 17:30:20 +01:00
import { Flex, HStack, Stack, Tag, Text } from '@chakra-ui/react'
import { useTypebot } from 'contexts/TypebotContext'
import {
Step,
StartStep,
BubbleStepType,
InputStepType,
LogicStepType,
SetVariableStep,
2022-01-15 17:30:20 +01:00
ConditionStep,
IntegrationStepType,
} from 'models'
2022-01-12 09:10:59 +01:00
import { ChoiceItemsList } from './ChoiceInputStepNode/ChoiceItemsList'
2022-01-15 17:30:20 +01:00
import { SourceEndpoint } from './SourceEndpoint'
2022-01-08 07:40:55 +01:00
2022-01-12 09:10:59 +01:00
type Props = {
step: Step | StartStep
isConnectable?: boolean
}
export const StepNodeContent = ({ step }: Props) => {
switch (step.type) {
2022-01-08 07:40:55 +01:00
case BubbleStepType.TEXT: {
return (
<Flex
flexDir={'column'}
2022-01-12 09:10:59 +01:00
opacity={step.content.html === '' ? '0.5' : '1'}
2022-01-08 07:40:55 +01:00
className="slate-html-container"
dangerouslySetInnerHTML={{
__html:
2022-01-12 09:10:59 +01:00
step.content.html === ''
2022-01-08 07:40:55 +01:00
? `<p>Click to edit...</p>`
2022-01-12 09:10:59 +01:00
: step.content.html,
2022-01-08 07:40:55 +01:00
}}
/>
)
}
case InputStepType.TEXT: {
return (
<Text color={'gray.500'}>
2022-01-12 09:10:59 +01:00
{step.options?.labels?.placeholder ?? 'Type your answer...'}
2022-01-08 07:40:55 +01:00
</Text>
)
}
case InputStepType.NUMBER: {
return (
<Text color={'gray.500'}>
2022-01-12 09:10:59 +01:00
{step.options?.labels?.placeholder ?? 'Type your answer...'}
2022-01-08 07:40:55 +01:00
</Text>
)
}
2022-01-08 08:20:54 +01:00
case InputStepType.EMAIL: {
return (
<Text color={'gray.500'}>
2022-01-12 09:10:59 +01:00
{step.options?.labels?.placeholder ?? 'Type your email...'}
2022-01-08 08:20:54 +01:00
</Text>
)
}
2022-01-09 07:36:29 +01:00
case InputStepType.URL: {
return (
<Text color={'gray.500'}>
2022-01-12 09:10:59 +01:00
{step.options?.labels?.placeholder ?? 'Type your URL...'}
2022-01-09 07:36:29 +01:00
</Text>
)
}
2022-01-10 08:05:03 +01:00
case InputStepType.DATE: {
return (
<Text color={'gray.500'}>
2022-01-12 09:10:59 +01:00
{step.options?.labels?.from ?? 'Pick a date...'}
2022-01-10 08:05:03 +01:00
</Text>
)
}
case InputStepType.PHONE: {
return (
<Text color={'gray.500'}>
2022-01-12 09:10:59 +01:00
{step.options?.labels?.placeholder ?? 'Your phone number...'}
</Text>
)
}
2022-01-12 09:10:59 +01:00
case InputStepType.CHOICE: {
return <ChoiceItemsList step={step} />
}
case LogicStepType.SET_VARIABLE: {
return <SetVariableNodeContent step={step} />
}
2022-01-15 17:30:20 +01:00
case LogicStepType.CONDITION: {
return <ConditionNodeContent step={step} />
}
case IntegrationStepType.GOOGLE_SHEETS: {
if (!step.options) return <Text color={'gray.500'}>Configure...</Text>
return <Text>{step.options?.action}</Text>
}
2022-01-08 07:40:55 +01:00
case 'start': {
2022-01-12 09:10:59 +01:00
return <Text>{step.label}</Text>
2022-01-08 07:40:55 +01:00
}
default: {
return <Text>No input</Text>
}
}
}
const SetVariableNodeContent = ({ step }: { step: SetVariableStep }) => {
const { typebot } = useTypebot()
const variableName =
typebot?.variables.byId[step.options?.variableId ?? '']?.name ?? ''
const expression = step.options?.expressionToEvaluate ?? ''
return (
<Text color={'gray.500'}>
{variableName === '' && expression === ''
? 'Click to edit...'
: `${variableName} = ${expression}`}
</Text>
)
}
2022-01-15 17:30:20 +01:00
const ConditionNodeContent = ({ step }: { step: ConditionStep }) => {
const { typebot } = useTypebot()
return (
<Flex>
<Stack color={'gray.500'}>
{step.options?.comparisons.allIds.map((comparisonId, idx) => {
const comparison = step.options?.comparisons.byId[comparisonId]
const variable = typebot?.variables.byId[comparison?.variableId ?? '']
return (
<HStack key={comparisonId} spacing={1}>
{idx > 0 && <Text>{step.options?.logicalOperator ?? ''}</Text>}
{variable?.name && (
<Tag bgColor="orange.400">{variable.name}</Tag>
)}
{comparison.comparisonOperator && (
<Text>{comparison?.comparisonOperator}</Text>
)}
{comparison?.value && (
<Tag bgColor={'green.400'}>{comparison.value}</Tag>
)}
</HStack>
)
})}
</Stack>
<SourceEndpoint
source={{
blockId: step.blockId,
stepId: step.id,
conditionType: 'true',
}}
pos="absolute"
top="7px"
right="15px"
/>
<SourceEndpoint
source={{
blockId: step.blockId,
stepId: step.id,
conditionType: 'false',
}}
pos="absolute"
bottom="7px"
right="15px"
/>
</Flex>
)
}