import React, { useCallback, useEffect, useRef, useState } from 'react' import dayjs from 'dayjs' import { Link, useParams } from 'react-router-dom' import { getNavigationsValue } from '@ijl/cli' import { useForm, Controller } from 'react-hook-form' import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, Container, Box, Card, CardBody, CardHeader, Heading, Button, ButtonGroup, CloseButton, useToast, Stack, VStack, FormControl, FormLabel, FormHelperText, FormErrorMessage, Input, TableContainer, Table, Thead, Tr, Th, Tbody, Td, } from '@chakra-ui/react' import { AddIcon } from '@chakra-ui/icons' import { LessonItem, Lessonname, ErrorSpan, BreadcrumbsWrapper } from './style' import { keycloak } from '../__data__/kc' import { useAppSelector } from '../__data__/store' import { api } from '../__data__/api/api' import { isTeacher } from '../utils/user' import { qrCode } from '../assets' interface NewLessonForm { name: string date: string } const LessonList = () => { const { courseId } = useParams() const user = useAppSelector((s) => s.user) const { data, isLoading, error } = api.useLessonListQuery(courseId) const [createLesson, crLQuery] = api.useCreateLessonMutation() const [value, setValue] = useState('') const [showForm, setShowForm] = useState(false) const { control, handleSubmit, reset, formState: { errors }, getValues, } = useForm({ defaultValues: { name: '', date: '', }, }) const toast = useToast() const toastRef = useRef(null) const handleChange = useCallback( (event) => { setValue(event.target.value.toUpperCase()) }, [setValue], ) const onSubmit = ({ name, date }) => { toastRef.current = toast({ title: 'Отправляем', status: 'loading', duration: 9000, }) createLesson({ name, courseId, date }) } useEffect(() => { if (crLQuery.isSuccess) { const values = getValues() if (toastRef.current) { toast.update(toastRef.current, { title: 'Лекция создана', description: `Лекция ${values.name} успешно создана`, status: 'success', duration: 9000, isClosable: true, }) } reset() } }, [crLQuery.isSuccess]) return ( <> Журнал Курс {isTeacher(user) && ( {showForm ? ( Создание лекции setShowForm(false)} />
( Дата {errors.date ? ( {errors.date?.message} ) : ( Укажите дату и время лекции )} )} /> ( Название новой лекции: {errors.name && ( {errors.name.message} )} )} /> {crLQuery.error && ( {(crLQuery.error as any).error} )}
) : ( )}
)} {data?.body?.map((lesson) => ( ))}
ссылка Дата into Участников
{dayjs(lesson.date).format('H:mm DD.MM.YY')} {lesson.name} {lesson.students.length}
{/* */}
) } export default LessonList