Skip to content

Commit

Permalink
добавляет возможность супер пользователю создать карту
Browse files Browse the repository at this point in the history
  • Loading branch information
semant1cs committed Nov 27, 2023
1 parent 755ae1f commit ae87cba
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/mapMenu/MapMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const MapMenu: React.FC = observer(() => {

return (
<div>
{user?.is_superuser
{!user?.is_superuser
? <SuperUserMap allUsers={superUserStore.allUsers}/>
: <EmployeeMap user={user} formattedDate={formattedDate}/>
}
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/components/mapMenu/SuperUserMap.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import React from 'react';
import {IUserType} from "../../types/UserType.ts";
import CustomButton from "../../UIComponents/customButton/CustomButton.tsx";
import mapMenuStore from "../../store/mapMenuStore.ts";
import CustomInput from "../../UIComponents/customInput/CustomInput.tsx";
import {observer} from "mobx-react-lite";

interface ISuperUserMap {
allUsers: IUserType[]
}

const SuperUserMap: React.FC<ISuperUserMap> = ({allUsers}) => {
const SuperUserMap: React.FC<ISuperUserMap> = observer(({allUsers}) => {
return (
<div>
<select>
{allUsers?.map((user) =>
<option key={user.username} value={user.username}>{user.username}</option>)}
</select>
<CustomInput type="text" value={mapMenuStore.newNameMap}
handleOnChange={(e) => mapMenuStore.changeNewNameMap(e)}/>
<CustomButton text="Создать новую карту"
handleOnClick={() => mapMenuStore.createMap(mapMenuStore.newNameMap)}/>

</div>
);
};
});

export default SuperUserMap;
17 changes: 13 additions & 4 deletions frontend/src/store/mapMenuStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {IFetchLevelType} from "../types/LevelType/FetchLevelType.ts";
import moduleMenuStore from "./moduleMenuStore.ts";

class MapMenuStore {
// Доступное всем пользователям
mapMenu: IMapType | null = null
availableMaps: IMapType[] = []

Expand All @@ -14,6 +15,9 @@ class MapMenuStore {

availableLevels: ILevelType[] = []

// Для суперпользователя
newNameMap: string = ""

constructor() {
makeAutoObservable(this)
}
Expand All @@ -22,10 +26,6 @@ class MapMenuStore {
await axios.get("http://localhost:8000/maps/").then((response) => this.availableMaps = response.data)
}

createMap(mapName: string) {
axios.post("http://localhost:8000/maps/", {title: mapName})
}

async fetchMapById(id: string) {
await axios.get("http://localhost:8000/maps/" + id).then((response) => {
this.mapMenu = response?.data
Expand Down Expand Up @@ -107,6 +107,15 @@ class MapMenuStore {
// ]
// })
// }

// Для суперпользователя

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

export default new MapMenuStore()
2 changes: 0 additions & 2 deletions frontend/src/store/superUserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class SuperUserStore {
setAllUsers(fetchedUsers: IUserType[]) {
this.allUsers = fetchedUsers
}


}

export default new SuperUserStore()
2 changes: 1 addition & 1 deletion frontend/src/types/MenuItemType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ITheoryUnitType} from "./TheoryUnitType.ts";
import {ITaskType} from "./TaskType.ts";

export interface IMenuItemType, {
export interface IMenuItemType {
length: number,
type: string,
item: ITheoryUnitType & ITaskType
Expand Down

0 comments on commit ae87cba

Please sign in to comment.