Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdf6c5e8a1 | ||
|
|
87c08e18bd | ||
|
|
2d98b55bbc | ||
|
|
ced1f85a7f | ||
|
|
e21b41f9ca | ||
|
|
cb3629bd43 | ||
|
|
65216843ac | ||
|
|
a76fce5506 | ||
|
|
c842befc8f | ||
|
|
fb267a11f9 | ||
|
|
a94acbf7d3 | ||
| 1cd1e26751 | |||
|
|
d7b521c2ec | ||
|
|
a669e2af81 | ||
|
|
f093c0f3ad | ||
| 61cfd689f8 | |||
| 82a54022b2 | |||
| f28c644da5 | |||
| 50bf5b31b6 | |||
| 5670a96696 | |||
| 3a13b68a3d | |||
| fc3366d52a |
80
Jenkinsfile
vendored
80
Jenkinsfile
vendored
@@ -1,37 +1,57 @@
|
||||
pipeline {
|
||||
agent {
|
||||
docker {
|
||||
image 'node:18'
|
||||
}
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('install') {
|
||||
steps {
|
||||
sh 'node -v'
|
||||
sh 'npm -v'
|
||||
sh 'npm ci'
|
||||
}
|
||||
agent {
|
||||
docker {
|
||||
image 'node:20'
|
||||
}
|
||||
}
|
||||
|
||||
stage('eslint') {
|
||||
steps {
|
||||
sh 'npm run eslint'
|
||||
}
|
||||
}
|
||||
stages {
|
||||
stage('install') {
|
||||
steps {
|
||||
sh 'node -v'
|
||||
sh 'npm -v'
|
||||
script {
|
||||
String tag = sh(returnStdout: true, script: 'git tag --contains').trim()
|
||||
String branchName = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()
|
||||
String commit = sh(returnStdout: true, script: 'git log -1 --oneline').trim()
|
||||
String commitMsg = commit.substring(commit.indexOf(' ')).trim()
|
||||
|
||||
stage('build') {
|
||||
steps {
|
||||
sh 'npm run build'
|
||||
}
|
||||
}
|
||||
if (tag) {
|
||||
currentBuild.displayName = "#${BUILD_NUMBER}, tag ${tag}"
|
||||
} else {
|
||||
currentBuild.displayName = "#${BUILD_NUMBER}, branch ${branchName}"
|
||||
}
|
||||
|
||||
stage('clean-all') {
|
||||
steps {
|
||||
sh 'rm -rf .[!.]*'
|
||||
sh 'rm -rf ./*'
|
||||
sh 'ls -a'
|
||||
}
|
||||
String author = sh(returnStdout: true, script: "git log -1 --pretty=format:'%an'").trim()
|
||||
currentBuild.description = "${author}<br />${commitMsg}"
|
||||
echo 'starting installing'
|
||||
sh 'npm ci'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('checks') {
|
||||
parallel {
|
||||
stage('eslint') {
|
||||
steps {
|
||||
sh 'npm run eslint'
|
||||
}
|
||||
}
|
||||
|
||||
stage('build') {
|
||||
steps {
|
||||
sh 'npm run build'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('clean-all') {
|
||||
steps {
|
||||
sh 'rm -rf .[!.]*'
|
||||
sh 'rm -rf ./*'
|
||||
sh 'ls -a'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ npm install
|
||||
пропишите в hosts строку
|
||||
|
||||
```
|
||||
127.0.0.1 ift-b1.kc.inno-js.test
|
||||
127.0.0.1 journal.test
|
||||
```
|
||||
|
||||
## Запуск
|
||||
@@ -28,4 +28,4 @@ npm install
|
||||
npm start
|
||||
```
|
||||
|
||||
откройте в браузере [проект](http://ift-b1.kc.inno-js.test)
|
||||
откройте в браузере [проект](http://journal.test)
|
||||
@@ -12,7 +12,6 @@ module.exports = {
|
||||
},
|
||||
features: {
|
||||
journal: {
|
||||
// add your features here in the format [featureName]: { value: string }
|
||||
'lesson.bar': {
|
||||
on: true,
|
||||
value: '',
|
||||
|
||||
2
index.d.ts
vendored
2
index.d.ts
vendored
@@ -2,3 +2,5 @@ declare module '*.svg' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare const __webpack_public_path__: string;
|
||||
8789
package-lock.json
generated
8789
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@@ -1,31 +1,31 @@
|
||||
{
|
||||
"name": "journal.pl",
|
||||
"version": "2.4.1",
|
||||
"description": "inno-js platform journal ui repo",
|
||||
"version": "3.1.2",
|
||||
"description": "bro-js platform journal ui repo",
|
||||
"main": "./src/index.tsx",
|
||||
"scripts": {
|
||||
"start": "start chrome http://ift-b1.kc.inno-js.test/journal.pl & ijl-cli server --port=80",
|
||||
"build": "npm run clean && ijl-cli build --dev",
|
||||
"build:prod": "npm run clean && ijl-cli build",
|
||||
"start": "brojs server --port=8099 --with-open-browser",
|
||||
"build": "npm run clean && brojs build --dev",
|
||||
"build:prod": "npm run clean && brojs build",
|
||||
"clean": "rimraf dist",
|
||||
"test": "echo ok",
|
||||
"eslint": "npx eslint ."
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "ssh://git@85.143.175.152:10022/omni-tech/journal.pl.git"
|
||||
"url": "ssh://git@85.143.175.152:222/bro-js/journal.pl.git"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@ijl/cli": "^5.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
||||
"@typescript-eslint/parser": "^7.4.0",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-plugin-react": "^7.34.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@brojs/cli": "^0.0.4-alpha.10",
|
||||
"@chakra-ui/icons": "^2.1.1",
|
||||
"@chakra-ui/react": "^2.8.2",
|
||||
"@emotion/react": "^11.11.4",
|
||||
@@ -35,18 +35,19 @@
|
||||
"@types/react": "^18.2.60",
|
||||
"@types/react-dom": "^18.2.19",
|
||||
"dayjs": "^1.11.10",
|
||||
"express": "^4.18.2",
|
||||
"express": "^4.19.2",
|
||||
"js-sha256": "^0.11.0",
|
||||
"keycloak-js": "^23.0.7",
|
||||
"prettier": "^3.2.5",
|
||||
"qrcode": "^1.5.3",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-helmet": "^6.1.0",
|
||||
"react-hook-form": "^7.51.2",
|
||||
"react-redux": "^9.1.0",
|
||||
"react-router-dom": "^6.22.1",
|
||||
"redux": "^5.0.1",
|
||||
"typescript": "^5.3.3"
|
||||
"typescript": "^5.3.3",
|
||||
"webpack-hot-middleware": "^2.26.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
|
||||
import { getConfigValue } from '@ijl/cli'
|
||||
import { getConfigValue } from '@brojs/cli'
|
||||
|
||||
import { keycloak } from '../kc'
|
||||
import {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import Keycloak from 'keycloak-js';
|
||||
|
||||
export const keycloak = new Keycloak({
|
||||
url: 'https://kc.inno-js.ru',
|
||||
realm: 'inno-js',
|
||||
url: 'https://kc.bro-js.ru',
|
||||
realm: 'bro-js',
|
||||
clientId: 'journal'
|
||||
});
|
||||
|
||||
|
||||
87
src/app.tsx
87
src/app.tsx
@@ -1,87 +1,28 @@
|
||||
import React from 'react';
|
||||
import { Helmet } from 'react-helmet';
|
||||
import { Global, css } from '@emotion/react'
|
||||
import { Global } from '@emotion/react'
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
import ruLocale from 'dayjs/locale/ru';
|
||||
import dayjs from 'dayjs';
|
||||
import { ChakraProvider } from '@chakra-ui/react'
|
||||
|
||||
import { Dashboard } from './dashboard';
|
||||
import { globalStyles } from './global.styles';
|
||||
|
||||
dayjs.locale('ru', ruLocale);
|
||||
|
||||
const App = ({ store }) => {
|
||||
return(
|
||||
<ChakraProvider>
|
||||
<BrowserRouter>
|
||||
<Helmet>
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no" />
|
||||
<title>Журнал</title>
|
||||
</Helmet>
|
||||
<Global
|
||||
styles={css`
|
||||
html {
|
||||
height: 100%;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
body {
|
||||
color: #000;
|
||||
/* background: radial-gradient(circle at top right, rgb(154 227 33), rgb(33 160 56)); */
|
||||
background: radial-gradient(
|
||||
farthest-side at bottom left,
|
||||
rgba(35, 235, 4, 0.709),
|
||||
rgba(255, 255, 255, 0) 65%
|
||||
),
|
||||
radial-gradient(
|
||||
farthest-corner at bottom center,
|
||||
rgba(244, 244, 8, 0.6),
|
||||
rgba(255, 255, 255, 0) 40%
|
||||
),
|
||||
radial-gradient(
|
||||
farthest-side at bottom right,
|
||||
rgba(0, 195, 255, 0.648),
|
||||
rgb(239 244 246) 65%
|
||||
/* rgba(255, 255, 255, 0) 65% */
|
||||
);
|
||||
height: 100%;
|
||||
/* font-family: KiyosunaSans, Montserrat, RFKrabuler, sans-serif; */
|
||||
font-weight: 600;
|
||||
}
|
||||
#app {
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'KiyosunaSans';
|
||||
src: url('${__webpack_public_path__ + '/remote-assets/KiyosunaSans/KiyosunaSans-B.otf'}');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'KiyosunaSans';
|
||||
src: url('${__webpack_public_path__ + '/remote-assets/KiyosunaSans/KiyosunaSans-L.otf'}');
|
||||
font-weight: lighter;
|
||||
font-style: normal;
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'RFKrabuler';
|
||||
src: url('${__webpack_public_path__ + '/remote-assets/RF-Krabuler/WEB/RFKrabuler-Regular.eot'}');
|
||||
src:
|
||||
url('${__webpack_public_path__ + '/remote-assets/RF-Krabuler/WEB/RFKrabuler-Regular.woff2'}') format('woff2'),
|
||||
url('${__webpack_public_path__ + '/remote-assets/RF-Krabuler/WEB/RFKrabuler-Regular.woff'}') format('woff'),
|
||||
url('${__webpack_public_path__ + '/remote-assets/RF-Krabuler/TTF/RF-Krabuler-Regular.ttf'}') format('truetype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
`}
|
||||
/>
|
||||
<Dashboard store={store} />
|
||||
</BrowserRouter>
|
||||
</ChakraProvider>
|
||||
)
|
||||
}
|
||||
const App = ({ store }) => (
|
||||
<ChakraProvider>
|
||||
<BrowserRouter>
|
||||
<Helmet>
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no" />
|
||||
<title>Журнал</title>
|
||||
</Helmet>
|
||||
<Global styles={globalStyles} />
|
||||
<Dashboard store={store} />
|
||||
</BrowserRouter>
|
||||
</ChakraProvider>
|
||||
)
|
||||
|
||||
export default App;
|
||||
|
||||
|
||||
1
src/components/xl-spinner/index.ts
Normal file
1
src/components/xl-spinner/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { XlSpinner } from './xl-spinner';
|
||||
20
src/components/xl-spinner/xl-spinner.tsx
Normal file
20
src/components/xl-spinner/xl-spinner.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import React from 'react'
|
||||
import {
|
||||
Container,
|
||||
Center,
|
||||
Spinner,
|
||||
} from '@chakra-ui/react'
|
||||
|
||||
export const XlSpinner = () => (
|
||||
<Container maxW="container.xl">
|
||||
<Center h="300px">
|
||||
<Spinner
|
||||
thickness="4px"
|
||||
speed="0.65s"
|
||||
emptyColor="gray.200"
|
||||
color="blue.500"
|
||||
size="xl"
|
||||
/>
|
||||
</Center>
|
||||
</Container>
|
||||
)
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useEffect, Suspense } from 'react'
|
||||
import { Routes, Route, useNavigate } from 'react-router-dom'
|
||||
import { Provider } from 'react-redux'
|
||||
import { getNavigationsValue } from '@ijl/cli'
|
||||
import { getNavigationsValue } from '@brojs/cli'
|
||||
import { Box, Container, Spinner, VStack } from '@chakra-ui/react'
|
||||
|
||||
import {
|
||||
|
||||
60
src/global.styles.ts
Normal file
60
src/global.styles.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { css } from '@emotion/react'
|
||||
|
||||
export const globalStyles = css`
|
||||
html {
|
||||
height: 100%;
|
||||
max-width: 100%;
|
||||
min-width: 320px;
|
||||
overflow: hidden;
|
||||
}
|
||||
body {
|
||||
color: #000;
|
||||
/* background: radial-gradient(circle at top right, rgb(154 227 33), rgb(33 160 56)); */
|
||||
background: radial-gradient(
|
||||
farthest-side at bottom left,
|
||||
rgba(35, 235, 4, 0.709),
|
||||
rgba(255, 255, 255, 0) 65%
|
||||
),
|
||||
radial-gradient(
|
||||
farthest-corner at bottom center,
|
||||
rgba(244, 244, 8, 0.6),
|
||||
rgba(255, 255, 255, 0) 40%
|
||||
),
|
||||
radial-gradient(
|
||||
farthest-side at bottom right,
|
||||
rgba(0, 195, 255, 0.648),
|
||||
rgb(239 244 246) 65%
|
||||
/* rgba(255, 255, 255, 0) 65% */
|
||||
);
|
||||
height: 100%;
|
||||
/* font-family: KiyosunaSans, Montserrat, RFKrabuler, sans-serif; */
|
||||
font-weight: 600;
|
||||
}
|
||||
#app {
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'KiyosunaSans';
|
||||
src: url('${__webpack_public_path__ + '/remote-assets/KiyosunaSans/KiyosunaSans-B.otf'}');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'KiyosunaSans';
|
||||
src: url('${__webpack_public_path__ + '/remote-assets/KiyosunaSans/KiyosunaSans-L.otf'}');
|
||||
font-weight: lighter;
|
||||
font-style: normal;
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'RFKrabuler';
|
||||
src: url('${__webpack_public_path__ + '/remote-assets/RF-Krabuler/WEB/RFKrabuler-Regular.eot'}');
|
||||
src:
|
||||
url('${__webpack_public_path__ + '/remote-assets/RF-Krabuler/WEB/RFKrabuler-Regular.woff2'}') format('woff2'),
|
||||
url('${__webpack_public_path__ + '/remote-assets/RF-Krabuler/WEB/RFKrabuler-Regular.woff'}') format('woff'),
|
||||
url('${__webpack_public_path__ + '/remote-assets/RF-Krabuler/TTF/RF-Krabuler-Regular.ttf'}') format('truetype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
`
|
||||
@@ -5,6 +5,10 @@ import App from './app';
|
||||
import { keycloak } from "./__data__/kc";
|
||||
import { createStore } from "./__data__/store";
|
||||
|
||||
if(!module.hot) {
|
||||
import('./ym');
|
||||
}
|
||||
|
||||
export default (props) => <App {...props} />;
|
||||
|
||||
let rootElement: ReactDOM.Root
|
||||
@@ -12,7 +16,7 @@ let rootElement: ReactDOM.Root
|
||||
export const mount = async (Сomponent, element = document.getElementById('app')) => {
|
||||
let user = null;
|
||||
try {
|
||||
await keycloak.init({ onLoad: "login-required" }); // 'login-required' });
|
||||
await keycloak.init({ onLoad: "login-required" });
|
||||
user = { ...(await keycloak.loadUserInfo()), ...keycloak.tokenParsed };
|
||||
} catch (error) {
|
||||
console.error("Failed to initialize adapter:", error);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import dayjs from 'dayjs'
|
||||
import { Link as ConnectedLink } from 'react-router-dom'
|
||||
import { getNavigationsValue } from '@ijl/cli'
|
||||
import { getNavigationsValue } from '@brojs/cli'
|
||||
import {
|
||||
Box,
|
||||
CardHeader,
|
||||
@@ -61,8 +61,8 @@ const CoursesList = () => {
|
||||
getValues,
|
||||
} = useForm<NewCourseForm>({
|
||||
defaultValues: {
|
||||
startDt: '',
|
||||
name: '',
|
||||
startDt: dayjs().format('YYYY-MM-DD'),
|
||||
name: 'Название',
|
||||
},
|
||||
})
|
||||
|
||||
@@ -288,7 +288,7 @@ const CourseCard = ({
|
||||
</CardBody>
|
||||
)}
|
||||
<CardFooter>
|
||||
<ButtonGroup spacing="4" mt="16px">
|
||||
<ButtonGroup spacing={[0, 4]} mt="16px" flexDirection={['column', 'row']}>
|
||||
<Tooltip label="На страницу с лекциями" fontSize="12px" top="16px">
|
||||
<Button
|
||||
leftIcon={<LinkIcon />}
|
||||
@@ -302,6 +302,7 @@ const CourseCard = ({
|
||||
<Tooltip label="Детали" fontSize="12px" top="16px">
|
||||
<Button
|
||||
colorScheme="blue"
|
||||
mt={["16px", 0]}
|
||||
variant="outline"
|
||||
leftIcon={isOpened ? <ArrowUpIcon /> : <ArrowDownIcon />}
|
||||
loadingText="Загрузка"
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { lazy } from 'react'
|
||||
|
||||
export const CourseListPage = lazy(/* chank-name="course-details" */() => import('./course-list'));
|
||||
|
||||
export const LessonDetailsPage = lazy(/* chank-name="course-details" */() => import('./lesson-details'));
|
||||
export const LessonListPage = lazy(/* chank-name="course-details" */() => import('./lesson-list'));
|
||||
|
||||
export const UserPage = lazy(/* chank-name="course-details" */() => import('./user-page'));
|
||||
export const CourseListPage = lazy(() => import(/* webpackChunkName: "course-list" */ './course-list'));
|
||||
export const LessonDetailsPage = lazy(() => import(/* webpackChunkName: "lesson-details" */ './lesson-details'));
|
||||
export const LessonListPage = lazy(() => import(/* webpackChunkName: "lesson-list" */ './lesson-list'));
|
||||
export const UserPage = lazy(() => import(/* webpackChunkName: "user-page" */ './user-page'));
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useParams, Link } from 'react-router-dom'
|
||||
import dayjs from 'dayjs'
|
||||
import QRCode from 'qrcode'
|
||||
import { sha256 } from 'js-sha256'
|
||||
import { getConfigValue, getNavigationsValue } from '@ijl/cli'
|
||||
import { getConfigValue, getNavigationsValue } from '@brojs/cli'
|
||||
import {
|
||||
Box,
|
||||
Breadcrumb,
|
||||
|
||||
28
src/pages/lesson-list/components/bar.tsx
Normal file
28
src/pages/lesson-list/components/bar.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import React from 'react'
|
||||
import { ResponsiveBar } from '@nivo/bar'
|
||||
|
||||
export const Bar = ({ data }) => (
|
||||
<ResponsiveBar
|
||||
data={data}
|
||||
keys={['count']}
|
||||
indexBy="lessonIndex"
|
||||
margin={{ top: 50, right: 130, bottom: 50, left: 60 }}
|
||||
padding={0.3}
|
||||
valueScale={{ type: 'linear' }}
|
||||
indexScale={{ type: 'band', round: true }}
|
||||
colors={{ scheme: 'set3' }}
|
||||
axisTop={null}
|
||||
axisRight={null}
|
||||
labelSkipWidth={12}
|
||||
labelSkipHeight={12}
|
||||
labelTextColor={{
|
||||
from: 'color',
|
||||
modifiers: [['brighter', 1.4]],
|
||||
}}
|
||||
role="application"
|
||||
ariaLabel="График посещаемости лекций"
|
||||
barAriaLabel={(e) =>
|
||||
e.id + ': ' + e.formattedValue + ' on lection: ' + e.indexValue
|
||||
}
|
||||
/>
|
||||
)
|
||||
137
src/pages/lesson-list/components/lessons-form.tsx
Normal file
137
src/pages/lesson-list/components/lessons-form.tsx
Normal file
@@ -0,0 +1,137 @@
|
||||
import React from 'react'
|
||||
import { useForm, Controller } from 'react-hook-form'
|
||||
import {
|
||||
Box,
|
||||
Card,
|
||||
CardBody,
|
||||
CardHeader,
|
||||
Heading,
|
||||
Button,
|
||||
CloseButton,
|
||||
VStack,
|
||||
FormControl,
|
||||
FormLabel,
|
||||
FormHelperText,
|
||||
FormErrorMessage,
|
||||
Input,
|
||||
} from '@chakra-ui/react'
|
||||
import { AddIcon } from '@chakra-ui/icons'
|
||||
|
||||
import { dateToCalendarFormat } from '../../../utils/time'
|
||||
import { Lesson } from '../../../__data__/model'
|
||||
import { ErrorSpan } from '../style'
|
||||
|
||||
interface NewLessonForm {
|
||||
name: string;
|
||||
date: string;
|
||||
}
|
||||
|
||||
interface LessonFormProps {
|
||||
lesson?: Partial<Lesson>
|
||||
isLoading: boolean
|
||||
onCancel: () => void
|
||||
onSubmit: (lesson: Lesson) => void
|
||||
error?: string
|
||||
title: string
|
||||
nameButton: string
|
||||
}
|
||||
|
||||
export const LessonForm = ({
|
||||
lesson,
|
||||
isLoading,
|
||||
onCancel,
|
||||
onSubmit,
|
||||
error,
|
||||
title,
|
||||
nameButton,
|
||||
}: LessonFormProps) => {
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { errors },
|
||||
} = useForm<NewLessonForm>({
|
||||
defaultValues: (lesson && { ...lesson, date: dateToCalendarFormat(lesson.date) }) || {
|
||||
name: '',
|
||||
date: dateToCalendarFormat(),
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<Card align="left">
|
||||
<CardHeader display="flex">
|
||||
<Heading as="h2" mt="0">
|
||||
{title}
|
||||
</Heading>
|
||||
<CloseButton
|
||||
ml="auto"
|
||||
onClick={() => {
|
||||
reset()
|
||||
onCancel()
|
||||
}}
|
||||
/>
|
||||
</CardHeader>
|
||||
<CardBody>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<VStack spacing="10" align="left">
|
||||
<Controller
|
||||
control={control}
|
||||
name="date"
|
||||
rules={{ required: 'Обязательное поле' }}
|
||||
render={({ field }) => (
|
||||
<FormControl>
|
||||
<FormLabel>Дата</FormLabel>
|
||||
<Input
|
||||
{...field}
|
||||
required={false}
|
||||
placeholder="Укажите дату лекции"
|
||||
size="md"
|
||||
type="datetime-local"
|
||||
/>
|
||||
{errors.date ? (
|
||||
<FormErrorMessage>{errors.date?.message}</FormErrorMessage>
|
||||
) : (
|
||||
<FormHelperText>Укажите дату и время лекции</FormHelperText>
|
||||
)}
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
control={control}
|
||||
name="name"
|
||||
rules={{ required: 'Обязательное поле' }}
|
||||
render={({ field }) => (
|
||||
<FormControl isRequired isInvalid={Boolean(errors.name)}>
|
||||
<FormLabel>Название новой лекции:</FormLabel>
|
||||
<Input
|
||||
{...field}
|
||||
required={false}
|
||||
placeholder="Название лекции"
|
||||
size="md"
|
||||
/>
|
||||
{errors.name && (
|
||||
<FormErrorMessage>{errors.name.message}</FormErrorMessage>
|
||||
)}
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<Box mt="10">
|
||||
<Button
|
||||
size="lg"
|
||||
type="submit"
|
||||
leftIcon={<AddIcon />}
|
||||
colorScheme="blue"
|
||||
isLoading={isLoading}
|
||||
>
|
||||
{nameButton}
|
||||
</Button>
|
||||
</Box>
|
||||
</VStack>
|
||||
|
||||
{error && <ErrorSpan>{error}</ErrorSpan>}
|
||||
</form>
|
||||
</CardBody>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
3
src/pages/lesson-list/index.ts
Normal file
3
src/pages/lesson-list/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import LessonsList from './lesson-list';
|
||||
|
||||
export default LessonsList;
|
||||
@@ -4,31 +4,18 @@ import React, {
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react'
|
||||
import { ResponsiveBar } from '@nivo/bar'
|
||||
import dayjs from 'dayjs'
|
||||
import { Link, useParams } from 'react-router-dom'
|
||||
import { getNavigationsValue, getFeatures } from '@ijl/cli'
|
||||
import { useForm, Controller } from 'react-hook-form'
|
||||
import { getNavigationsValue, getFeatures } from '@brojs/cli'
|
||||
import {
|
||||
Breadcrumb,
|
||||
BreadcrumbItem,
|
||||
BreadcrumbLink,
|
||||
Container,
|
||||
Box,
|
||||
Card,
|
||||
CardBody,
|
||||
CardHeader,
|
||||
Heading,
|
||||
Button,
|
||||
CloseButton,
|
||||
useToast,
|
||||
VStack,
|
||||
FormControl,
|
||||
FormLabel,
|
||||
Toast,
|
||||
FormHelperText,
|
||||
FormErrorMessage,
|
||||
Input,
|
||||
TableContainer,
|
||||
Table,
|
||||
Thead,
|
||||
@@ -41,8 +28,6 @@ import {
|
||||
MenuItem,
|
||||
Text,
|
||||
MenuList,
|
||||
Center,
|
||||
Spinner,
|
||||
AlertDialog,
|
||||
AlertDialogBody,
|
||||
AlertDialogContent,
|
||||
@@ -52,134 +37,22 @@ import {
|
||||
} from '@chakra-ui/react'
|
||||
import { AddIcon, EditIcon } from '@chakra-ui/icons'
|
||||
|
||||
import { useAppSelector } from '../__data__/store'
|
||||
import { api } from '../__data__/api/api'
|
||||
import { isTeacher } from '../utils/user'
|
||||
import { qrCode } from '../assets'
|
||||
import { Lesson } from '../__data__/model'
|
||||
import { useAppSelector } from '../../__data__/store'
|
||||
import { api } from '../../__data__/api/api'
|
||||
import { isTeacher } from '../../utils/user'
|
||||
import { qrCode } from '../../assets'
|
||||
import { Lesson } from '../../__data__/model'
|
||||
import { XlSpinner } from '../../components/xl-spinner'
|
||||
|
||||
import { ErrorSpan, BreadcrumbsWrapper } from './style'
|
||||
import { LessonForm } from './components/lessons-form'
|
||||
import { BreadcrumbsWrapper } from './style'
|
||||
import { Bar } from './components/bar'
|
||||
|
||||
const features = getFeatures('journal')
|
||||
|
||||
const barFeature = features?.['lesson.bar']
|
||||
const groupByDate = features?.['group.by.date']
|
||||
|
||||
interface NewLessonForm {
|
||||
name: string
|
||||
date: string
|
||||
}
|
||||
|
||||
interface LessonFormProps {
|
||||
lesson?: Partial<Lesson>
|
||||
isLoading: boolean
|
||||
onCancel: () => void
|
||||
onSubmit: (lesson: Lesson) => void
|
||||
error?: string
|
||||
title: string
|
||||
nameButton: string
|
||||
}
|
||||
|
||||
const LessonForm = ({
|
||||
lesson,
|
||||
isLoading,
|
||||
onCancel,
|
||||
onSubmit,
|
||||
error,
|
||||
title,
|
||||
nameButton,
|
||||
}: LessonFormProps) => {
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { errors },
|
||||
} = useForm<NewLessonForm>({
|
||||
defaultValues: lesson || {
|
||||
name: '',
|
||||
date: '',
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<Card align="left">
|
||||
<CardHeader display="flex">
|
||||
<Heading as="h2" mt="0">
|
||||
{title}
|
||||
</Heading>
|
||||
<CloseButton
|
||||
ml="auto"
|
||||
onClick={() => {
|
||||
reset()
|
||||
onCancel()
|
||||
}}
|
||||
/>
|
||||
</CardHeader>
|
||||
<CardBody>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<VStack spacing="10" align="left">
|
||||
<Controller
|
||||
control={control}
|
||||
name="date"
|
||||
rules={{ required: 'Обязательное поле' }}
|
||||
render={({ field }) => (
|
||||
<FormControl>
|
||||
<FormLabel>Дата</FormLabel>
|
||||
<Input
|
||||
{...field}
|
||||
required={false}
|
||||
placeholder="Укажите дату лекции"
|
||||
size="md"
|
||||
type="datetime-local"
|
||||
/>
|
||||
{errors.date ? (
|
||||
<FormErrorMessage>{errors.date?.message}</FormErrorMessage>
|
||||
) : (
|
||||
<FormHelperText>Укажите дату и время лекции</FormHelperText>
|
||||
)}
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
control={control}
|
||||
name="name"
|
||||
rules={{ required: 'Обязательное поле' }}
|
||||
render={({ field }) => (
|
||||
<FormControl isRequired isInvalid={Boolean(errors.name)}>
|
||||
<FormLabel>Название новой лекции:</FormLabel>
|
||||
<Input
|
||||
{...field}
|
||||
required={false}
|
||||
placeholder="Название лекции"
|
||||
size="md"
|
||||
/>
|
||||
{errors.name && (
|
||||
<FormErrorMessage>{errors.name.message}</FormErrorMessage>
|
||||
)}
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<Box mt="10">
|
||||
<Button
|
||||
size="lg"
|
||||
type="submit"
|
||||
leftIcon={<AddIcon />}
|
||||
colorScheme="blue"
|
||||
isLoading={isLoading}
|
||||
>
|
||||
{nameButton}
|
||||
</Button>
|
||||
</Box>
|
||||
</VStack>
|
||||
|
||||
{error && <ErrorSpan>{error}</ErrorSpan>}
|
||||
</form>
|
||||
</CardBody>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
const LessonList = () => {
|
||||
const { courseId } = useParams()
|
||||
const user = useAppSelector((s) => s.user)
|
||||
@@ -194,14 +67,13 @@ const LessonList = () => {
|
||||
const toastRef = useRef(null)
|
||||
const createdLessonRef = useRef(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(() => {
|
||||
if (!isSuccess) {
|
||||
return []
|
||||
}
|
||||
|
||||
|
||||
if (!groupByDate) {
|
||||
return [{ date: '', data: sorted }]
|
||||
}
|
||||
@@ -223,7 +95,7 @@ const LessonList = () => {
|
||||
}
|
||||
}
|
||||
|
||||
return lessonsData
|
||||
return lessonsData.sort((a, b) => a.date < b.date? 1 : -1)
|
||||
}, [groupByDate, isSuccess, sorted])
|
||||
|
||||
const onSubmit = (lessonData) => {
|
||||
@@ -308,19 +180,7 @@ const LessonList = () => {
|
||||
}, [updateLessonRqst.isSuccess])
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<Container maxW="container.xl">
|
||||
<Center h="300px">
|
||||
<Spinner
|
||||
thickness="4px"
|
||||
speed="0.65s"
|
||||
emptyColor="gray.200"
|
||||
color="blue.500"
|
||||
size="xl"
|
||||
/>
|
||||
</Center>
|
||||
</Container>
|
||||
)
|
||||
return <XlSpinner />;
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -453,7 +313,7 @@ const LessonList = () => {
|
||||
</Td>
|
||||
)}
|
||||
<Td textAlign="center">
|
||||
{dayjs(lesson.date).format('H:mm DD.MM.YY')}
|
||||
{dayjs(lesson.date).format(groupByDate ? 'HH:mm' : 'HH:mm DD.MM.YY')}
|
||||
</Td>
|
||||
<Td>{lesson.name}</Td>
|
||||
{isTeacher(user) && (
|
||||
@@ -494,29 +354,3 @@ const LessonList = () => {
|
||||
}
|
||||
|
||||
export default LessonList
|
||||
|
||||
const Bar = ({ data }) => (
|
||||
<ResponsiveBar
|
||||
data={data}
|
||||
keys={['count']}
|
||||
indexBy="lessonIndex"
|
||||
margin={{ top: 50, right: 130, bottom: 50, left: 60 }}
|
||||
padding={0.3}
|
||||
valueScale={{ type: 'linear' }}
|
||||
indexScale={{ type: 'band', round: true }}
|
||||
colors={{ scheme: 'set3' }}
|
||||
axisTop={null}
|
||||
axisRight={null}
|
||||
labelSkipWidth={12}
|
||||
labelSkipHeight={12}
|
||||
labelTextColor={{
|
||||
from: 'color',
|
||||
modifiers: [['brighter', 1.4]],
|
||||
}}
|
||||
role="application"
|
||||
ariaLabel="График посещаемости лекций"
|
||||
barAriaLabel={(e) =>
|
||||
e.id + ': ' + e.formattedValue + ' on lection: ' + e.indexValue
|
||||
}
|
||||
/>
|
||||
)
|
||||
13
src/pages/lesson-list/style.ts
Normal file
13
src/pages/lesson-list/style.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
export const BreadcrumbsWrapper = styled.div`
|
||||
padding: 12px;
|
||||
`;
|
||||
|
||||
export const ErrorSpan = styled.span`
|
||||
color: #f9e2e2;
|
||||
display: block;
|
||||
padding: 16px;
|
||||
background-color: #d32f0b;
|
||||
border-radius: 11px;
|
||||
`
|
||||
@@ -9,10 +9,8 @@ import {
|
||||
Box,
|
||||
Center,
|
||||
Container,
|
||||
Heading,
|
||||
Spinner,
|
||||
Text,
|
||||
Stack,
|
||||
} from '@chakra-ui/react'
|
||||
import { UserCard } from '../components/user-card'
|
||||
|
||||
|
||||
3
src/utils/time.ts
Normal file
3
src/utils/time.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export const dateToCalendarFormat = (date?: string) => dayjs(date).format('YYYY-MM-DDTHH:mm')
|
||||
17
src/ym.ts
Normal file
17
src/ym.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
(function (m, e, t, r, i, k, a) {
|
||||
m[i] = m[i] || function () { (m[i].a = m[i].a || []).push(arguments) };
|
||||
// @ts-ignore
|
||||
m[i].l = 1 * new Date();
|
||||
for (var j = 0; j < document.scripts.length; j++) { if (document.scripts[j].src === r) { return; } }
|
||||
k = e.createElement(t), a = e.getElementsByTagName(t)[0], k.async = 1, k.src = r, a.parentNode.insertBefore(k, a)
|
||||
})(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
|
||||
|
||||
// @ts-ignore
|
||||
ym(98045358, "init", {
|
||||
clickmap: true,
|
||||
trackLinks: true,
|
||||
accurateTrackBounce: true,
|
||||
webvisor: true
|
||||
});
|
||||
|
||||
export const dummy = true;
|
||||
Reference in New Issue
Block a user