Skip to content

Commit

Permalink
Merge branch 'super-user-interface-adding-content' into frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
semant1cs committed Dec 14, 2023
2 parents 23200d1 + 98e3249 commit 6245aa9
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 40 deletions.
19 changes: 19 additions & 0 deletions frontend/src/UIComponents/customAddButton/CustomAddButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import styles from "./customAddButton.module.scss"

interface ICustomAddButton {
handleOnClick: () => void;
}

const CustomAddButton: React.FC<ICustomAddButton> = ({handleOnClick}) => {
return (
<div onClick={handleOnClick} className={styles.add__btn}>
<svg width="70" height="70" viewBox="0 0 70 70" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="35" cy="35" r="35" fill="#00D29D"/>
<path d="M35 10V60M10 34.5H35H60" stroke="white" strokeWidth="4"/>
</svg>
</div>
);
};

export default CustomAddButton;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.add__btn{
:hover {
cursor: pointer
}
}
5 changes: 5 additions & 0 deletions frontend/src/UIComponents/customInput/CustomInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IPropTypes {
register?: UseFormRegister<FormValues>,
required?: boolean,
value?: string,
handleOnChange?: (e: string) => void,
}

const CustomInput: React.FC<IPropTypes> =
Expand All @@ -33,6 +34,8 @@ const CustomInput: React.FC<IPropTypes> =
defaultValue,
register,
validateRules,
value,
handleOnChange,
...inputProps
}) => {
return (
Expand All @@ -49,6 +52,8 @@ const CustomInput: React.FC<IPropTypes> =
defaultValue={defaultValue}
{...register !== undefined && name !== undefined ? {...register(name, validateRules)} : ""}
{...inputProps}
value={value}
onChange={(e) => handleOnChange ? (e.target.value) : undefined}
/>
{/*{error.message && <span className="custom-input__error">{error.message}</span>}*/}
</div>
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/components/authentication/AuthForm.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, {useCallback, useState} from 'react';

import CustomInput from "../../UIComponents/customInput/CustomInput.tsx";
import CustomCheckbox from "../../UIComponents/customCheckbox/CustomCheckbox.tsx";
import CustomInput from "../../UIComponents/customInput/CustomInput";
import CustomCheckbox from "../../UIComponents/customCheckbox/CustomCheckbox";

import {useNavigate} from "react-router-dom"
import {useForm} from "react-hook-form";

import {observer} from "mobx-react-lite";

import authStore from "../../store/authStore.ts";
import auth from "../../utils/auth.ts";
import authStore from "../../store/authStore";
import auth from "../../utils/auth";
import Starfield from "react-starfield";

export type FormValues = {
Expand All @@ -29,7 +29,6 @@ const AuthForm: React.FC = observer(() => {

const onHandleSubmit = useCallback((data: { login: string, password: string }) => {
authStore.signIn(data.login, data.password).then(() => navigateTo('/map'))
console.log(data.login, data.password)
}, [navigateTo])

return (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/mapMenu/MapMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const MapMenu: React.FC = observer(() => {
speedFactor={0.05}
backgroundColor="black"
/>
{user?.is_superuser
{!user?.is_superuser
? <SuperUserMap/>
: <EmployeeMap user={user} formattedDate={formattedDate}/>
}
Expand Down
72 changes: 46 additions & 26 deletions frontend/src/components/mapMenu/SuperUserMap/SuperUserMap.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect, useState} from 'react';
import React, {useCallback, useEffect, useState} from 'react';
import CustomButton from "../../../UIComponents/customButton/CustomButton.tsx";
import mapMenuStore from "../../../store/mapMenuStore.ts";
import CustomInput from "../../../UIComponents/customInput/CustomInput.tsx";
Expand All @@ -8,6 +8,7 @@ import moduleMenuStore from "../../../store/moduleMenuStore.ts";
import {IMapType} from "../../../types/MapType.ts";
import ModalWindow from "../../../UIComponents/modalWindow/ModalWindow.tsx";
import UsersListModalBody from "./UsersListModalBody.tsx";
import CustomAddButton from "../../../UIComponents/customAddButton/CustomAddButton.tsx";

interface ISuperUserMap {

Expand All @@ -16,55 +17,74 @@ interface ISuperUserMap {
const SuperUserMap: React.FC<ISuperUserMap> = observer(() => {
const [isUsersListModalOpen, setIsUserListModalOpen] = useState<boolean>(false)

const [mapName, setMapName] = useState<string>("")
const [moduleName, setModuleName] = useState<string>("")
const [levelName, setLevelName] = useState<string>("")

useEffect(() => {
mapMenuStore.fetchAvailableMaps()
.then(() => mapMenuStore.fetchMapById(mapMenuStore.availableMaps[mapMenuStore.currentMapIndex].id)
.then(() => moduleMenuStore.fetchModules()))
}, []);

function handleOnClickOptionMap(map: IMapType, indexMap: number) {
const handleOnClickOptionMap = useCallback((map: IMapType, indexMap: number) => {
mapMenuStore.selectMap(map).then(() => mapMenuStore.changeCurrentMapIndex(indexMap))
}
}, [])

function handleOnClickChangeIsModalOpen() {
const handleOnClickChangeIsModalOpen = useCallback(() => {
setIsUserListModalOpen(!isUsersListModalOpen)
}

}, [isUsersListModalOpen])

return (
<div>
{isUsersListModalOpen
? <ModalWindow
onClose={handleOnClickChangeIsModalOpen}
body={<UsersListModalBody users={superUserStore.allUsers}/>}
windowContentStyles=""
/>
: ""}
<CustomButton handleOnClick={handleOnClickChangeIsModalOpen} text="Открыть список сотрудников"/>
<select>
{superUserStore.allUsers.map((user) =>
<option key={user.username} value={user.username}>{user.username}</option>)}
</select>
{
isUsersListModalOpen
? <ModalWindow
onClose={handleOnClickChangeIsModalOpen}
body={<UsersListModalBody users={superUserStore.allUsers}/>}
windowContentStyles=""
/>
: null
}


<CustomButton additionalClassName="users-list__btn" handleOnClick={handleOnClickChangeIsModalOpen}
text="Открыть список сотрудников"/>

{/*<select>*/}
{/* {superUserStore.allUsers.map((user) =>*/}
{/* <option key={user.username} value={user.username}>{user.username}</option>)}*/}
{/*</select>*/}

<div className="map-create">
<CustomInput
type="text" value={mapMenuStore.newNameMap}
handleOnChange={(e) => mapMenuStore.changeNewMapName(e)}
/>
<CustomAddButton
handleOnClick={() => mapMenuStore.createMap(mapMenuStore.newNameMap)}
/>
</div>

<div className="module-create">
<CustomButton text="Создать новый модуль"
handleOnClick={() => mapMenuStore.createMap(mapMenuStore.newNameMap)}/>
<CustomInput type="text" value={mapMenuStore.newNameMap}
handleOnChange={(e) => mapMenuStore.changeNewMapName(e)}/>
<CustomButton text="Создать новую карту"
handleOnClick={() => mapMenuStore.createMap(mapMenuStore.newNameMap)}/>
</div>

<select className="available-maps">
{mapMenuStore.availableMaps?.map((map, index) =>
<option key={map.id} value={map.title}
onClick={() => handleOnClickOptionMap(map, index)}>{map.title}</option>)}
<CustomButton text="Удалить выбранную карту" additionalClassName="delete-map__btn"
handleOnClick={() => mapMenuStore.deleteMap(mapMenuStore.mapMenu?.id)}/>
</select>
<CustomButton text="Удалить выбранную карту" additionalClassName="delete-map__btn"
handleOnClick={() => mapMenuStore.deleteMap(mapMenuStore.mapMenu?.id)}/>

<select className="available-modules">
{moduleMenuStore.availableModules.map((module) =>
<option key={module.id} value={module.title}>{module.title}</option>)}
</select>
{/*<select className="available-modules">*/}
{/* {moduleMenuStore.availableModules.map((module) =>*/}
{/* <option key={module.id} value={module.title}>{module.title}</option>)}*/}
{/*</select>*/}
</div>
);
});
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/store/mapMenuStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class MapMenuStore {
id: level.id,
title: level.title,
body: level.body,
theoryUnits: level.theory_units,
taskUnits: level.task_units
theoryUnits: level.theoryUnits,
taskUnits: level.taskUnits,
}
})
}
Expand Down Expand Up @@ -107,7 +107,7 @@ class MapMenuStore {
// Для суперпользователя

createMap(mapName: string) {
axios.post("http://localhost:8000/maps/", {title: mapName}).then()
axios.post("http://localhost:8000/maps/", {title: mapName}).then(() => this.fetchAvailableMaps())
this.newNameMap = ""
}

Expand All @@ -127,7 +127,7 @@ class MapMenuStore {

deleteMap(mapId?: string) {
axios.delete("http://localhost:8000/maps/" + mapId)
.then()
.then(() => this.fetchAvailableMaps())
.catch(() => alert("Выбрана несуществующая карта"))
}
}
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/styles/mapMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,14 @@
right: 10%;
top: 5%;
}

.users-list__btn {
margin-bottom: 10px;
}

.map-create {
display: flex;
align-items: end;
justify-content: center;
gap: 10px;
}
15 changes: 11 additions & 4 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"module": "ESNext",
"skipLibCheck": true,

"esModuleInterop": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
Expand All @@ -24,5 +27,9 @@
"include": [
"src"
],
"references": [{ "path": "./tsconfig.node.json"}]
"references": [
{
"path": "./tsconfig.node.json"
}
]
}

0 comments on commit 6245aa9

Please sign in to comment.