From 7dd067505e718762af766122d1a9e8c27de98021 Mon Sep 17 00:00:00 2001 From: Felix Albrigtsen Date: Sun, 24 Apr 2022 14:38:47 +0200 Subject: [PATCH] Clean role-selector --- src/client/src/AdminsOverview.js | 63 +++++++++++++--------- src/client/src/components/ErrorSnackbar.js | 1 + 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/client/src/AdminsOverview.js b/src/client/src/AdminsOverview.js index 132da10..59ec91b 100644 --- a/src/client/src/AdminsOverview.js +++ b/src/client/src/AdminsOverview.js @@ -3,16 +3,11 @@ import { BrowserRouter as Router, Link, Route, Routes, useParams } from "react-r import Appbar from "./components/AsuraBar"; import ErrorSnackbar from "./components/ErrorSnackbar"; import LoginPage from "./LoginPage"; -import {Button, Box, TextField, Stack, InputLabel, Paper, TableContainer, Table, TableBody, TableHead, TableCell, TableRow, Typography} from '@mui/material'; +import {Button, Box, TextField, Stack, InputLabel, Paper, TableContainer, Table, TableBody, TableHead, TableCell, TableRow, Typography, Select, MenuItem, FormControl} from '@mui/material'; import AddCircleIcon from '@mui/icons-material/AddCircle'; import DeleteIcon from '@mui/icons-material/Delete'; import EditIcon from '@mui/icons-material/Edit'; -function showError(error) { - alert("Something went wrong. \n" + error); - console.error(error); -} - function AdminCreator(props){ function postCreate(){ let adminEmail = document.getElementById("adminEmailInput").value; @@ -21,7 +16,6 @@ function AdminCreator(props){ return; } - let formData = new FormData(); formData.append("email", adminEmail) let body = new URLSearchParams(formData) @@ -75,7 +69,8 @@ function UserList(props){ } let updateRank = (asuraId) => event => { - let isManager = event.target.value == "manager"; + event.preventDefault(); + let isManager = event.target.value === "manager"; let formData = new FormData(); formData.append("isManager", isManager); let body = new URLSearchParams(formData); @@ -109,7 +104,7 @@ function UserList(props){ {props.users.map((user) => ( - + {user.name} @@ -118,10 +113,12 @@ function UserList(props){ {user.email} {/* TODO Drop down menu for selecting rank */} - + + + {/* {team.members} */} @@ -137,7 +134,19 @@ function UserList(props){ ) } +let showError = (message) => {}; + + + export default function Users(props) { + + const [openError, setOpenError] = React.useState(false); + const [errorMessage, setErrorMessage] = React.useState(""); + showError = (message) => { + setOpenError(false); + setErrorMessage(message); + setOpenError(true); + } const [users, setUsers] = React.useState([]); function getUsers() { @@ -146,6 +155,7 @@ export default function Users(props) { .then((data) =>{ if(data.status !== "OK") { showError(data.data); + return; } setUsers(data.data); }) @@ -155,24 +165,27 @@ export default function Users(props) { getUsers() }, []); - if (!props.user.isLoggedIn) { return ; } - if (!props.user.isManager) { - return (<> - - -
- You do not have permission to view this page. If you believe this is incorrect, please contact a manager. -
-
- ); - } + // if (!props.user.isLoggedIn) { return ; } + // if (!props.user.isManager) { + // return (<> + // + // + //
+ // You do not have permission to view this page. If you believe this is incorrect, please contact a manager. + //
+ //
+ // ); + // } + return ( <>
- +
+ + ); } \ No newline at end of file diff --git a/src/client/src/components/ErrorSnackbar.js b/src/client/src/components/ErrorSnackbar.js index 6c39763..ee2f324 100644 --- a/src/client/src/components/ErrorSnackbar.js +++ b/src/client/src/components/ErrorSnackbar.js @@ -16,6 +16,7 @@ export default function showError(props) { props.setOpen(false); }; + console.log(props.message); return (