Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a133cea95c | ||
|
|
4704b404f9 | ||
|
|
55d23f1e47 | ||
|
|
6b07fef62f | ||
|
|
3242576a12 | ||
|
|
a7168231a1 | ||
|
|
cc7f3d3371 | ||
|
|
d20cb7257b | ||
|
|
ab9e5f6d19 | ||
|
|
71d2f59750 | ||
|
|
bdd53ca15b | ||
|
|
789d2ed6ca | ||
|
|
d4b7d0616e | ||
|
|
b5bd2e02d7 | ||
|
|
428b06f920 | ||
|
|
7d6f2a4ca0 | ||
|
|
2fe7600ef3 | ||
|
|
985b8ef315 | ||
|
|
956fdec7f5 | ||
|
|
d44a511a3d | ||
|
|
0aebb87210 | ||
|
|
9509f12d73 | ||
|
|
021031ced7 | ||
|
|
22a9199d9d | ||
|
|
e56f0e4e5d | ||
|
|
5c13ca1cac | ||
|
|
56e07bc2ef | ||
|
|
923f7034dd | ||
|
|
fd422da06f | ||
|
|
0034704af6 | ||
|
|
3dfd854a4c |
24
@types/index.d.ts
vendored
Normal file
24
@types/index.d.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
declare const IS_PROD: string
|
||||||
|
declare const KC_URL: string
|
||||||
|
declare const KC_REALM: string
|
||||||
|
declare const KC_CLIENT_ID: string
|
||||||
|
|
||||||
|
declare module '*.svg' {
|
||||||
|
const value: string
|
||||||
|
|
||||||
|
export default value
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module '*.jpg' {
|
||||||
|
const value: string
|
||||||
|
|
||||||
|
export default value
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module '*.png' {
|
||||||
|
const value: string
|
||||||
|
|
||||||
|
export default value
|
||||||
|
}
|
||||||
|
|
||||||
|
declare const __webpack_public_path__: string
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
const webpack = require('webpack');
|
||||||
|
|
||||||
const pkg = require('./package')
|
const pkg = require('./package')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -6,11 +8,19 @@ module.exports = {
|
|||||||
output: {
|
output: {
|
||||||
publicPath: `/static/${pkg.name}/${process.env.VERSION || pkg.version}/`,
|
publicPath: `/static/${pkg.name}/${process.env.VERSION || pkg.version}/`,
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
KC_URL: process.env.KC_URL || '"https://kc.bro-js.ru"',
|
||||||
|
KC_REALM: process.env.KC_REALM || '"bro-js"',
|
||||||
|
KC_CLIENT_ID: process.env.KC_CLIENT_ID || '"microfrontend-admin"',
|
||||||
|
}),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
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: {
|
||||||
6
index.d.ts
vendored
6
index.d.ts
vendored
@@ -1,6 +0,0 @@
|
|||||||
declare module '*.svg' {
|
|
||||||
const src: string;
|
|
||||||
export default src;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare const __webpack_public_path__: string;
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import type { ConfigFile } from '@rtk-query/codegen-openapi'
|
|
||||||
|
|
||||||
const config: ConfigFile = {
|
|
||||||
schemaFile: 'https://platform.bro-js.ru/jrnl-bh/documentation/json',
|
|
||||||
apiFile: './src/__data__/api/api.ts',
|
|
||||||
apiImport: 'api',
|
|
||||||
outputFile: './src/__data__/api/jrnl.ts',
|
|
||||||
exportName: 'jrnlApi',
|
|
||||||
hooks: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
export default config
|
|
||||||
5650
package-lock.json
generated
5650
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "journal.pl",
|
"name": "journal.pl",
|
||||||
"version": "3.3.1",
|
"version": "3.6.6",
|
||||||
"description": "bro-js platform journal ui repo",
|
"description": "bro-js platform journal ui repo",
|
||||||
"main": "./src/index.tsx",
|
"main": "./src/index.tsx",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -19,14 +19,13 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rtk-query/codegen-openapi": "^1.2.0",
|
|
||||||
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
||||||
"@typescript-eslint/parser": "^7.4.0",
|
"@typescript-eslint/parser": "^7.4.0",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-react": "^7.34.1"
|
"eslint-plugin-react": "^7.34.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@brojs/cli": "^0.0.4-beta.0",
|
"@brojs/cli": "^1.8.4",
|
||||||
"@chakra-ui/icons": "^2.1.1",
|
"@chakra-ui/icons": "^2.1.1",
|
||||||
"@chakra-ui/react": "^2.8.2",
|
"@chakra-ui/react": "^2.8.2",
|
||||||
"@emotion/react": "^11.11.4",
|
"@emotion/react": "^11.11.4",
|
||||||
@@ -38,7 +37,7 @@
|
|||||||
"dayjs": "^1.11.10",
|
"dayjs": "^1.11.10",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"js-sha256": "^0.11.0",
|
"js-sha256": "^0.11.0",
|
||||||
"keycloak-js": "^23.0.7",
|
"keycloak-js": "^26.0.7",
|
||||||
"prettier": "^3.2.5",
|
"prettier": "^3.2.5",
|
||||||
"qrcode": "^1.5.3",
|
"qrcode": "^1.5.3",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import Keycloak from 'keycloak-js';
|
import Keycloak from 'keycloak-js'
|
||||||
|
|
||||||
export const keycloak = new Keycloak({
|
export const keycloak = new Keycloak({
|
||||||
url: 'https://kc.bro-js.ru',
|
url: KC_URL,
|
||||||
realm: 'bro-js',
|
realm: KC_REALM,
|
||||||
clientId: 'journal'
|
clientId: KC_CLIENT_ID,
|
||||||
});
|
});
|
||||||
|
|
||||||
window.keycloak = keycloak;
|
(window as any).kc = keycloak
|
||||||
@@ -53,10 +53,17 @@ export interface Lesson {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
students: User[];
|
students: User[];
|
||||||
|
teachers: Teacher[];
|
||||||
date: string;
|
date: string;
|
||||||
created: string;
|
created: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Teacher {
|
||||||
|
sub: string;
|
||||||
|
email_verified: boolean;
|
||||||
|
preferred_username: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AccessCode {
|
export interface AccessCode {
|
||||||
expires: string;
|
expires: string;
|
||||||
lesson: Lesson;
|
lesson: Lesson;
|
||||||
|
|||||||
26
src/components/error-boundary/index.tsx
Normal file
26
src/components/error-boundary/index.tsx
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,23 +9,28 @@ 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={
|
||||||
<Container>
|
<ErrorBoundary>
|
||||||
<VStack>
|
<Container>
|
||||||
<Box mt="150">
|
<VStack>
|
||||||
<Spinner
|
<Box mt="150">
|
||||||
thickness="4px"
|
<Spinner
|
||||||
speed="0.65s"
|
thickness="4px"
|
||||||
emptyColor="gray.200"
|
speed="0.65s"
|
||||||
color="blue.500"
|
emptyColor="gray.200"
|
||||||
size="xl"
|
color="blue.500"
|
||||||
/></Box>
|
size="xl"
|
||||||
</VStack>
|
/>
|
||||||
</Container>
|
</Box>
|
||||||
|
</VStack>
|
||||||
|
</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>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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';
|
||||||
|
|
||||||
@@ -13,23 +14,30 @@ export default (props) => <App {...props} />;
|
|||||||
|
|
||||||
let rootElement: ReactDOM.Root
|
let rootElement: ReactDOM.Root
|
||||||
|
|
||||||
export const mount = async (Сomponent, element = document.getElementById('app')) => {
|
export const mount = async (Component, element = document.getElementById('app')) => {
|
||||||
let user = null;
|
let user = null;
|
||||||
try {
|
try {
|
||||||
await keycloak.init({ onLoad: "login-required" });
|
await keycloak.init({ onLoad: 'check-sso' }) // 'login-required' });
|
||||||
user = { ...(await keycloak.loadUserInfo()), ...keycloak.tokenParsed };
|
|
||||||
|
const userInfo = await keycloak.loadUserInfo()
|
||||||
|
|
||||||
|
if (userInfo && keycloak.tokenParsed) {
|
||||||
|
user = { ...userInfo, ...keycloak.tokenParsed }
|
||||||
|
} else {
|
||||||
|
console.error('No userInfo or tokenParsed', userInfo, keycloak.tokenParsed)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to initialize adapter:", error);
|
console.error('Failed to initialize adapter:', error)
|
||||||
keycloak.login();
|
// keycloak.login()
|
||||||
}
|
}
|
||||||
const store = createStore({ user });
|
const store = createStore({ user });
|
||||||
|
|
||||||
rootElement = ReactDOM.createRoot(element);
|
rootElement = ReactDOM.createRoot(element);
|
||||||
rootElement.render(<Сomponent store={store} />);
|
rootElement.render(<Component store={store} />);
|
||||||
|
|
||||||
if(module.hot) {
|
if(module.hot) {
|
||||||
module.hot.accept('./app', ()=> {
|
module.hot.accept('./app', ()=> {
|
||||||
rootElement.render(<Сomponent store={store} />);
|
rootElement.render(<Component store={store} />);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
140
src/pages/attendance/attendance.tsx
Normal file
140
src/pages/attendance/attendance.tsx
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
import React, { useMemo } from 'react'
|
||||||
|
import { useParams } from 'react-router-dom'
|
||||||
|
import { Box, Heading, Tooltip, Text } from '@chakra-ui/react'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
|
import { api } from '../../__data__/api/api'
|
||||||
|
import { PageLoader } from '../../components/page-loader/page-loader'
|
||||||
|
|
||||||
|
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()
|
||||||
|
const teachersMap = new Map()
|
||||||
|
|
||||||
|
attendance.forEach((lesson) => {
|
||||||
|
lesson.teachers?.map((teacher: any) => {
|
||||||
|
teachersMap.set(teacher.sub, { id: teacher.sub, ...teacher, value: teacher.value || (teacher.family_name && teacher.given_name
|
||||||
|
? `${teacher.family_name} ${teacher.given_name}`
|
||||||
|
: teacher.name || teacher.email || teacher.preferred_username || teacher.family_name || teacher.given_name), })
|
||||||
|
})
|
||||||
|
|
||||||
|
lesson.students.forEach((student) => {
|
||||||
|
const current = studentsMap.get(student.sub) || {}
|
||||||
|
|
||||||
|
studentsMap.set(student.sub, {
|
||||||
|
...student,
|
||||||
|
id: student.sub,
|
||||||
|
value: current.value || (student.family_name && student.given_name
|
||||||
|
? `${student.family_name} ${student.given_name}`
|
||||||
|
: student.name || student.email || student.preferred_username || student.family_name || student.given_name),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const compare = Intl.Collator('ru').compare
|
||||||
|
|
||||||
|
const students = [...studentsMap.values()]
|
||||||
|
const taechers = [...teachersMap.values()]
|
||||||
|
students.sort(({ family_name: name }, { family_name: nname }) =>
|
||||||
|
compare(name, nname),
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
students,
|
||||||
|
taechers,
|
||||||
|
}
|
||||||
|
}, [attendance])
|
||||||
|
|
||||||
|
if (!data || isLoading || courseInfoIssLoading) {
|
||||||
|
return <PageLoader />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box mt={12} mb={12}>
|
||||||
|
<Heading>{courseInfo.name}</Heading>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
{data.taechers.map(teacher => (
|
||||||
|
<th id={teacher.id} key={teacher.id}>{teacher.value}</th>
|
||||||
|
))}
|
||||||
|
<th>Дата</th>
|
||||||
|
<th>Название занятия</th>
|
||||||
|
{data.students.map((student) => (
|
||||||
|
<th id={student.id || student.sub} key={student.sub}>{student.name || student.value || 'Имя не определено'}</th>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{attendance.map((lesson, index) => (
|
||||||
|
<tr key={lesson.name}>
|
||||||
|
{data?.taechers?.map((teacher) => {
|
||||||
|
|
||||||
|
const wasThere = Boolean(lesson.teachers) &&
|
||||||
|
lesson?.teachers?.findIndex((u) => u.sub === teacher.sub) !== -1
|
||||||
|
return (
|
||||||
|
<td
|
||||||
|
style={{
|
||||||
|
textAlign: 'center',
|
||||||
|
backgroundColor: wasThere ? '#8ef78a' : '#e09797',
|
||||||
|
}}
|
||||||
|
key={teacher.sub}
|
||||||
|
>
|
||||||
|
{wasThere ? '+' : '-'}
|
||||||
|
</td>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
<td>{dayjs(lesson.date).format('DD.MM.YYYY')}</td>
|
||||||
|
<td>{<ShortText text={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>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ShortText = ({ text }: { text: string }) => {
|
||||||
|
const needShortText = text.length > 20
|
||||||
|
|
||||||
|
if (needShortText) {
|
||||||
|
return (
|
||||||
|
<Tooltip label="На страницу с лекциями" fontSize="12px" top="16px">
|
||||||
|
<Text>{text.slice(0, 20)}...</Text>
|
||||||
|
</Tooltip>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return text
|
||||||
|
}
|
||||||
3
src/pages/attendance/index.ts
Normal file
3
src/pages/attendance/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { Attendance } from './attendance'
|
||||||
|
|
||||||
|
export default Attendance
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
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,
|
||||||
CardHeader,
|
CardHeader,
|
||||||
CardBody,
|
CardBody,
|
||||||
CardFooter,
|
CardFooter,
|
||||||
ButtonGroup,
|
ButtonGroup,
|
||||||
Stack,
|
Stack,
|
||||||
StackDivider,
|
StackDivider,
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
Heading,
|
Heading,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Spinner,
|
Spinner,
|
||||||
} from '@chakra-ui/react'
|
} from '@chakra-ui/react'
|
||||||
|
|
||||||
import { api } from '../../__data__/api/api'
|
import { api } from '../../__data__/api/api'
|
||||||
@@ -22,72 +22,100 @@ 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,
|
const [getLessonList, populatedCourse] = api.useLazyGetCourseByIdQuery()
|
||||||
}: {
|
const [isOpened, setIsOpened] = useState(false)
|
||||||
course: Course
|
useEffect(() => {
|
||||||
}) => {
|
if (isOpened) {
|
||||||
const [getLessonList, populatedCourse] = api.useLazyGetCourseByIdQuery()
|
getLessonList(course.id, true)
|
||||||
const [isOpened, setIsOpened] = useState(false)
|
}
|
||||||
useEffect(() => {
|
}, [isOpened])
|
||||||
if (isOpened) {
|
|
||||||
getLessonList(course.id, true)
|
|
||||||
}
|
|
||||||
}, [isOpened])
|
|
||||||
|
|
||||||
const handleToggleOpene = useCallback(() => {
|
const handleToggleOpene = useCallback(() => {
|
||||||
setIsOpened(opened => !opened)
|
setIsOpened((opened) => !opened)
|
||||||
}, [setIsOpened])
|
}, [setIsOpened])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card key={course._id} align="left">
|
<Card key={course._id} align="left">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<Heading as="h2" mt="0">
|
<Heading as="h2" mt="0">
|
||||||
{course.name}
|
{course.name}
|
||||||
</Heading>
|
</Heading>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
{isOpened && (
|
{isOpened && (
|
||||||
<CardBody mt="16px">
|
<CardBody mt="16px">
|
||||||
<Stack divider={<StackDivider />} spacing="8px">
|
<Stack divider={<StackDivider />} spacing="8px">
|
||||||
<Box as="span" textAlign="left">
|
<Box as="span" textAlign="left">
|
||||||
{`Дата начала курса - ${dayjs(course.startDt).format('DD MMMM YYYYг.')}`}
|
{`Дата начала курса - ${dayjs(course.startDt).format('DD MMMM YYYYг.')}`}
|
||||||
</Box>
|
</Box>
|
||||||
<Box as="span" textAlign="left">
|
<Box as="span" textAlign="left">
|
||||||
Количество занятий - {course.lessons.length}
|
Количество занятий - {course.lessons.length}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{populatedCourse.isFetching && <Spinner />}
|
{populatedCourse.isFetching && <Spinner />}
|
||||||
{!populatedCourse.isFetching && populatedCourse.isSuccess && <CourseDetails populatedCourse={populatedCourse.data} />}
|
{!populatedCourse.isFetching && populatedCourse.isSuccess && (
|
||||||
</Stack>
|
<CourseDetails populatedCourse={populatedCourse.data} />
|
||||||
</CardBody>
|
|
||||||
)}
|
)}
|
||||||
<CardFooter>
|
|
||||||
<ButtonGroup spacing={[0, 4]} mt="16px" flexDirection={['column', 'row']}>
|
{getNavigationsValue('link.journal.attendance') && (
|
||||||
<Tooltip label="На страницу с лекциями" fontSize="12px" top="16px">
|
<Tooltip
|
||||||
<Button
|
label="На страницу с лекциями"
|
||||||
leftIcon={<LinkIcon />}
|
fontSize="12px"
|
||||||
as={ConnectedLink}
|
top="16px"
|
||||||
colorScheme="blue"
|
>
|
||||||
to={`${getNavigationsValue('journal.main')}/lessons-list/${course._id}`}
|
<Button
|
||||||
>
|
leftIcon={<LinkIcon />}
|
||||||
Открыть
|
as={ConnectedLink}
|
||||||
</Button>
|
variant="outline"
|
||||||
</Tooltip>
|
colorScheme="blue"
|
||||||
<Tooltip label="Детали" fontSize="12px" top="16px">
|
to={generatePath(
|
||||||
<Button
|
`${getNavigationsValue('journal.main')}${getNavigationsValue('link.journal.attendance')}`,
|
||||||
colorScheme="blue"
|
{ courseId: course.id },
|
||||||
mt={["16px", 0]}
|
)}
|
||||||
variant="outline"
|
>
|
||||||
leftIcon={<ArrowUpIcon transform={isOpened ? 'rotate(0)' : 'rotate(180deg)'} />}
|
<Box mt={3}></Box>
|
||||||
loadingText="Загрузка"
|
Посещаемость
|
||||||
isLoading={populatedCourse.isFetching}
|
</Button>
|
||||||
onClick={handleToggleOpene}
|
</Tooltip>
|
||||||
>
|
)}
|
||||||
{isOpened ? 'Закрыть' : 'Просмотреть детали'}
|
</Stack>
|
||||||
</Button>
|
</CardBody>
|
||||||
</Tooltip>
|
)}
|
||||||
</ButtonGroup>
|
<CardFooter>
|
||||||
</CardFooter>
|
<ButtonGroup
|
||||||
</Card>
|
spacing={[0, 4]}
|
||||||
)
|
mt="16px"
|
||||||
|
flexDirection={['column', 'row']}
|
||||||
|
>
|
||||||
|
<Tooltip label="На страницу с лекциями" fontSize="12px" top="16px">
|
||||||
|
<Button
|
||||||
|
leftIcon={<LinkIcon />}
|
||||||
|
as={ConnectedLink}
|
||||||
|
colorScheme="blue"
|
||||||
|
to={`${getNavigationsValue('journal.main')}/lessons-list/${course._id}`}
|
||||||
|
>
|
||||||
|
Открыть
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip label="Детали" fontSize="12px" top="16px">
|
||||||
|
<Button
|
||||||
|
colorScheme="blue"
|
||||||
|
mt={['16px', 0]}
|
||||||
|
variant="outline"
|
||||||
|
leftIcon={
|
||||||
|
<ArrowUpIcon
|
||||||
|
transform={isOpened ? 'rotate(0)' : 'rotate(180deg)'}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
loadingText="Загрузка"
|
||||||
|
isLoading={populatedCourse.isFetching}
|
||||||
|
onClick={handleToggleOpene}
|
||||||
|
>
|
||||||
|
{isOpened ? 'Закрыть' : 'Просмотреть детали'}
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</ButtonGroup>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,82 +11,98 @@ 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()
|
||||||
|
|
||||||
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">
|
||||||
|
Экзамен: {exam?.name}{' '}
|
||||||
|
{exam && (
|
||||||
|
<Tooltip label="Начать экзамен" fontSize="12px" top="16px">
|
||||||
|
<Button
|
||||||
|
leftIcon={<LinkIcon />}
|
||||||
|
as={'a'}
|
||||||
|
colorScheme="blue"
|
||||||
|
href={
|
||||||
|
getNavigationsValue('exam.main') +
|
||||||
|
getNavigationsValue('link.exam.details')
|
||||||
|
.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>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</Heading>
|
||||||
|
)}
|
||||||
|
{!Boolean(exam) && (
|
||||||
<>
|
<>
|
||||||
<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">
|
Не задан
|
||||||
<Button
|
</Heading>
|
||||||
leftIcon={<LinkIcon />}
|
<Box mt={10}>
|
||||||
as={'a'}
|
<Tooltip label="Создать экзамен с жюри" fontSize="12px" top="16px">
|
||||||
colorScheme="blue"
|
<Button
|
||||||
href={getNavigationsValue('exam.main') + getNavigationsValue('link.exam.details').replace(':courseId', populatedCourse.id).replace(':examId', exam.id)}
|
colorScheme="blue"
|
||||||
onClick={event => {
|
mt={['16px', 0]}
|
||||||
event.preventDefault();
|
variant="outline"
|
||||||
history.push(getNavigationsValue('exam.main') + getNavigationsValue('link.exam.details').replace(':courseId', populatedCourse.id).replace(':examId', exam.id))
|
isLoading={examWithJuryRequest.isLoading}
|
||||||
}}
|
onClick={() => toggleExamWithJury(populatedCourse.id)}
|
||||||
>
|
>
|
||||||
Открыть
|
Создать
|
||||||
</Button>
|
</Button>
|
||||||
</Tooltip>}
|
</Tooltip>
|
||||||
</Heading>
|
</Box>
|
||||||
{!Boolean(exam) && (
|
|
||||||
<>
|
|
||||||
<Heading as="h3" mt={4} mb={3} size="lg">
|
|
||||||
Не задан
|
|
||||||
</Heading>
|
|
||||||
<Box mt={10}>
|
|
||||||
<Tooltip label="Создать экзамен с жюри" fontSize="12px" top="16px">
|
|
||||||
<Button
|
|
||||||
colorScheme="blue"
|
|
||||||
mt={["16px", 0]}
|
|
||||||
variant="outline"
|
|
||||||
isLoading={examWithJuryRequest.isLoading}
|
|
||||||
onClick={() => toggleExamWithJury(populatedCourse.id)}
|
|
||||||
>
|
|
||||||
Создать
|
|
||||||
</Button>
|
|
||||||
</Tooltip>
|
|
||||||
</Box>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{Boolean(exam) && (
|
|
||||||
<>
|
|
||||||
<Heading as="h3" mt={4} mb={3} size="lg">
|
|
||||||
Количество членов жюри:
|
|
||||||
</Heading>
|
|
||||||
<Heading as="h3" mt={4} mb={3} size="lg">
|
|
||||||
{populatedCourse.examWithJury.jury.length}
|
|
||||||
</Heading></>
|
|
||||||
|
|
||||||
)}
|
|
||||||
<Heading as="h3" mt={4} mb={3} size="lg">
|
|
||||||
Список занятий:
|
|
||||||
</Heading>
|
|
||||||
<Stack>
|
|
||||||
{populatedCourse?.lessons?.map((lesson) => (
|
|
||||||
<Link
|
|
||||||
as={ConnectedLink}
|
|
||||||
key={lesson.id}
|
|
||||||
to={
|
|
||||||
isTeacher(user)
|
|
||||||
? `${getNavigationsValue('journal.main')}/lesson/${populatedCourse.id}/${lesson.id}`
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{lesson.name}
|
|
||||||
</Link>
|
|
||||||
))}
|
|
||||||
</Stack>
|
|
||||||
</>
|
</>
|
||||||
)
|
)}
|
||||||
}
|
{Boolean(exam) && (
|
||||||
|
<>
|
||||||
|
<Heading as="h3" mt={4} mb={3} size="lg">
|
||||||
|
Количество членов жюри:
|
||||||
|
</Heading>
|
||||||
|
<Heading as="h3" mt={4} mb={3} size="lg">
|
||||||
|
{populatedCourse.examWithJury.jury.length}
|
||||||
|
</Heading>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<Heading as="h3" mt={4} mb={3} size="lg">
|
||||||
|
Список занятий:
|
||||||
|
</Heading>
|
||||||
|
<Stack>
|
||||||
|
{populatedCourse?.lessons?.map((lesson) => (
|
||||||
|
<Link
|
||||||
|
as={ConnectedLink}
|
||||||
|
key={lesson.id}
|
||||||
|
to={
|
||||||
|
isTeacher(user)
|
||||||
|
? `${getNavigationsValue('journal.main')}/lesson/${populatedCourse.id}/${lesson.id}`
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{lesson.name}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -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'));
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import {
|
|||||||
StudentList,
|
StudentList,
|
||||||
BreadcrumbsWrapper,
|
BreadcrumbsWrapper,
|
||||||
} from './style'
|
} from './style'
|
||||||
|
import { useAppSelector } from '../__data__/store'
|
||||||
|
import { isTeacher } from '../utils/user'
|
||||||
|
|
||||||
export function getGravatarURL(email, user) {
|
export function getGravatarURL(email, user) {
|
||||||
if (!email) return void 0
|
if (!email) return void 0
|
||||||
@@ -37,6 +39,8 @@ export function getGravatarURL(email, user) {
|
|||||||
const LessonDetail = () => {
|
const LessonDetail = () => {
|
||||||
const { lessonId, courseId } = useParams()
|
const { lessonId, courseId } = useParams()
|
||||||
const canvRef = useRef(null)
|
const canvRef = useRef(null)
|
||||||
|
const user = useAppSelector((s) => s.user)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isFetching,
|
isFetching,
|
||||||
data: accessCode,
|
data: accessCode,
|
||||||
@@ -45,6 +49,7 @@ const LessonDetail = () => {
|
|||||||
} = api.useCreateAccessCodeQuery(
|
} = api.useCreateAccessCodeQuery(
|
||||||
{ lessonId },
|
{ lessonId },
|
||||||
{
|
{
|
||||||
|
skip: !isTeacher(user),
|
||||||
pollingInterval:
|
pollingInterval:
|
||||||
Number(getConfigValue('journal.polling-interval')) || 3000,
|
Number(getConfigValue('journal.polling-interval')) || 3000,
|
||||||
skipPollingIfUnfocused: true,
|
skipPollingIfUnfocused: true,
|
||||||
@@ -144,7 +149,7 @@ const LessonDetail = () => {
|
|||||||
<QRCanvas ref={canvRef} />
|
<QRCanvas ref={canvRef} />
|
||||||
</a>
|
</a>
|
||||||
<StudentList>
|
<StudentList>
|
||||||
{studentsArr.map((student) => (
|
{isTeacher(user) && studentsArr.map((student) => (
|
||||||
<UserCard
|
<UserCard
|
||||||
wrapperAS="li"
|
wrapperAS="li"
|
||||||
key={student.sub}
|
key={student.sub}
|
||||||
|
|||||||
144
src/pages/lesson-list/components/item.tsx
Normal file
144
src/pages/lesson-list/components/item.tsx
Normal 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>
|
||||||
|
)
|
||||||
|
}
|
||||||
45
src/pages/lesson-list/components/lesson-items.tsx
Normal file
45
src/pages/lesson-list/components/lesson-items.tsx
Normal 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}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useForm, Controller } from 'react-hook-form'
|
import { useForm, Controller } from 'react-hook-form'
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Card,
|
Card,
|
||||||
CardBody,
|
CardBody,
|
||||||
CardHeader,
|
CardHeader,
|
||||||
Heading,
|
Heading,
|
||||||
Button,
|
Button,
|
||||||
CloseButton,
|
CloseButton,
|
||||||
VStack,
|
VStack,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormHelperText,
|
FormHelperText,
|
||||||
FormErrorMessage,
|
FormErrorMessage,
|
||||||
Input,
|
Input,
|
||||||
} from '@chakra-ui/react'
|
} from '@chakra-ui/react'
|
||||||
import { AddIcon } from '@chakra-ui/icons'
|
import { AddIcon } from '@chakra-ui/icons'
|
||||||
|
|
||||||
@@ -22,116 +22,119 @@ 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 {
|
||||||
lesson?: Partial<Lesson>
|
lesson?: Partial<Lesson>
|
||||||
isLoading: boolean
|
isLoading: boolean
|
||||||
onCancel: () => void
|
onCancel: () => void
|
||||||
onSubmit: (lesson: Lesson) => void
|
onSubmit: (lesson: Lesson) => void
|
||||||
error?: string
|
error?: string
|
||||||
title: string
|
title: string
|
||||||
nameButton: string
|
nameButton: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const LessonForm = ({
|
export const LessonForm = ({
|
||||||
lesson,
|
lesson,
|
||||||
isLoading,
|
isLoading,
|
||||||
onCancel,
|
onCancel,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
error,
|
error,
|
||||||
title,
|
title,
|
||||||
nameButton,
|
nameButton,
|
||||||
}: LessonFormProps) => {
|
}: LessonFormProps) => {
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
reset,
|
reset,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<NewLessonForm>({
|
} = useForm<NewLessonForm>({
|
||||||
defaultValues: (lesson && { ...lesson, date: dateToCalendarFormat(lesson.date) }) || {
|
defaultValues: (lesson && {
|
||||||
name: '',
|
...lesson,
|
||||||
date: dateToCalendarFormat(),
|
date: dateToCalendarFormat(lesson.date),
|
||||||
},
|
}) || {
|
||||||
})
|
name: '',
|
||||||
|
date: dateToCalendarFormat(),
|
||||||
return (
|
},
|
||||||
<Card align="left">
|
})
|
||||||
<CardHeader display="flex">
|
|
||||||
|
return (
|
||||||
|
<Card align="left">
|
||||||
|
<CardHeader display="flex">
|
||||||
<Heading as="h2" mt="0">
|
<Heading as="h2" mt="0">
|
||||||
{title}
|
{title}
|
||||||
</Heading>
|
</Heading>
|
||||||
<CloseButton
|
<CloseButton
|
||||||
ml="auto"
|
ml="auto"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
reset()
|
reset()
|
||||||
onCancel()
|
onCancel()
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<VStack spacing="10" align="left">
|
<VStack spacing="10" align="left">
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="date"
|
name="date"
|
||||||
rules={{ required: 'Обязательное поле' }}
|
rules={{ required: 'Обязательное поле' }}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<FormLabel>Дата</FormLabel>
|
<FormLabel>Дата</FormLabel>
|
||||||
<Input
|
<Input
|
||||||
{...field}
|
{...field}
|
||||||
required={false}
|
required={false}
|
||||||
placeholder="Укажите дату лекции"
|
placeholder="Укажите дату лекции"
|
||||||
size="md"
|
size="md"
|
||||||
type="datetime-local"
|
type="datetime-local"
|
||||||
|
/>
|
||||||
|
{errors.date ? (
|
||||||
|
<FormErrorMessage>{errors.date?.message}</FormErrorMessage>
|
||||||
|
) : (
|
||||||
|
<FormHelperText>Укажите дату и время лекции</FormHelperText>
|
||||||
|
)}
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
{errors.date ? (
|
|
||||||
<FormErrorMessage>{errors.date?.message}</FormErrorMessage>
|
<Controller
|
||||||
) : (
|
control={control}
|
||||||
<FormHelperText>Укажите дату и время лекции</FormHelperText>
|
name="name"
|
||||||
)}
|
rules={{ required: 'Обязательное поле' }}
|
||||||
</FormControl>
|
render={({ field }) => (
|
||||||
)}
|
<FormControl isRequired isInvalid={Boolean(errors.name)}>
|
||||||
/>
|
<FormLabel>Название новой лекции:</FormLabel>
|
||||||
|
<Input
|
||||||
<Controller
|
{...field}
|
||||||
control={control}
|
required={false}
|
||||||
name="name"
|
placeholder="Название лекции"
|
||||||
rules={{ required: 'Обязательное поле' }}
|
size="md"
|
||||||
render={({ field }) => (
|
/>
|
||||||
<FormControl isRequired isInvalid={Boolean(errors.name)}>
|
{errors.name && (
|
||||||
<FormLabel>Название новой лекции:</FormLabel>
|
<FormErrorMessage>{errors.name.message}</FormErrorMessage>
|
||||||
<Input
|
)}
|
||||||
{...field}
|
</FormControl>
|
||||||
required={false}
|
)}
|
||||||
placeholder="Название лекции"
|
|
||||||
size="md"
|
|
||||||
/>
|
/>
|
||||||
{errors.name && (
|
<Box mt="10">
|
||||||
<FormErrorMessage>{errors.name.message}</FormErrorMessage>
|
<Button
|
||||||
)}
|
size="lg"
|
||||||
</FormControl>
|
type="submit"
|
||||||
)}
|
leftIcon={<AddIcon />}
|
||||||
/>
|
colorScheme="blue"
|
||||||
<Box mt="10">
|
isLoading={isLoading}
|
||||||
<Button
|
>
|
||||||
size="lg"
|
{nameButton}
|
||||||
type="submit"
|
</Button>
|
||||||
leftIcon={<AddIcon />}
|
</Box>
|
||||||
colorScheme="blue"
|
</VStack>
|
||||||
isLoading={isLoading}
|
|
||||||
>
|
{error && <ErrorSpan>{error}</ErrorSpan>}
|
||||||
{nameButton}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
</VStack>
|
|
||||||
|
|
||||||
{error && <ErrorSpan>{error}</ErrorSpan>}
|
|
||||||
</form>
|
</form>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,19 +246,17 @@ const LessonList = () => {
|
|||||||
nameButton={editLesson ? 'Редактировать' : 'Создать'}
|
nameButton={editLesson ? 'Редактировать' : 'Создать'}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Box p="2" m="2">
|
<Button
|
||||||
<Button
|
leftIcon={<AddIcon />}
|
||||||
leftIcon={<AddIcon />}
|
colorScheme="green"
|
||||||
colorScheme="green"
|
onClick={() => setShowForm(true)}
|
||||||
onClick={() => setShowForm(true)}
|
>
|
||||||
>
|
Добавить
|
||||||
Добавить
|
</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>
|
||||||
|
|||||||
@@ -4,6 +4,13 @@
|
|||||||
{
|
{
|
||||||
"_id": "65e2e5fbec37fec650f28489",
|
"_id": "65e2e5fbec37fec650f28489",
|
||||||
"name": "ВВЕДЕНИЕ В ВЕБ-РАЗРАБОТКУ. ИНСТРУМЕНТАРИЙ, ОБЗОР ВЕБ-ТЕХНОЛОГИЙ",
|
"name": "ВВЕДЕНИЕ В ВЕБ-РАЗРАБОТКУ. ИНСТРУМЕНТАРИЙ, ОБЗОР ВЕБ-ТЕХНОЛОГИЙ",
|
||||||
|
"teachers": [
|
||||||
|
{
|
||||||
|
"sub": "f62905b1-e223-40ca-910f-c8d84c6137c1",
|
||||||
|
"email_verified": true,
|
||||||
|
"preferred_username": "primakov"
|
||||||
|
}
|
||||||
|
],
|
||||||
"students": [
|
"students": [
|
||||||
{
|
{
|
||||||
"sub": "fcde3f22-d9ba-412a-a572-c59e515a290f",
|
"sub": "fcde3f22-d9ba-412a-a572-c59e515a290f",
|
||||||
|
|||||||
@@ -1,25 +1,26 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": [
|
"lib": ["dom", "es2017"],
|
||||||
"dom",
|
|
||||||
"es2017"
|
|
||||||
],
|
|
||||||
"outDir": "./dist/",
|
"outDir": "./dist/",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"moduleResolution": "node",
|
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
"typeRoots": ["node_modules/@types", "src/typings"],
|
"typeRoots": ["node_modules/@types", "./@types"],
|
||||||
"types" : ["webpack-env", "node"],
|
"types": ["webpack-env", "node"],
|
||||||
"resolveJsonModule": true
|
"resolveJsonModule": true,
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"skipLibCheck": true,
|
||||||
},
|
},
|
||||||
|
"types": [
|
||||||
|
"@types/*"
|
||||||
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"**/*.test.ts",
|
"**/*.test.ts",
|
||||||
"**/*.test.tsx",
|
"**/*.test.tsx",
|
||||||
"node_modules/@types/jest"
|
"node_modules/@types/jest"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user