Clean role-selector
This commit is contained in:
parent
2a8dfd0cbf
commit
7dd067505e
|
@ -3,16 +3,11 @@ import { BrowserRouter as Router, Link, Route, Routes, useParams } from "react-r
|
||||||
import Appbar from "./components/AsuraBar";
|
import Appbar from "./components/AsuraBar";
|
||||||
import ErrorSnackbar from "./components/ErrorSnackbar";
|
import ErrorSnackbar from "./components/ErrorSnackbar";
|
||||||
import LoginPage from "./LoginPage";
|
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 AddCircleIcon from '@mui/icons-material/AddCircle';
|
||||||
import DeleteIcon from '@mui/icons-material/Delete';
|
import DeleteIcon from '@mui/icons-material/Delete';
|
||||||
import EditIcon from '@mui/icons-material/Edit';
|
import EditIcon from '@mui/icons-material/Edit';
|
||||||
|
|
||||||
function showError(error) {
|
|
||||||
alert("Something went wrong. \n" + error);
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
function AdminCreator(props){
|
function AdminCreator(props){
|
||||||
function postCreate(){
|
function postCreate(){
|
||||||
let adminEmail = document.getElementById("adminEmailInput").value;
|
let adminEmail = document.getElementById("adminEmailInput").value;
|
||||||
|
@ -21,7 +16,6 @@ function AdminCreator(props){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append("email", adminEmail)
|
formData.append("email", adminEmail)
|
||||||
let body = new URLSearchParams(formData)
|
let body = new URLSearchParams(formData)
|
||||||
|
@ -75,7 +69,8 @@ function UserList(props){
|
||||||
}
|
}
|
||||||
|
|
||||||
let updateRank = (asuraId) => event => {
|
let updateRank = (asuraId) => event => {
|
||||||
let isManager = event.target.value == "manager";
|
event.preventDefault();
|
||||||
|
let isManager = event.target.value === "manager";
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append("isManager", isManager);
|
formData.append("isManager", isManager);
|
||||||
let body = new URLSearchParams(formData);
|
let body = new URLSearchParams(formData);
|
||||||
|
@ -109,7 +104,7 @@ function UserList(props){
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{props.users.map((user) => (
|
{props.users.map((user) => (
|
||||||
<TableRow key={user.id}>
|
<TableRow key={user.asuraId}>
|
||||||
<TableCell component="th" scope="row">
|
<TableCell component="th" scope="row">
|
||||||
<b>
|
<b>
|
||||||
{user.name}
|
{user.name}
|
||||||
|
@ -118,10 +113,12 @@ function UserList(props){
|
||||||
<TableCell>{user.email}</TableCell>
|
<TableCell>{user.email}</TableCell>
|
||||||
{/* TODO Drop down menu for selecting rank */}
|
{/* TODO Drop down menu for selecting rank */}
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<select onChange={updateRank(user.asuraId)} value={user.isManager ? "manager" : "admin"}>
|
<FormControl variant="standard">
|
||||||
<option value="manager">Manager</option>
|
<Select onChange={updateRank(user.asuraId)} value={user.isManager ? "manager" : "admin"} label="rank" labelId="rankSelect" id="rankSelect">
|
||||||
<option value="admin">Admin</option>
|
<MenuItem value={"manager"}>Manager</MenuItem>
|
||||||
</select>
|
<MenuItem value={"admin"}>Admin</MenuItem>
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
{/* <TableCell align="right">{team.members}</TableCell> */}
|
{/* <TableCell align="right">{team.members}</TableCell> */}
|
||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
|
@ -137,7 +134,19 @@ function UserList(props){
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let showError = (message) => {};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function Users(props) {
|
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([]);
|
const [users, setUsers] = React.useState([]);
|
||||||
|
|
||||||
function getUsers() {
|
function getUsers() {
|
||||||
|
@ -146,6 +155,7 @@ export default function Users(props) {
|
||||||
.then((data) =>{
|
.then((data) =>{
|
||||||
if(data.status !== "OK") {
|
if(data.status !== "OK") {
|
||||||
showError(data.data);
|
showError(data.data);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
setUsers(data.data);
|
setUsers(data.data);
|
||||||
})
|
})
|
||||||
|
@ -155,24 +165,27 @@ export default function Users(props) {
|
||||||
getUsers()
|
getUsers()
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!props.user.isLoggedIn) { return <LoginPage user={props.user} />; }
|
// if (!props.user.isLoggedIn) { return <LoginPage user={props.user} />; }
|
||||||
if (!props.user.isManager) {
|
// if (!props.user.isManager) {
|
||||||
return (<>
|
// return (<>
|
||||||
<Appbar user={props.user} pageTitle="Admins" />
|
// <Appbar user={props.user} pageTitle="Admins" />
|
||||||
<Paper sx={{minHeight: "30vh", width:"90vw", margin:"10px auto", padding: "25px"}} component={Stack} direction="column" justifycontent="center">
|
// <Paper sx={{minHeight: "30vh", width:"90vw", margin:"10px auto", padding: "25px"}} component={Stack} direction="column" justifycontent="center">
|
||||||
<div align="center">
|
// <div align="center">
|
||||||
<Typography variant="h4">You do not have permission to view this page. If you believe this is incorrect, please contact a manager.</Typography>
|
// <Typography variant="h4">You do not have permission to view this page. If you believe this is incorrect, please contact a manager.</Typography>
|
||||||
</div>
|
// </div>
|
||||||
</Paper>
|
// </Paper>
|
||||||
</>);
|
// </>);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Appbar user={props.user} pageTitle="Admins" />
|
<Appbar user={props.user} pageTitle="Admins" />
|
||||||
<div className="admins">
|
<div className="admins">
|
||||||
<AdminCreator onAdminCreated={getUsers} onUserUpdated={getUsers} />
|
<AdminCreator onAdminCreated={getUsers} onUserUpdated={getUsers} />
|
||||||
<UserList users={users}/>
|
<UserList users={users} setUsers={setUsers} onUserUpdated={getUsers} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<ErrorSnackbar message={errorMessage} open={openError} setOpen={setOpenError} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -16,6 +16,7 @@ export default function showError(props) {
|
||||||
|
|
||||||
props.setOpen(false);
|
props.setOpen(false);
|
||||||
};
|
};
|
||||||
|
console.log(props.message);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={2} sx={{ width: '100%' }}>
|
<Stack spacing={2} sx={{ width: '100%' }}>
|
||||||
|
|
Loading…
Reference in New Issue