Continued session, admin page

This commit is contained in:
Felix Albrigtsen 2022-04-23 14:37:18 +02:00
parent 176c0b5ad4
commit 5c4130d3e4
5 changed files with 48 additions and 29 deletions

View File

@ -26,7 +26,7 @@ function AdminCreator(props){
formData.append("email", adminEmail) formData.append("email", adminEmail)
let body = new URLSearchParams(formData) let body = new URLSearchParams(formData)
fetch(process.env.REACT_APP_API_URL + `/admins/create`, { fetch(process.env.REACT_APP_API_URL + `/users/createBlank`, {
method: "POST", method: "POST",
body: body body: body
}) })
@ -45,7 +45,7 @@ function AdminCreator(props){
return ( return (
<Paper sx={{width: "90vw", margin: "10px auto", padding: "15px"}} component={Stack} direction="column"> <Paper sx={{width: "90vw", margin: "10px auto", padding: "15px"}} component={Stack} direction="column">
<div align="center"> <div align="center">
<TextField id="adminEmailInput" sx={{ width: "70%" }} label="Admin Email" variant="outlined" /> <TextField id="adminEmailInput" sx={{ width: "70%" }} label="Admin Email" variant="outlined" type="email" />
{/* <Button variant="contained" color="primary" onClick={postCreate}>Create Team</Button> */} {/* <Button variant="contained" color="primary" onClick={postCreate}>Create Team</Button> */}
<Button variant="contained" color="success" onClick={postCreate} sx={{width: "20%", marginLeft: "5px"}}> <Button variant="contained" color="success" onClick={postCreate} sx={{width: "20%", marginLeft: "5px"}}>
<Box sx={{padding: "10px"}}> <Box sx={{padding: "10px"}}>
@ -58,16 +58,16 @@ function AdminCreator(props){
) )
} }
function AdminList(props){ function UserList(props){
const deleteAdmin = adminId => { const deleteUsers = userId => {
fetch(process.env.REACT_APP_API_URL + `/users/${adminId}`, {method: "DELETE"}) fetch(process.env.REACT_APP_API_URL + `/users/${userId}`, {method: "DELETE"})
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
if(data.status !== "OK"){ if(data.status !== "OK"){
showError(data.data); showError(data.data);
return; return;
} }
props.setAdmins(props.admins.filter(admin => admin.id !== adminId)); props.setUsers(props.users.filter(user => user.id !== userId));
}) })
.catch(error => showError(error)); .catch(error => showError(error));
} }
@ -79,20 +79,27 @@ function AdminList(props){
<Table aria-label="simple table"> <Table aria-label="simple table">
<TableHead> <TableHead>
<TableRow> <TableRow>
<TableCell>Admin</TableCell> <TableCell>Name</TableCell>
<TableCell>Email</TableCell>
<TableCell>Rank</TableCell>
<TableCell align="center">Actions</TableCell> <TableCell align="center">Actions</TableCell>
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{props.admins.map((admin) => ( {props.users.map((user) => (
<TableRow key={admin.id}> <TableRow key={user.id}>
<TableCell component="th" scope="row"> <b> <TableCell component="th" scope="row">
{admin.name} <b>
</b></TableCell> {user.name}
</b>
</TableCell>
<TableCell>{user.email}</TableCell>
{/* TODO Drop down menu for selecting rank */}
<TableCell>{'user.rank'}</TableCell>
{/* <TableCell align="right">{team.members}</TableCell> */} {/* <TableCell align="right">{team.members}</TableCell> */}
<TableCell align="center"> <TableCell align="center">
{/* <Button variant="contained" sx={{margin: "auto 5px"}} color="primary" onClick={() => props.setSelectedTeamId(team.id)} endIcon={<EditIcon />}>Edit</Button> */} {/* <Button variant="contained" sx={{margin: "auto 5px"}} color="primary" onClick={() => props.setSelectedTeamId(team.id)} endIcon={<EditIcon />}>Edit</Button> */}
<Button variant="contained" sx={{margin: "auto 5px"}} color="error" onClick={() => {deleteAdmin(admin.id)}} endIcon={<DeleteIcon />}>Delete</Button> <Button variant="contained" sx={{margin: "auto 5px"}} color="error" onClick={() => {deleteUsers(user.id)}} endIcon={<DeleteIcon />}>Delete</Button>
</TableCell> </TableCell>
</TableRow> </TableRow>
))} ))}
@ -103,23 +110,23 @@ function AdminList(props){
) )
} }
export default function Admins(props) { export default function Users(props) {
const [admins, setAdmins] = React.useState([]); const [users, setUsers] = React.useState([]);
const { adminId } = useParams(); const { userId } = useParams();
function getAdmins() { function getUsers() {
fetch(process.env.REACT_APP_API_URL + `/users/getUsers`) fetch(process.env.REACT_APP_API_URL + `/users/getUsers`)
.then((res) => res.json()) .then((res) => res.json())
.then((data) =>{ .then((data) =>{
if(data.status !== "OK") { if(data.status !== "OK") {
showError(data.data); showError(data.data);
} }
setAdmins(data.data); setUsers(data.data);
}) })
.catch((err) => showError(err)); .catch((err) => showError(err));
} }
React.useEffect(() => { React.useEffect(() => {
getAdmins() getUsers()
}, []); }, []);
return ( return (
@ -127,7 +134,7 @@ export default function Admins(props) {
<Appbar pageTitle="Admins" /> <Appbar pageTitle="Admins" />
<div className="admins"> <div className="admins">
<AdminCreator /> <AdminCreator />
<AdminList /> <UserList users={users}/>
</div> </div>
</> </>
); );

View File

@ -8,15 +8,25 @@ export default function ProfilePage(props) {
if (!props.login) { if (!props.login) {
return <h1>Something went very wrong</h1> return <h1>Something went very wrong</h1>
} }
console.log(props.login.user);
let user = props.login.user;
console.log(props.login);
return (<> return (<>
<AppBar pageTitle="Profile" /> <AppBar pageTitle="Profile" />
<Container sx={{minHeight: "30vh", width: "90vw", padding: "20px 20px"}} component={Container} direction="column" align="center"> <Container sx={{minHeight: "30vh", width: "90vw", padding: "20px 20px"}} component={Container} direction="column" align="center">
{props.login.isLoggedIn ? <> {props.login.isLoggedIn() ? <>
<Box sx={{ padding: "20px", width: "90vw", height: "30vh", display: "flex", flexDirection: "column", justifyContent: "space-between", alignItems: "center", alignContent: "center", flexGrow: 1}}> <Paper sx={{minHeight: "30vh", width: "90vw", margin: "10px auto"}} component={Stack} direction="column" justifyContent="center">
<div align="center">
</Box> <h2><b>Your profile</b></h2>
</>:<> <Box>
<h3><b>Name: </b> {user.name}</h3>
<h3><b>Email: </b> {user.email}</h3>
<h3><b>Role: </b> {user.isManager() ? "Manager" : "Administrator"}</h3>
<h3><b>Picture: </b> <img src={user.imgURL} alt="Your profile"></img></h3>
</Box>
</div>
</Paper>
</> : <>
<Box sx={{ padding: "20px", width: "90vw", height: "30vh", display: "flex", flexDirection: "column", justifyContent: "space-between", alignItems: "center", alignContent: "center", flexGrow: 1}}> <Box sx={{ padding: "20px", width: "90vw", height: "30vh", display: "flex", flexDirection: "column", justifyContent: "space-between", alignItems: "center", alignContent: "center", flexGrow: 1}}>
You are not logged in. You are not logged in.
</Box> </Box>

View File

@ -55,7 +55,8 @@ function shorten(description, maxLength) {
<Typography variant="h5" color="text.primary" gutterBottom> Players: {props.tournament.teamCount} / {props.tournament.teamLimit} </Typography> <Typography variant="h5" color="text.primary" gutterBottom> Players: {props.tournament.teamCount} / {props.tournament.teamLimit} </Typography>
<Description /> <Description />
<Typography variant="body" color="text.primary"><EmojiEventsIcon alt="A trohpy" color="gold" align="vertical-center"/> Prize: {props.tournament.prize} </Typography>
<Box sx={{flexGrow: 1, marginTop: "20px"}}> <Box sx={{flexGrow: 1, marginTop: "20px"}}>
<Grid container spacing={4} justifyContent="center" wrap="wrap"> <Grid container spacing={4} justifyContent="center" wrap="wrap">
<Grid item > <Grid item >
@ -67,7 +68,6 @@ function shorten(description, maxLength) {
</Grid> </Grid>
</Grid> </Grid>
</Box> </Box>
<Typography variant="body" color="text.primary"><EmojiEventsIcon alt="A trohpy" color="gold" align="vertical-center"/> Prize: {props.tournament.prize} </Typography>
</CardContent> </CardContent>
</Card> </Card>
</Paper> </Paper>

View File

@ -4,6 +4,7 @@ import { AppBar, Typography, Toolbar, CssBaseline, Box, Button, IconButton, Grid
import MenuIcon from '@mui/icons-material/Menu'; import MenuIcon from '@mui/icons-material/Menu';
import AccountCircleIcon from '@mui/icons-material/AccountCircle'; import AccountCircleIcon from '@mui/icons-material/AccountCircle';
import HistoryIcon from '@mui/icons-material/History'; import HistoryIcon from '@mui/icons-material/History';
import EditIcon from '@mui/icons-material/Edit';
import LogoutIcon from '@mui/icons-material/Logout'; import LogoutIcon from '@mui/icons-material/Logout';
import LoginIcon from '@mui/icons-material/Login'; import LoginIcon from '@mui/icons-material/Login';
import logo from "./../Asura2222.png"; import logo from "./../Asura2222.png";
@ -35,6 +36,7 @@ function LoggedInMenu() {
<Link to="/" style={{color:"black"}}><MenuItem onClick={handleClose}><Button endIcon={<AccountCircleIcon />}>Profile</Button></MenuItem></Link> <Link to="/" style={{color:"black"}}><MenuItem onClick={handleClose}><Button endIcon={<AccountCircleIcon />}>Profile</Button></MenuItem></Link>
<Link to="/history" style={{color:"black"}}><MenuItem onClick={handleClose}><Button endIcon={<HistoryIcon />}>History</Button></MenuItem></Link> <Link to="/history" style={{color:"black"}}><MenuItem onClick={handleClose}><Button endIcon={<HistoryIcon />}>History</Button></MenuItem></Link>
<Link to="/" style={{color:"black"}}><MenuItem onClick={logout}><Button endIcon={<LogoutIcon />} >Logout</Button></MenuItem></Link> <Link to="/" style={{color:"black"}}><MenuItem onClick={logout}><Button endIcon={<LogoutIcon />} >Logout</Button></MenuItem></Link>
<Link to="/admins" style={{color:"black"}}><MenuItem onClick={handleClose}><Button endIcon={<EditIcon />} >Admins</Button></MenuItem></Link>
</Menu> </Menu>
</> </>
); );

View File

@ -10,7 +10,7 @@
display:flex; display:flex;
flex-direction:column; flex-direction:column;
justify-content:center; justify-content:center;
width:20%; width:20vw;
list-style:none; list-style:none;
padding:0; padding:0;
font-size: 1.5rem; font-size: 1.5rem;