diff --git a/frontend/src/components/authentication/AuthForm.tsx b/frontend/src/components/authentication/AuthForm.tsx index 44d6a0c..2ecf272 100644 --- a/frontend/src/components/authentication/AuthForm.tsx +++ b/frontend/src/components/authentication/AuthForm.tsx @@ -30,6 +30,7 @@ const AuthForm: React.FC = observer(() => { const onHandleSubmit = useCallback((data: { login: string, password: string }) => { authStore.signIn(data.login, data.password).then(() => navigateTo('/map')) + authStore.setUser(data.login) }, []) return ( diff --git a/frontend/src/components/mapMenu/EmployeeMap/EmployeeMap.tsx b/frontend/src/components/mapMenu/EmployeeMap/EmployeeMap.tsx index 3d15259..01c9aa2 100644 --- a/frontend/src/components/mapMenu/EmployeeMap/EmployeeMap.tsx +++ b/frontend/src/components/mapMenu/EmployeeMap/EmployeeMap.tsx @@ -1,4 +1,4 @@ -import React, {useEffect} from 'react'; +import React, {useEffect, useState} from 'react'; import Coins from "../UIMapMenu/Coins.tsx"; import ChooseModuleWindow from "../UIMapMenu/ChooseModuleWindow.tsx"; @@ -11,9 +11,11 @@ import {observer} from "mobx-react-lite"; import moduleMenuStore from "../../../store/moduleMenuStore.ts"; import mapMenuStore from "../../../store/mapMenuStore.ts" +import levelStore from "../../../store/levelStore.ts"; import {IUserType} from "../../../types/UserType.ts"; -import levelStore from "../../../store/levelStore.ts"; +import axios from "axios"; +import Starfield from "react-starfield"; interface IEmployeeMap { @@ -23,14 +25,28 @@ interface IEmployeeMap { } const EmployeeMap: React.FC = observer(({user, formattedDate, logOut}) => { + const [isLoading, setIsLoading] = useState(true) + const [employee, setEmployee] = useState(null) + + useEffect(() => { + // console.log(user) + axios.get("http://localhost:8000/employees").then((r) => { + r.data.map((employee) => { + if (user?.id === employee.user.id) { + setEmployee(employee) + setIsLoading(false) + } + }) + }) + }, []); + useEffect(() => { mapMenuStore.fetchAvailableMaps().then(() => { mapMenuStore.fetchMapById(mapMenuStore.availableMaps[0].id).then(() => { moduleMenuStore.fetchModules().then(() => { moduleMenuStore.fetchModuleById(moduleMenuStore.availableModules[0].id).then(() => { levelStore.fetchLevels().then(() => { - - }).catch(() => alert("Нет доступных уровней для данного модуля")) + }) }) }).catch(() => alert("Нет доступных модулей для данной карты")) }) @@ -38,22 +54,52 @@ const EmployeeMap: React.FC = observer(({user, formattedDate, logO }, []); return ( -
- - - - -
-
- {levelStore.availableLevels.map((level, index) => { - return - })} + isLoading ? ( + + ) + : + ( +
+ + + + + +
+
+ {levelStore.availableLevels.map((level, index) => { + return + })} +
+
-
-
+ ) ); }); diff --git a/frontend/src/components/mapMenu/MapMenu.tsx b/frontend/src/components/mapMenu/MapMenu.tsx index 355d547..c8934dd 100644 --- a/frontend/src/components/mapMenu/MapMenu.tsx +++ b/frontend/src/components/mapMenu/MapMenu.tsx @@ -21,12 +21,13 @@ const MapMenu: React.FC = observer(() => { const navigate = useNavigate() const [user, setUser] = useState() - const [formattedDate, setFormattedDate] = useState("") + const [formattedDate, setFormattedDate] = useState("") + const [isLoading, setIsLoading] = useState(true) useEffect(() => { axios.get("http://localhost:8000/users/").then((response) => { response.data.map((user: IUserType) => { - if (user.username === authStore.userLogin) { + if (user.email === authStore.nickname) { setUser(user) } }) @@ -36,6 +37,7 @@ const MapMenu: React.FC = observer(() => { const date = new Date(Date.parse(user!.registered_at)) setFormattedDate(`${date.getDay()}.${date.getMonth()}.${date.getUTCFullYear()}`) } + setIsLoading(false) }) }, []) @@ -52,20 +54,22 @@ const MapMenu: React.FC = observer(() => { return (
- - { - user?.is_superuser - ? - : + {isLoading + ? + : ( + user?.is_superuser + ? + : + ) }
); diff --git a/frontend/src/components/mapMenu/SuperUserMap/superUserControlPanel/CreateUnit.tsx b/frontend/src/components/mapMenu/SuperUserMap/superUserControlPanel/CreateUnit.tsx index 515552b..b0cf684 100644 --- a/frontend/src/components/mapMenu/SuperUserMap/superUserControlPanel/CreateUnit.tsx +++ b/frontend/src/components/mapMenu/SuperUserMap/superUserControlPanel/CreateUnit.tsx @@ -30,7 +30,7 @@ const CreateUnit: React.FC = currentUnitId, availableUnits }) => { - let btnText = "" + let btnText: string if (unitName === "map") { btnText = "Удалить выбранную карту" @@ -48,6 +48,7 @@ const CreateUnit: React.FC =
) + case ("task"): + return ( +
+ {unit.title} + {unit.content} +
+ ) default: return (
Блок пуст
) } } function renderTasks(menuItems?: IMenuItemType[], theoryUnits?: ITheoryUnitType[], taskUnits?: ITaskType[]) { - console.log(levelStore.chosenTaskIndex) if (menuItems && levelStore.chosenTaskIndex <= menuItems[0].length) return renderChosenTask(theoryUnits[levelStore.chosenTaskIndex - 1], "theory") if (menuItems && levelStore.chosenTaskIndex <= menuItems[0].length + menuItems[1].length) return renderChosenTask(taskUnits[levelStore.chosenTaskIndex - menuItems[0].length - 1], "test") - } return ( diff --git a/frontend/src/store/authStore.ts b/frontend/src/store/authStore.ts index 9e0cf11..9baf8ee 100644 --- a/frontend/src/store/authStore.ts +++ b/frontend/src/store/authStore.ts @@ -1,16 +1,18 @@ import {makeAutoObservable} from "mobx"; import axios from "axios"; - class AuthStore { isUserAuthorized: boolean = false - - // userRole: string | null = null + nickname: string | null = null constructor() { makeAutoObservable(this) } + setUser(nickname: string) { + this.nickname = nickname + } + async signIn(login: string, password: string) { await axios.post("http://localhost:8000/auth/login", { username: login, diff --git a/frontend/src/types/UserType.ts b/frontend/src/types/UserType.ts index 904310a..b01f4cd 100644 --- a/frontend/src/types/UserType.ts +++ b/frontend/src/types/UserType.ts @@ -1,6 +1,7 @@ export interface IUserType { username: string, email: string, + id: string, registered_at: string, is_superuser: boolean }