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

68 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-01-20 16:14:47 +01:00
import {
Portal,
PopoverContent,
PopoverArrow,
PopoverBody,
} from '@chakra-ui/react'
2022-01-20 17:45:25 +01:00
import { ImageUploadContent } from 'components/shared/ImageUploadContent'
2022-01-20 16:14:47 +01:00
import { useTypebot } from 'contexts/TypebotContext'
import {
BubbleStep,
BubbleStepType,
ImageBubbleStep,
TextBubbleStep,
VideoBubbleContent,
VideoBubbleStep,
2022-01-20 16:14:47 +01:00
} from 'models'
import { useRef } from 'react'
2022-01-20 17:45:25 +01:00
import { VideoUploadContent } from './VideoUploadContent'
2022-01-20 16:14:47 +01:00
type Props = {
step: Exclude<BubbleStep, TextBubbleStep>
}
export const ContentPopover = ({ step }: Props) => {
const ref = useRef<HTMLDivElement | null>(null)
const handleMouseDown = (e: React.MouseEvent) => e.stopPropagation()
return (
<Portal>
2022-01-20 17:45:25 +01:00
<PopoverContent onMouseDown={handleMouseDown}>
2022-01-20 16:14:47 +01:00
<PopoverArrow />
<PopoverBody ref={ref} shadow="lg">
<StepContent step={step} />
</PopoverBody>
</PopoverContent>
</Portal>
)
}
export const StepContent = ({ step }: Props) => {
const { updateStep } = useTypebot()
2022-01-20 17:45:25 +01:00
const handleContentChange = (url: string) =>
updateStep(step.id, { content: { url } } as Partial<ImageBubbleStep>)
const handleVideoContentChange = (content: VideoBubbleContent) =>
updateStep(step.id, { content } as Partial<VideoBubbleStep>)
2022-01-20 16:14:47 +01:00
switch (step.type) {
case BubbleStepType.IMAGE: {
return (
2022-01-20 17:45:25 +01:00
<ImageUploadContent
url={step.content?.url}
2022-01-20 17:45:25 +01:00
onSubmit={handleContentChange}
/>
)
}
case BubbleStepType.VIDEO: {
return (
<VideoUploadContent
content={step.content}
onSubmit={handleVideoContentChange}
2022-01-20 16:14:47 +01:00
/>
)
}
}
}