forked from DeerCo/IBS
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from DakshChan/feature/IBS-13
IBS-13
- Loading branch information
Showing
3 changed files
with
289 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 111 additions & 24 deletions
135
frontend/src/components/Page/Admin/AdminImpersonate.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,120 @@ | ||
import {TextField} from "@mui/material"; | ||
import {useState} from "react"; | ||
import {useNavigate, useParams} from "react-router-dom"; | ||
import { useState } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import NavBar from "../../Module/Navigation/NavBar"; | ||
import CustomFormLabel from '../../FlexyMainComponents/forms/custom-elements/CustomFormLabel'; | ||
import FeatherIcon from 'feather-icons-react'; | ||
import { | ||
Card, | ||
CardContent, | ||
Divider, | ||
Box, | ||
Typography, | ||
Button, | ||
FormControl, | ||
InputAdornment, | ||
OutlinedInput, | ||
Grid, | ||
} from '@mui/material'; | ||
import AdminApi from "../../../api/admin_api"; | ||
|
||
export default function AdminImpersonate() { | ||
const [username, setUsername] = useState(""); | ||
const navigate = useNavigate(); | ||
|
||
|
||
return ( | ||
<form onSubmit={(e) => { | ||
AdminApi.impersonate(username).then( | ||
(response) => { | ||
console.log(response); | ||
sessionStorage.setItem("origusername", sessionStorage.getItem("username")); | ||
sessionStorage.setItem("origroles", sessionStorage.getItem("roles")); | ||
sessionStorage.setItem("origtoken", sessionStorage.getItem("token")); | ||
sessionStorage.setItem("username", username); | ||
sessionStorage.setItem("roles", JSON.stringify(response.data.roles)); | ||
sessionStorage.setItem("token", response.data.token); | ||
navigate("/home"); | ||
navigate(0) | ||
} | ||
) | ||
e.preventDefault(); | ||
}}> | ||
<p>Admin Impersonate</p> | ||
<TextField placeholder={"Enter username"} value={username} onChange={(e) => setUsername(e.target.value)}/> | ||
<button>Impersonate</button> | ||
</form> | ||
<Grid container | ||
direction="column" | ||
height="100%" | ||
wrap="nowrap"> | ||
<NavBar item page="Impersonate" /> | ||
<Grid item container | ||
spacing={2} | ||
direction="row" | ||
justifyContent="center" | ||
alignContent="center" | ||
justify="center" | ||
flex="1 1 auto"> | ||
<Grid item> | ||
<Card | ||
sx={{ | ||
p: 0, | ||
}} | ||
> | ||
<Box | ||
sx={{ | ||
padding: '15px 30px', | ||
}} | ||
display="flex" | ||
alignItems="center" | ||
> | ||
<Box flexGrow={1}> | ||
<Typography fontWeight="500" variant="h4"> | ||
Student View | ||
</Typography> | ||
</Box> | ||
</Box> | ||
<Divider /> | ||
<CardContent | ||
sx={{ | ||
padding: '30px', | ||
}} | ||
> | ||
<form onSubmit={(e) => { | ||
AdminApi.impersonate(username).then( | ||
(response) => { | ||
console.log(response); | ||
sessionStorage.setItem("origusername", sessionStorage.getItem("username")); | ||
sessionStorage.setItem("origroles", sessionStorage.getItem("roles")); | ||
sessionStorage.setItem("origtoken", sessionStorage.getItem("token")); | ||
sessionStorage.setItem("username", username); | ||
sessionStorage.setItem("roles", JSON.stringify(response.data.roles)); | ||
sessionStorage.setItem("token", response.data.token); | ||
navigate("/home"); | ||
navigate(0) | ||
} | ||
) | ||
e.preventDefault(); | ||
}}> | ||
<FormControl> | ||
<CustomFormLabel | ||
sx={{ | ||
mt: 0, | ||
}} | ||
htmlFor="username-text" | ||
> | ||
Username | ||
</CustomFormLabel> | ||
<OutlinedInput | ||
startAdornment={ | ||
<InputAdornment position="start"> | ||
<FeatherIcon icon="user" width="20" /> | ||
</InputAdornment> | ||
} | ||
placeholder={"Enter username"} | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
id="username-text" | ||
size="small" | ||
/> | ||
</FormControl> | ||
|
||
<Box pt={3} alignContent='center'> | ||
<Button | ||
type="submit" | ||
color="primary" | ||
variant="contained" | ||
sx={{ | ||
mr: 1, | ||
}} | ||
> | ||
View | ||
</Button> | ||
</Box> | ||
</form> | ||
</CardContent> | ||
</Card> | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
) | ||
} |
Oops, something went wrong.