adminFront/src/pages/dashboard/Content/Users.tsx

611 lines
19 KiB
TypeScript
Raw Normal View History

2022-09-08 17:21:17 +00:00
import * as React from "react";
2023-04-20 15:42:18 +00:00
import { useNavigate } from "react-router-dom";
2022-09-09 13:54:49 +00:00
import { Box, Typography, TextField, Button } from "@mui/material";
2022-09-26 12:35:56 +00:00
import Table from "@mui/material/Table";
import TableHead from "@mui/material/TableHead";
import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell";
import TableRow from "@mui/material/TableRow";
import Radio from "@mui/material/Radio";
import Skeleton from "@mui/material/Skeleton";
2023-04-20 15:42:18 +00:00
import Accordion from "@mui/material/Accordion";
import AccordionSummary from "@mui/material/AccordionSummary";
import AccordionDetails from "@mui/material/AccordionDetails";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import ClearIcon from "@mui/icons-material/Clear";
import { getRoles_mock, TMockData } from "../../../api/roles";
import type { UsersType } from "../../../api/roles";
2023-04-20 15:42:18 +00:00
import theme from "../../../theme";
import axios from "axios";
2023-05-05 19:05:09 +00:00
import {authStore} from "@stores/auth";
import ConditionalRender from "@root/pages/Setting/ConditionalRender";
2022-09-08 17:21:17 +00:00
2023-04-20 15:42:18 +00:00
const Users: React.FC = () => {
2023-05-05 19:05:09 +00:00
const { makeRequest } = authStore();
// makeRequest({
// url: "https://admin.pena.digital/strator/account",
// method: "get",
// bearer: true,
// contentType: true,
// })
const radioboxes = ["admin", "manager", "user"];
2022-09-26 12:35:56 +00:00
const [selectedValue, setSelectedValue] = React.useState("admin");
2022-09-09 13:54:49 +00:00
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSelectedValue(event.target.value);
if (selectedValue === "manager") {
}
2022-09-09 13:54:49 +00:00
};
2022-09-14 10:24:02 +00:00
const navigate = useNavigate();
2022-09-24 15:37:24 +00:00
const [data, setData] = React.useState<TMockData>([]);
2023-04-20 15:42:18 +00:00
2022-09-24 15:37:24 +00:00
const handleChangeData = () => {
2022-09-26 12:35:56 +00:00
getRoles_mock().then((mockdata) => {
2023-04-20 15:42:18 +00:00
setData(mockdata);
});
2022-09-24 15:37:24 +00:00
};
2022-09-27 20:42:56 +00:00
const [accordionHeader, setAccordionHeader] = React.useState<string>("none");
const [accordionState, setAccordionState] = React.useState<boolean>(true);
const [accordionText, setAccordionText] = React.useState<string>("");
2023-04-20 15:42:18 +00:00
const handleChangeAccordion = (text: string) => {
if (text == "") {
setAccordionState(true);
2022-09-27 20:42:56 +00:00
setAccordionHeader("none");
2023-04-20 15:42:18 +00:00
} else {
2022-09-27 20:42:56 +00:00
handleToggleAccordion();
2023-04-20 15:42:18 +00:00
setAccordionHeader("flex");
2022-09-27 20:42:56 +00:00
}
2023-04-20 15:42:18 +00:00
accordionState ? setAccordionText(text) : setAccordionText("");
};
2022-09-27 20:42:56 +00:00
const handleToggleAccordion = () => {
2023-04-20 15:42:18 +00:00
setAccordionState(!accordionState);
};
2022-09-27 20:42:56 +00:00
2022-09-26 12:35:56 +00:00
handleChangeData();
2023-04-20 15:42:18 +00:00
const [roles, setRoles] = React.useState<TMockData>([]);
const [users, setUsers] = React.useState<UsersType>();
const [manager, setManager] = React.useState<UsersType>();
2023-04-20 15:42:18 +00:00
React.useEffect(() => {
const axiosRoles = async () => {
const { data } = await axios({
2023-04-20 15:42:18 +00:00
method: "get",
url: "https://admin.pena.digital/strator/role/",
});
setRoles(data);
2023-04-20 15:42:18 +00:00
};
const gettingRegisteredUsers = async () => {
const { data } = await axios({
method: "get",
url: "https://hub.pena.digital/user/",
});
setUsers(data);
};
const gettingListManagers = async () => {
const { data } = await axios({
method: "get",
url: "https://admin.pena.digital/user/",
});
setManager(data);
};
gettingListManagers();
gettingRegisteredUsers();
axiosRoles();
2023-04-20 15:42:18 +00:00
}, []);
2022-09-08 17:21:17 +00:00
return (
<React.Fragment>
2023-04-20 15:42:18 +00:00
<Button
variant="text"
onClick={() => navigate("/modalAdmin")}
sx={{
width: "84%",
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
marginBottom: "35px",
border: "2px solid",
fontWeight: "normal",
borderColor: theme.palette.golden.main,
color: theme.palette.secondary.main,
"&:hover": {
backgroundColor: theme.palette.menu.main,
},
}}
>
ИНФОРМАЦИЯ О ПРОЕКТЕ
</Button>
2022-09-08 17:21:17 +00:00
2023-04-20 15:42:18 +00:00
<Accordion
sx={{
width: "84%",
2023-04-20 15:42:18 +00:00
backgroundColor: theme.palette.content.main,
}}
expanded={accordionState}
>
<AccordionSummary
sx={{ display: accordionHeader }}
expandIcon={
<ExpandMoreIcon
sx={{
color: theme.palette.secondary.main,
}}
onClick={() => handleToggleAccordion()}
/>
}
aria-controls="panel1a-content"
id="panel1a-header"
>
<Typography
sx={{
width: "100%",
color: theme.palette.secondary.main,
}}
2022-09-27 20:42:56 +00:00
>
2023-04-20 15:42:18 +00:00
{accordionText}
</Typography>
2022-09-27 20:42:56 +00:00
2023-04-20 15:42:18 +00:00
<Box
sx={{
2022-09-27 20:42:56 +00:00
display: "flex",
2023-04-20 15:42:18 +00:00
alignItems: "right",
}}
>
<ClearIcon sx={{ color: theme.palette.secondary.main }} onClick={() => handleChangeAccordion("")} />
</Box>
</AccordionSummary>
<AccordionDetails>
<Table
sx={{
width: "100%",
border: "2px solid",
borderColor: theme.palette.secondary.main,
}}
aria-label="simple table"
>
<TableHead>
<TableRow
sx={{
borderBottom: "2px solid",
borderColor: theme.palette.grayLight.main,
height: "100px",
}}
>
<TableCell>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
Имя
</Typography>
</TableCell>
<TableCell>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
Описание
</Typography>
</TableCell>
<TableCell>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
Отобразить
</Typography>
</TableCell>
</TableRow>
</TableHead>
2022-09-09 13:54:49 +00:00
2023-04-20 15:42:18 +00:00
<TableBody>
{data.length ? (
data.map(function (item, index) {
return (
<TableRow
sx={{
borderTop: "2px solid",
borderColor: theme.palette.grayLight.main,
height: "100px",
cursor: "pointer",
}}
key={item.key}
onClick={() => handleChangeAccordion(item.desc)}
>
2022-09-26 12:35:56 +00:00
<TableCell>
2023-04-20 15:42:18 +00:00
<Typography
sx={{
color: theme.palette.secondary.main,
}}
>
{item.name}
2022-09-26 12:35:56 +00:00
</Typography>
</TableCell>
<TableCell>
2023-04-20 15:42:18 +00:00
<Typography
sx={{
color: theme.palette.secondary.main,
}}
>
{item.desc}
2022-09-26 12:35:56 +00:00
</Typography>
</TableCell>
<TableCell>
2023-04-20 15:42:18 +00:00
<Radio
checked={selectedValue === radioboxes[index]}
2022-09-26 12:35:56 +00:00
onChange={handleChange}
2023-04-20 15:42:18 +00:00
value={radioboxes[index]}
2022-09-26 12:35:56 +00:00
sx={{
2023-04-20 15:42:18 +00:00
"&, &.Mui-checked": {
color: theme.palette.secondary.main,
},
}}
/>
2022-09-26 12:35:56 +00:00
</TableCell>
</TableRow>
);
})
2023-04-20 15:42:18 +00:00
) : (
<TableRow
sx={{
borderTop: "2px solid",
borderColor: theme.palette.grayLight.main,
height: "100px",
}}
>
2022-09-27 20:42:56 +00:00
<TableCell colSpan={3}>
2023-04-20 15:42:18 +00:00
<Skeleton
variant="rectangular"
2022-09-27 20:42:56 +00:00
sx={{
width: "100%",
minWidth: "100%",
minHeight: "200px",
marginTop: "15px",
2023-04-20 15:42:18 +00:00
marginBottom: "15px",
2022-09-27 20:42:56 +00:00
}}
/>
</TableCell>
</TableRow>
2023-04-20 15:42:18 +00:00
)}
</TableBody>
</Table>
2022-09-27 20:42:56 +00:00
</AccordionDetails>
</Accordion>
2023-04-20 15:42:18 +00:00
<Box
sx={{
width: "90%",
marginTop: "35px",
}}
>
2022-09-09 13:54:49 +00:00
<Box sx={{ display: "flex" }}>
<TextField
2023-04-20 15:42:18 +00:00
id="standard-basic"
label="id"
variant="filled"
color="secondary"
sx={{
width: "80%",
2022-09-09 13:54:49 +00:00
}}
InputProps={{
style: {
backgroundColor: theme.palette.content.main,
color: theme.palette.secondary.main,
borderBottom: "1px solid",
borderColor: theme.palette.grayLight.main,
2023-04-20 15:42:18 +00:00
},
}}
2022-09-09 13:54:49 +00:00
InputLabelProps={{
style: {
2023-04-20 15:42:18 +00:00
color: theme.palette.secondary.main,
},
}}
2022-09-09 13:54:49 +00:00
/>
<Box
2022-09-09 13:54:49 +00:00
sx={{
2023-04-20 15:42:18 +00:00
display: "flex",
justifyContent: "center",
maxWidth: "317px",
width: "100%",
}}
>
<Button
2023-04-20 15:42:18 +00:00
variant="text"
sx={{
backgroundColor: theme.palette.content.main,
color: theme.palette.secondary.main,
// width: "20%",
"&:hover": {
2023-04-20 15:42:18 +00:00
backgroundColor: theme.palette.content.main,
},
}}
>
НАЙТИ
</Button>
</Box>
2022-09-09 13:54:49 +00:00
</Box>
<Box sx={{ display: "flex" }}>
<TextField
2023-04-20 15:42:18 +00:00
id="standard-basic"
label="mail"
variant="filled"
color="secondary"
sx={{
width: "80%",
2022-09-09 13:54:49 +00:00
}}
InputProps={{
style: {
backgroundColor: theme.palette.content.main,
color: theme.palette.secondary.main,
borderBottom: "1px solid",
borderColor: theme.palette.grayLight.main,
2023-04-20 15:42:18 +00:00
},
}}
2022-09-09 13:54:49 +00:00
InputLabelProps={{
style: {
2023-04-20 15:42:18 +00:00
color: theme.palette.secondary.main,
},
}}
2022-09-09 13:54:49 +00:00
/>
<Box
2023-04-20 15:42:18 +00:00
sx={{
display: "flex",
justifyContent: "center",
maxWidth: "317px",
width: "100%",
}}
>
<Button
2023-04-20 15:42:18 +00:00
variant="text"
sx={{
backgroundColor: theme.palette.content.main,
color: theme.palette.secondary.main,
width: "20%",
"&:hover": {
2023-04-20 15:42:18 +00:00
backgroundColor: theme.palette.content.main,
},
}}
>
СБРОСИТЬ
</Button>
</Box>
2022-09-09 13:54:49 +00:00
</Box>
</Box>
2023-04-20 15:42:18 +00:00
<Table
sx={{
width: "90%",
border: "2px solid",
borderColor: theme.palette.grayLight.main,
marginTop: "35px",
}}
aria-label="simple table"
>
<TableHead>
2023-04-20 15:42:18 +00:00
<TableRow
sx={{
borderBottom: "2px solid",
borderColor: theme.palette.grayLight.main,
height: "100px",
}}
>
<TableCell sx={{ textAlign: "center" }}>
2023-04-20 15:42:18 +00:00
<Typography
variant="h4"
sx={{
2023-04-20 15:42:18 +00:00
color: theme.palette.secondary.main,
}}
>
login
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
2023-04-20 15:42:18 +00:00
<Typography
variant="h4"
2023-04-20 15:42:18 +00:00
sx={{
color: theme.palette.secondary.main,
}}
>
email
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
2023-04-20 15:42:18 +00:00
<Typography
variant="h4"
2023-04-20 15:42:18 +00:00
sx={{
color: theme.palette.secondary.main,
}}
>
phoneNumber
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
isDeleted
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
2023-04-20 15:42:18 +00:00
<Typography
variant="h4"
2023-04-20 15:42:18 +00:00
sx={{
color: theme.palette.secondary.main,
}}
>
createdAt
</Typography>
</TableCell>
</TableRow>
</TableHead>
<TableBody>
<ConditionalRender
isLoading={false}
role={selectedValue}
childrenManager={
<>
{manager &&
manager.map(({ login, email, phoneNumber, isDeleted, createdAt }) => (
<TableRow
key={createdAt}
sx={{
borderBottom: "2px solid",
borderColor: theme.palette.grayLight.main,
height: "100px",
}}
>
<TableCell sx={{ textAlign: "center" }}>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
{login}
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
{email}
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
{phoneNumber}
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
{isDeleted ? "true" : "false"}
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
{createdAt}
</Typography>
</TableCell>
</TableRow>
))}
</>
}
childrenUser={
<>
{users &&
users.map(({ login, email, phoneNumber, isDeleted, createdAt }) => (
<TableRow
key={createdAt}
sx={{
borderBottom: "2px solid",
borderColor: theme.palette.grayLight.main,
height: "100px",
}}
>
<TableCell sx={{ textAlign: "center" }}>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
{login}
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
{email}
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
{phoneNumber}
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
{isDeleted ? "true" : "false"}
</Typography>
</TableCell>
<TableCell sx={{ textAlign: "center" }}>
<Typography
variant="h4"
sx={{
color: theme.palette.secondary.main,
}}
>
{createdAt}
</Typography>
</TableCell>
</TableRow>
))}
</>
}
/>
</TableBody>
</Table>
2022-09-08 17:21:17 +00:00
</React.Fragment>
);
2023-04-20 15:42:18 +00:00
};
2022-09-08 17:21:17 +00:00
2023-04-20 15:42:18 +00:00
export default Users;