import FormLayout, { ButtonBlack, Flex, FormField, FormLabel, FormMessage, Input, } from '@components/Objects/StyledElements/Form/Form' import React, { useState } from 'react' import * as Form from '@radix-ui/react-form' import BarLoader from 'react-spinners/BarLoader' import { Youtube } from 'lucide-react' import { constructAcceptValue } from '@/lib/constants'; const SUPPORTED_FILES = constructAcceptValue(['mp4', 'webm']) interface ExternalVideoObject { name: string type: string uri: string chapter_id: string } function VideoModal({ submitFileActivity, submitExternalVideo, chapterId, course, }: any) { const [video, setVideo] = React.useState(null) as any const [isSubmitting, setIsSubmitting] = useState(false) const [name, setName] = React.useState('') const [youtubeUrl, setYoutubeUrl] = React.useState('') const [selectedView, setSelectedView] = React.useState('file') as any const handleVideoChange = (event: React.ChangeEvent) => { setVideo(event.target.files[0]) } const handleNameChange = (event: React.ChangeEvent) => { setName(event.target.value) } const handleYoutubeUrlChange = ( event: React.ChangeEvent ) => { setYoutubeUrl(event.target.value) } const handleSubmit = async (e: any) => { e.preventDefault() setIsSubmitting(true) if (selectedView === 'file') { let status = await submitFileActivity( video, 'video', { name: name, chapter_id: chapterId, activity_type: 'TYPE_VIDEO', activity_sub_type: 'SUBTYPE_VIDEO_HOSTED', published_version: 1, version: 1, course_id: course.id, }, chapterId ) setIsSubmitting(false) } if (selectedView === 'youtube') { let external_video_object: ExternalVideoObject = { name, type: 'youtube', uri: youtubeUrl, chapter_id: chapterId, } let status = await submitExternalVideo( external_video_object, 'activity', chapterId ) setIsSubmitting(false) } } /* TODO : implement some sort of progress bar for file uploads, it is not possible yet because i'm not using axios. and the actual upload isn't happening here anyway, it's in the submitFileActivity function */ return ( Video name Please provide a name for your video activity
{ setSelectedView('file') }} className="rounded-full bg-slate-900 text-zinc-50 py-2 px-4 text-sm drop-shadow-md hover:cursor-pointer hover:bg-slate-700 " > Video upload
{ setSelectedView('youtube') }} className="rounded-full bg-slate-900 text-zinc-50 py-2 px-4 text-sm drop-shadow-md hover:cursor-pointer hover:bg-slate-700" > YouTube Video
{selectedView === 'file' && (
Video file Please provide a video for your activity
)} {selectedView === 'youtube' && (
YouTube URL Please provide a video for your activity
)}
{isSubmitting ? ( ) : ( 'Create activity' )}
) } export default VideoModal