import React, { useEffect, useState } from 'react'; import { FormControl, FormHelperText, FormLabel, Text, Input, InputGroup, Stack, Box, Button, Textarea, Flex, Divider, } from '@chakra-ui/react'; import * as constants from '@educt/constants'; import { Controller, UseFormReturn } from 'react-hook-form'; import VideoUploader from '@educt/components/VideoUploader'; import FilesUploader from '@educt/components/FilesUploader'; import { FileSupportedFormatsEnum, VideoSupportedFormatsEnum } from '@educt/enums'; import type { AttachmentFileType, LessonVideoType } from '@educt/types'; import { DESCRIPTION_MAX_LENGTH } from './LessonForm.validator'; export type InputFields = { title: string; description: string; duration: string; video: File; linked_video_url?: string | undefined; materials?: FileList | undefined; }; export type LessonFormPropsType = { onSubmit: () => Promise; buttonLabel: string; isLoading: boolean; reactHookForm: UseFormReturn; preloadedVideo?: LessonVideoType | undefined; preloadedMaterials?: AttachmentFileType[] | undefined; }; const LessonForm: React.FC = ({ onSubmit, buttonLabel, isLoading, reactHookForm, preloadedVideo, preloadedMaterials, }) => { const { control, register, watch, formState: { errors, isDirty }, unregister, } = reactHookForm; const [isLinkedVideoUrl, setIsLinkedVideoUrl] = useState(false); const watchDescription = watch('description'); useEffect(() => { if (!isLinkedVideoUrl) { unregister('linked_video_url'); } }, [isLinkedVideoUrl]); return (
Title {errors.title?.message} e.g Introduction Description