7 Commits

Author SHA1 Message Date
Primakov Alexandr Alexandrovich
e56f0e4e5d 3.5.0 2024-11-06 12:52:36 +03:00
Primakov Alexandr Alexandrovich
5c13ca1cac no width limit in attendance 2024-11-06 12:52:29 +03:00
Primakov Alexandr Alexandrovich
56e07bc2ef attendance table 2024-11-06 12:35:55 +03:00
Primakov Alexandr Alexandrovich
923f7034dd 3.4.1
All checks were successful
platform/bro-js/journal.pl/pipeline/head This commit looks good
2024-10-30 14:44:17 +03:00
Primakov Alexandr Alexandrovich
fd422da06f fix update lesson 2024-10-30 14:44:12 +03:00
Primakov Alexandr Alexandrovich
0034704af6 3.4.0 2024-10-30 14:28:55 +03:00
Primakov Alexandr Alexandrovich
3dfd854a4c inline edit mode 2024-10-30 14:28:42 +03:00
15 changed files with 670 additions and 365 deletions

View File

@@ -10,7 +10,8 @@ module.exports = {
navigations: { navigations: {
'journal.main': '/journal.pl', 'journal.main': '/journal.pl',
'exam.main': '/exam', 'exam.main': '/exam',
'link.exam.details': '/details/:courseId/:examId' 'link.exam.details': '/details/:courseId/:examId',
'link.journal.attendance': '/attendance/:courseId',
}, },
features: { features: {
journal: { journal: {

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "journal.pl", "name": "journal.pl",
"version": "3.3.1", "version": "3.5.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "journal.pl", "name": "journal.pl",
"version": "3.3.1", "version": "3.5.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@brojs/cli": "^0.0.4-beta.0", "@brojs/cli": "^0.0.4-beta.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "journal.pl", "name": "journal.pl",
"version": "3.3.1", "version": "3.5.0",
"description": "bro-js platform journal ui repo", "description": "bro-js platform journal ui repo",
"main": "./src/index.tsx", "main": "./src/index.tsx",
"scripts": { "scripts": {

View File

@@ -0,0 +1,26 @@
import { Alert } from '@chakra-ui/react'
import React from 'react'
export class ErrorBoundary extends React.Component<
React.PropsWithChildren,
{ hasError: boolean, error?: string }
> {
state = { hasError: false, error: null }
static getDerivedStateFromError(error: Error) {
return { hasError: true, error: error.message }
}
render() {
if (this.state.hasError) {
return (
<Alert status="error" title="Ошибка">
Что-то пошло не так<br />
{this.state.error && <span>{this.state.error}</span>}
</Alert>
)
}
return this.props.children
}
}

View File

@@ -9,11 +9,14 @@ import {
LessonDetailsPage, LessonDetailsPage,
LessonListPage, LessonListPage,
UserPage, UserPage,
AttendancePage,
} from './pages' } from './pages'
import { ErrorBoundary } from './components/error-boundary'
const Wrapper = ({ children }: { children: React.ReactElement }) => ( const Wrapper = ({ children }: { children: React.ReactElement }) => (
<Suspense <Suspense
fallback={ fallback={
<ErrorBoundary>
<Container> <Container>
<VStack> <VStack>
<Box mt="150"> <Box mt="150">
@@ -23,9 +26,11 @@ const Wrapper = ({ children }: { children: React.ReactElement }) => (
emptyColor="gray.200" emptyColor="gray.200"
color="blue.500" color="blue.500"
size="xl" size="xl"
/></Box> />
</Box>
</VStack> </VStack>
</Container> </Container>
</ErrorBoundary>
} }
> >
{children} {children}
@@ -67,6 +72,14 @@ export const Dashboard = ({ store }) => (
</Wrapper> </Wrapper>
} }
/> />
<Route
path={`${getNavigationsValue('journal.main')}${getNavigationsValue('link.journal.attendance')}`}
element={
<Wrapper>
<AttendancePage />
</Wrapper>
}
/>
</Routes> </Routes>
</Provider> </Provider>
) )

View File

@@ -1,3 +1,4 @@
/* eslint-disable react/display-name */
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';

View File

@@ -0,0 +1,88 @@
import React, { useMemo } from 'react'
import { useParams } from 'react-router-dom'
import styled from '@emotion/styled'
import { api } from '../../__data__/api/api'
import { PageLoader } from '../../components/page-loader/page-loader'
import { Box, Container, Heading } from '@chakra-ui/react'
import dayjs from 'dayjs'
export const Attendance = () => {
const { courseId } = useParams()
const { data: attendance, isLoading } = api.useLessonListQuery(courseId, {
selectFromResult: ({ data, isLoading }) => ({
data: data?.body,
isLoading,
}),
})
const { data: courseInfo, isLoading: courseInfoIssLoading } =
api.useGetCourseByIdQuery(courseId)
const data = useMemo(() => {
if (!attendance) return null
const studentsMap = new Map()
attendance.forEach((lesson) => {
lesson.students.forEach((student) => {
studentsMap.set(student.sub, {
...student,
value:
student.family_name && student.given_name
? `${student.family_name} ${student.given_name}`
: student.name || student.email,
})
})
})
const compare = Intl.Collator('ru').compare
const students = [...studentsMap.values()]
students.sort(({ family_name: name }, { family_name: nname }) =>
compare(name, nname),
)
return {
students,
}
}, [attendance])
if (!data || isLoading || courseInfoIssLoading) {
return <PageLoader />
}
return (
<Box>
<Box mt={12} mb={12}>
<Heading>{courseInfo.name}</Heading>
</Box>
<Box>
<table>
<thead>
<tr>
<th>Дата</th>
<th>Название занятия</th>
{data.students.map((student) => (
<th key={student.sub}>{student.name}</th>
))}
</tr>
</thead>
<tbody>
{attendance.map((lesson, index) => (
<tr key={lesson.name}>
<td>{dayjs(lesson.date).format('DD.MM.YYYY')}</td>
<td>{lesson.name}</td>
{data.students.map((st) => {
const wasThere =
lesson.students.findIndex((u) => u.sub === st.sub) !== -1
return <td style={{
textAlign: 'center',
backgroundColor: wasThere ? '#8ef78a' : '#e09797',
}} key={st.sub}>{wasThere ? '+' : '-'}</td>
})}
</tr>
))}
</tbody>
</table>
</Box>
</Box>
)
}

View File

@@ -0,0 +1,3 @@
import { Attendance } from './attendance'
export default Attendance

View File

@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useState } from 'react' import React, { useCallback, useEffect, useState } from 'react'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { Link as ConnectedLink } from 'react-router-dom' import { Link as ConnectedLink, generatePath } from 'react-router-dom'
import { getNavigationsValue } from '@brojs/cli' import { getNavigationsValue } from '@brojs/cli'
import { import {
Box, Box,
@@ -22,11 +22,7 @@ import { ArrowUpIcon, LinkIcon } from '@chakra-ui/icons'
import { Course } from '../../__data__/model' import { Course } from '../../__data__/model'
import { CourseDetails } from './course-details' import { CourseDetails } from './course-details'
export const CourseCard = ({ export const CourseCard = ({ course }: { course: Course }) => {
course,
}: {
course: Course
}) => {
const [getLessonList, populatedCourse] = api.useLazyGetCourseByIdQuery() const [getLessonList, populatedCourse] = api.useLazyGetCourseByIdQuery()
const [isOpened, setIsOpened] = useState(false) const [isOpened, setIsOpened] = useState(false)
useEffect(() => { useEffect(() => {
@@ -36,7 +32,7 @@ export const CourseCard = ({
}, [isOpened]) }, [isOpened])
const handleToggleOpene = useCallback(() => { const handleToggleOpene = useCallback(() => {
setIsOpened(opened => !opened) setIsOpened((opened) => !opened)
}, [setIsOpened]) }, [setIsOpened])
return ( return (
@@ -57,12 +53,34 @@ export const CourseCard = ({
</Box> </Box>
{populatedCourse.isFetching && <Spinner />} {populatedCourse.isFetching && <Spinner />}
{!populatedCourse.isFetching && populatedCourse.isSuccess && <CourseDetails populatedCourse={populatedCourse.data} />} {!populatedCourse.isFetching && populatedCourse.isSuccess && (
<CourseDetails populatedCourse={populatedCourse.data} />
)}
<Tooltip label="На страницу с лекциями" fontSize="12px" top="16px">
<Button
leftIcon={<LinkIcon />}
as={ConnectedLink}
variant="outline"
colorScheme="blue"
to={generatePath(
`${getNavigationsValue('journal.main')}${getNavigationsValue('link.journal.attendance')}`,
{ courseId: course.id },
)}
>
<Box mt={3}></Box>
Посещаемость
</Button>
</Tooltip>
</Stack> </Stack>
</CardBody> </CardBody>
)} )}
<CardFooter> <CardFooter>
<ButtonGroup spacing={[0, 4]} mt="16px" flexDirection={['column', 'row']}> <ButtonGroup
spacing={[0, 4]}
mt="16px"
flexDirection={['column', 'row']}
>
<Tooltip label="На страницу с лекциями" fontSize="12px" top="16px"> <Tooltip label="На страницу с лекциями" fontSize="12px" top="16px">
<Button <Button
leftIcon={<LinkIcon />} leftIcon={<LinkIcon />}
@@ -76,9 +94,13 @@ export const CourseCard = ({
<Tooltip label="Детали" fontSize="12px" top="16px"> <Tooltip label="Детали" fontSize="12px" top="16px">
<Button <Button
colorScheme="blue" colorScheme="blue"
mt={["16px", 0]} mt={['16px', 0]}
variant="outline" variant="outline"
leftIcon={<ArrowUpIcon transform={isOpened ? 'rotate(0)' : 'rotate(180deg)'} />} leftIcon={
<ArrowUpIcon
transform={isOpened ? 'rotate(0)' : 'rotate(180deg)'}
/>
}
loadingText="Загрузка" loadingText="Загрузка"
isLoading={populatedCourse.isFetching} isLoading={populatedCourse.isFetching}
onClick={handleToggleOpene} onClick={handleToggleOpene}

View File

@@ -2,14 +2,7 @@ import React from 'react'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { Link as ConnectedLink } from 'react-router-dom' import { Link as ConnectedLink } from 'react-router-dom'
import { getNavigationsValue, getHistory } from '@brojs/cli' import { getNavigationsValue, getHistory } from '@brojs/cli'
import { import { Stack, Heading, Link, Button, Tooltip, Box } from '@chakra-ui/react'
Stack,
Heading,
Link,
Button,
Tooltip,
Box,
} from '@chakra-ui/react'
import { useAppSelector } from '../../__data__/store' import { useAppSelector } from '../../__data__/store'
import { isTeacher } from '../../utils/user' import { isTeacher } from '../../utils/user'
@@ -18,7 +11,7 @@ import { api } from '../../__data__/api/api'
import { LinkIcon } from '@chakra-ui/icons' import { LinkIcon } from '@chakra-ui/icons'
type CourseDetailsProps = { type CourseDetailsProps = {
populatedCourse: PopulatedCourse; populatedCourse: PopulatedCourse
} }
const history = getHistory() const history = getHistory()
@@ -26,26 +19,42 @@ const history = getHistory()
export const CourseDetails = ({ populatedCourse }: CourseDetailsProps) => { export const CourseDetails = ({ populatedCourse }: CourseDetailsProps) => {
const user = useAppSelector((s) => s.user) const user = useAppSelector((s) => s.user)
const exam = populatedCourse.examWithJury const exam = populatedCourse.examWithJury
const [toggleExamWithJury, examWithJuryRequest] = api.useToggleExamWithJuryMutation() const [toggleExamWithJury, examWithJuryRequest] =
api.useToggleExamWithJuryMutation()
return ( return (
<> <>
{isTeacher(user) && (
<Heading as="h3" mt={4} mb={3} size="lg"> <Heading as="h3" mt={4} mb={3} size="lg">
Экзамен: {exam?.name} {exam && <Tooltip label="Начать экзамен" fontSize="12px" top="16px"> Экзамен: {exam?.name}{' '}
{exam && (
<Tooltip label="Начать экзамен" fontSize="12px" top="16px">
<Button <Button
leftIcon={<LinkIcon />} leftIcon={<LinkIcon />}
as={'a'} as={'a'}
colorScheme="blue" colorScheme="blue"
href={getNavigationsValue('exam.main') + getNavigationsValue('link.exam.details').replace(':courseId', populatedCourse.id).replace(':examId', exam.id)} href={
onClick={event => { getNavigationsValue('exam.main') +
event.preventDefault(); getNavigationsValue('link.exam.details')
history.push(getNavigationsValue('exam.main') + getNavigationsValue('link.exam.details').replace(':courseId', populatedCourse.id).replace(':examId', exam.id)) .replace(':courseId', populatedCourse.id)
.replace(':examId', exam.id)
}
onClick={(event) => {
event.preventDefault()
history.push(
getNavigationsValue('exam.main') +
getNavigationsValue('link.exam.details')
.replace(':courseId', populatedCourse.id)
.replace(':examId', exam.id),
)
}} }}
> >
Открыть Открыть
</Button> </Button>
</Tooltip>} </Tooltip>
)}
</Heading> </Heading>
)}
{!Boolean(exam) && ( {!Boolean(exam) && (
<> <>
<Heading as="h3" mt={4} mb={3} size="lg"> <Heading as="h3" mt={4} mb={3} size="lg">
@@ -55,7 +64,7 @@ export const CourseDetails = ({ populatedCourse }: CourseDetailsProps) => {
<Tooltip label="Создать экзамен с жюри" fontSize="12px" top="16px"> <Tooltip label="Создать экзамен с жюри" fontSize="12px" top="16px">
<Button <Button
colorScheme="blue" colorScheme="blue"
mt={["16px", 0]} mt={['16px', 0]}
variant="outline" variant="outline"
isLoading={examWithJuryRequest.isLoading} isLoading={examWithJuryRequest.isLoading}
onClick={() => toggleExamWithJury(populatedCourse.id)} onClick={() => toggleExamWithJury(populatedCourse.id)}
@@ -73,8 +82,8 @@ export const CourseDetails = ({ populatedCourse }: CourseDetailsProps) => {
</Heading> </Heading>
<Heading as="h3" mt={4} mb={3} size="lg"> <Heading as="h3" mt={4} mb={3} size="lg">
{populatedCourse.examWithJury.jury.length} {populatedCourse.examWithJury.jury.length}
</Heading></> </Heading>
</>
)} )}
<Heading as="h3" mt={4} mb={3} size="lg"> <Heading as="h3" mt={4} mb={3} size="lg">
Список занятий: Список занятий:

View File

@@ -4,3 +4,4 @@ export const CourseListPage = lazy(() => import(/* webpackChunkName: "course-lis
export const LessonDetailsPage = lazy(() => import(/* webpackChunkName: "lesson-details" */ './lesson-details')); export const LessonDetailsPage = lazy(() => import(/* webpackChunkName: "lesson-details" */ './lesson-details'));
export const LessonListPage = lazy(() => import(/* webpackChunkName: "lesson-list" */ './lesson-list')); export const LessonListPage = lazy(() => import(/* webpackChunkName: "lesson-list" */ './lesson-list'));
export const UserPage = lazy(() => import(/* webpackChunkName: "user-page" */ './user-page')); export const UserPage = lazy(() => import(/* webpackChunkName: "user-page" */ './user-page'));
export const AttendancePage = lazy(() => import(/* webpackChunkName: "attendance-page" */ './attendance'));

View File

@@ -0,0 +1,144 @@
import React, { useEffect, useRef, useState } from 'react'
import dayjs from 'dayjs'
import { Link } from 'react-router-dom'
import { getNavigationsValue, getFeatures } from '@brojs/cli'
import {
Button,
Tr,
Td,
Menu,
MenuButton,
MenuItem,
MenuList,
useToast,
} from '@chakra-ui/react'
import { EditIcon } from '@chakra-ui/icons'
import { qrCode } from '../../../assets'
import { LessonForm } from './lessons-form'
import { api } from '../../../__data__/api/api'
const features = getFeatures('journal')
const groupByDate = features?.['group.by.date']
type ItemProps = {
id: string
date: string
name: string
isTeacher: boolean
courseId: string
setlessonToDelete(): void
students: unknown[]
}
export const Item: React.FC<ItemProps> = ({
id,
date,
name,
isTeacher,
courseId,
setlessonToDelete,
students,
}) => {
const [edit, setEdit] = useState(false)
const toastRef = useRef(null)
const toast = useToast()
const [updateLesson, updateLessonRqst] = api.useUpdateLessonMutation()
const createdLessonRef = useRef(null)
const onSubmit = (lessonData) => {
toastRef.current = toast({
title: 'Отправляем',
status: 'loading',
duration: 9000,
})
createdLessonRef.current = lessonData
if (navigator.onLine) {
updateLesson(lessonData)
} else {
toast.update(toastRef.current, {
title: 'Отсутствует интернет',
status: 'error',
duration: 3000
})
}
}
useEffect(() => {
if (updateLessonRqst.isSuccess) {
const toastProps = {
title: 'Лекция Обновлена',
description: `Лекция ${createdLessonRef.current?.name} успешно обновлена`,
status: 'success' as const,
duration: 9000,
isClosable: true,
}
if (toastRef.current) toast.update(toastRef.current, toastProps)
else toast(toastProps)
setEdit(false)
}
}, [updateLessonRqst.isSuccess])
if (edit && isTeacher) {
return (
<Tr>
<Td colSpan={5}>
<LessonForm
isLoading={updateLessonRqst.isLoading}
error={(updateLessonRqst.error as any)?.error}
onSubmit={onSubmit}
onCancel={() => {
setEdit(false)
}}
lesson={{ _id: id, id, name, date }}
title={'Редактирование лекции'}
nameButton={'Сохранить'}
/>
</Td>
</Tr>
)
}
return (
<Tr>
{isTeacher && (
<Td>
<Link
to={`${getNavigationsValue('journal.main')}/lesson/${courseId}/${id}`}
style={{ display: 'flex' }}
>
<img width={24} src={qrCode} style={{ margin: '0 auto' }} />
</Link>
</Td>
)}
<Td textAlign="center">
{dayjs(date).format(groupByDate ? 'HH:mm' : 'HH:mm DD.MM.YY')}
</Td>
<Td>{name}</Td>
{isTeacher && (
<Td>
{!edit && (
<Menu>
<MenuButton as={Button}>
<EditIcon />
</MenuButton>
<MenuList>
<MenuItem
onClick={() => {
setEdit(true)
}}
>
Edit
</MenuItem>
<MenuItem onClick={setlessonToDelete}>Delete</MenuItem>
</MenuList>
</Menu>
)}
{edit && <Button onClick={setlessonToDelete}>Сохранить</Button>}
</Td>
)}
<Td isNumeric>{students.length}</Td>
</Tr>
)
}

View File

@@ -0,0 +1,45 @@
import React from 'react'
import dayjs from 'dayjs'
import {
Tr,
Td,
} from '@chakra-ui/react'
import { Lesson } from '../../../__data__/model'
import { Item } from './item'
type LessonItemProps = {
date: string
lessons: Lesson[]
isTeacher: boolean
courseId: string
setlessonToDelete(lesson: Lesson): void
}
export const LessonItems: React.FC<LessonItemProps> = ({
date,
lessons,
isTeacher,
courseId,
setlessonToDelete,
}) => (
<>
{date && (
<Tr>
<Td colSpan={isTeacher ? 5 : 3}>
{dayjs(date).format('DD MMMM YYYY')}
</Td>
</Tr>
)}
{lessons.map((lesson) => (
<Item
key={lesson.id}
{...lesson}
setlessonToDelete={() => setlessonToDelete(lesson)}
courseId={courseId}
isTeacher={isTeacher}
/>
))}
</>
)

View File

@@ -22,8 +22,8 @@ import { Lesson } from '../../../__data__/model'
import { ErrorSpan } from '../style' import { ErrorSpan } from '../style'
interface NewLessonForm { interface NewLessonForm {
name: string; name: string
date: string; date: string
} }
interface LessonFormProps { interface LessonFormProps {
@@ -51,7 +51,10 @@ export const LessonForm = ({
reset, reset,
formState: { errors }, formState: { errors },
} = useForm<NewLessonForm>({ } = useForm<NewLessonForm>({
defaultValues: (lesson && { ...lesson, date: dateToCalendarFormat(lesson.date) }) || { defaultValues: (lesson && {
...lesson,
date: dateToCalendarFormat(lesson.date),
}) || {
name: '', name: '',
date: dateToCalendarFormat(), date: dateToCalendarFormat(),
}, },

View File

@@ -1,11 +1,6 @@
import React, { import React, { useEffect, useMemo, useRef, useState } from 'react'
useEffect,
useMemo,
useRef,
useState,
} from 'react'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { Link, useParams } from 'react-router-dom' import { generatePath, Link, useParams } from 'react-router-dom'
import { getNavigationsValue, getFeatures } from '@brojs/cli' import { getNavigationsValue, getFeatures } from '@brojs/cli'
import { import {
Breadcrumb, Breadcrumb,
@@ -22,12 +17,7 @@ import {
Tr, Tr,
Th, Th,
Tbody, Tbody,
Td,
Menu,
MenuButton,
MenuItem,
Text, Text,
MenuList,
AlertDialog, AlertDialog,
AlertDialogBody, AlertDialogBody,
AlertDialogContent, AlertDialogContent,
@@ -35,18 +25,18 @@ import {
AlertDialogHeader, AlertDialogHeader,
AlertDialogOverlay, AlertDialogOverlay,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import { AddIcon, EditIcon } from '@chakra-ui/icons' import { AddIcon } from '@chakra-ui/icons'
import { useAppSelector } from '../../__data__/store' import { useAppSelector } from '../../__data__/store'
import { api } from '../../__data__/api/api' import { api } from '../../__data__/api/api'
import { isTeacher } from '../../utils/user' import { isTeacher } from '../../utils/user'
import { qrCode } from '../../assets'
import { Lesson } from '../../__data__/model' import { Lesson } from '../../__data__/model'
import { XlSpinner } from '../../components/xl-spinner' import { XlSpinner } from '../../components/xl-spinner'
import { LessonForm } from './components/lessons-form' import { LessonForm } from './components/lessons-form'
import { BreadcrumbsWrapper } from './style'
import { Bar } from './components/bar' import { Bar } from './components/bar'
import { LessonItems } from './components/lesson-items'
import { BreadcrumbsWrapper } from './style'
const features = getFeatures('journal') const features = getFeatures('journal')
@@ -67,7 +57,10 @@ const LessonList = () => {
const toastRef = useRef(null) const toastRef = useRef(null)
const createdLessonRef = useRef(null) const createdLessonRef = useRef(null)
const [editLesson, setEditLesson] = useState<Lesson>(null) const [editLesson, setEditLesson] = useState<Lesson>(null)
const sorted = useMemo(() => [...(data?.body || [])]?.sort((a, b) => a.date > b.date ? 1 : -1), [data, data?.body]) const sorted = useMemo(
() => [...(data?.body || [])]?.sort((a, b) => (a.date > b.date ? 1 : -1)),
[data, data?.body],
)
const lessonCalc = useMemo(() => { const lessonCalc = useMemo(() => {
if (!isSuccess) { if (!isSuccess) {
@@ -95,7 +88,7 @@ const LessonList = () => {
} }
} }
return lessonsData.sort((a, b) => a.date < b.date? 1 : -1) return lessonsData.sort((a, b) => (a.date < b.date ? 1 : -1))
}, [groupByDate, isSuccess, sorted]) }, [groupByDate, isSuccess, sorted])
const onSubmit = (lessonData) => { const onSubmit = (lessonData) => {
@@ -153,8 +146,8 @@ const LessonList = () => {
if (crLQuery.isSuccess) { if (crLQuery.isSuccess) {
const toastProps = { const toastProps = {
title: 'Лекция создана', title: 'Лекция создана',
description: `Лекция ${createdLessonRef.current.name} успешно создана`, description: `Лекция ${createdLessonRef.current?.name} успешно создана`,
status: 'success' as 'success', status: 'success' as const,
duration: 9000, duration: 9000,
isClosable: true, isClosable: true,
} }
@@ -168,8 +161,8 @@ const LessonList = () => {
if (updateLessonRqst.isSuccess) { if (updateLessonRqst.isSuccess) {
const toastProps = { const toastProps = {
title: 'Лекция Обновлена', title: 'Лекция Обновлена',
description: `Лекция ${createdLessonRef.current.name} успешно обновлена`, description: `Лекция ${createdLessonRef.current?.name} успешно обновлена`,
status: 'success' as 'success', status: 'success' as const,
duration: 9000, duration: 9000,
isClosable: true, isClosable: true,
} }
@@ -180,7 +173,7 @@ const LessonList = () => {
}, [updateLessonRqst.isSuccess]) }, [updateLessonRqst.isSuccess])
if (isLoading) { if (isLoading) {
return <XlSpinner />; return <XlSpinner />
} }
return ( return (
@@ -213,7 +206,7 @@ const LessonList = () => {
colorScheme="red" colorScheme="red"
loadingText="" loadingText=""
isLoading={deletingRqst.isLoading} isLoading={deletingRqst.isLoading}
onClick={() => deleteLesson(lessonToDelete._id)} onClick={() => deleteLesson(lessonToDelete.id)}
ml={3} ml={3}
> >
Delete Delete
@@ -240,7 +233,7 @@ const LessonList = () => {
<Box mt="15" mb="15"> <Box mt="15" mb="15">
{showForm ? ( {showForm ? (
<LessonForm <LessonForm
key={editLesson?._id} key={editLesson?.id}
isLoading={crLQuery.isLoading} isLoading={crLQuery.isLoading}
onSubmit={onSubmit} onSubmit={onSubmit}
onCancel={() => { onCancel={() => {
@@ -253,7 +246,6 @@ const LessonList = () => {
nameButton={editLesson ? 'Редактировать' : 'Создать'} nameButton={editLesson ? 'Редактировать' : 'Создать'}
/> />
) : ( ) : (
<Box p="2" m="2">
<Button <Button
leftIcon={<AddIcon />} leftIcon={<AddIcon />}
colorScheme="green" colorScheme="green"
@@ -261,11 +253,10 @@ const LessonList = () => {
> >
Добавить Добавить
</Button> </Button>
</Box>
)} )}
</Box> </Box>
)} )}
{barFeature && sorted?.length && ( {barFeature && sorted?.length > 1 && (
<Box height="300"> <Box height="300">
<Bar <Bar
data={sorted.map((lesson, index) => ({ data={sorted.map((lesson, index) => ({
@@ -285,7 +276,7 @@ const LessonList = () => {
</Th> </Th>
)} )}
<Th textAlign="center" width={1}> <Th textAlign="center" width={1}>
Дата {groupByDate ? 'Время' : 'Дата'}
</Th> </Th>
<Th width="100%">Название</Th> <Th width="100%">Название</Th>
{isTeacher(user) && <Th>action</Th>} {isTeacher(user) && <Th>action</Th>}
@@ -294,56 +285,14 @@ const LessonList = () => {
</Thead> </Thead>
<Tbody> <Tbody>
{lessonCalc?.map(({ data: lessons, date }) => ( {lessonCalc?.map(({ data: lessons, date }) => (
<React.Fragment key={date}> <LessonItems
{date && <Tr><Td colSpan={isTeacher(user) ? 5 : 3}>{dayjs(date).format('DD MMMM YYYY')}</Td></Tr>} courseId={courseId}
{lessons.map((lesson) => ( date={date}
<Tr key={lesson._id}> isTeacher={isTeacher(user)}
{isTeacher(user) && ( lessons={lessons}
<Td> setlessonToDelete={setlessonToDelete}
<Link key={date}
to={`${getNavigationsValue('journal.main')}/lesson/${courseId}/${lesson._id}`}
style={{ display: 'flex' }}
>
<img
width={24}
src={qrCode}
style={{ margin: '0 auto' }}
/> />
</Link>
</Td>
)}
<Td textAlign="center">
{dayjs(lesson.date).format(groupByDate ? 'HH:mm' : 'HH:mm DD.MM.YY')}
</Td>
<Td>{lesson.name}</Td>
{isTeacher(user) && (
<Td>
<Menu>
<MenuButton as={Button}>
<EditIcon />
</MenuButton>
<MenuList>
<MenuItem
onClick={() => {
setShowForm(true)
setEditLesson(lesson)
}}
>
Edit
</MenuItem>
<MenuItem
onClick={() => setlessonToDelete(lesson)}
>
Delete
</MenuItem>
</MenuList>
</Menu>
</Td>
)}
<Td isNumeric>{lesson.students.length}</Td>
</Tr>
))}
</React.Fragment>
))} ))}
</Tbody> </Tbody>
</Table> </Table>