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,
|
2022-01-25 18:19:37 +01:00
|
|
|
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-29 11:22:22 +01:00
|
|
|
<PopoverContent onMouseDown={handleMouseDown} w="500px">
|
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
|
|
|
|
2022-01-25 18:19:37 +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
|
2022-01-25 18:19:37 +01:00
|
|
|
url={step.content?.url}
|
2022-01-20 17:45:25 +01:00
|
|
|
onSubmit={handleContentChange}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
case BubbleStepType.VIDEO: {
|
|
|
|
return (
|
|
|
|
<VideoUploadContent
|
|
|
|
content={step.content}
|
2022-01-25 18:19:37 +01:00
|
|
|
onSubmit={handleVideoContentChange}
|
2022-01-20 16:14:47 +01:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|