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

403 lines
11 KiB
TypeScript
Raw Normal View History

2022-09-08 17:21:17 +00:00
import * as React from "react";
import { useState, useEffect } from "react";
2023-08-14 13:08:28 +00:00
import { useNavigate, useParams } from "react-router-dom";
import {
AccordionDetails,
AccordionSummary,
Accordion,
Skeleton,
Radio,
Box,
Typography,
TextField,
Button,
Table,
TableHead,
TableBody,
TableCell,
TableRow,
} from "@mui/material";
import { GridSelectionModel } from "@mui/x-data-grid";
2023-04-20 15:42:18 +00:00
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import ConditionalRender from "@root/pages/Setting/ConditionalRender";
2023-08-14 11:58:12 +00:00
import ModalUser from "@root/pages/dashboard/ModalUser";
import ServiceUsersDG from "./ServiceUsersDG";
2023-09-01 13:17:24 +00:00
import { getRegisteredUsers, getManagersList } from "@root/api/user";
import { getRoles } from "@root/api/privilegies";
import { getRoles_mock, TMockData } from "../../../api/roles";
2023-04-20 15:42:18 +00:00
import theme from "../../../theme";
2023-07-25 07:47:20 +00:00
import type { UserType } from "../../../api/roles";
2023-07-12 10:27:21 +00:00
2023-04-20 15:42:18 +00:00
const Users: React.FC = () => {
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
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);
2023-09-08 10:17:27 +00:00
setAccordionText(mockdata[0].desc || "");
2023-04-20 15:42:18 +00:00
});
2022-09-24 15:37:24 +00:00
};
2022-09-27 20:42:56 +00:00
const [accordionState, setAccordionState] = React.useState<boolean>(true);
const [accordionText, setAccordionText] = React.useState<string>("");
2023-09-08 10:17:27 +00:00
const handleChange = (value: string) => {
setSelectedValue(value);
setAccordionText(data.find(({ name }) => name === value)?.desc || "");
if (selectedValue === "manager") {
}
2023-04-20 15:42:18 +00:00
};
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
2023-04-20 15:42:18 +00:00
const [roles, setRoles] = React.useState<TMockData>([]);
2023-07-25 07:47:20 +00:00
const [users, setUsers] = React.useState<UserType[]>([]);
const [manager, setManager] = React.useState<UserType[]>([]);
2023-08-14 11:58:12 +00:00
const [openUserModal, setOpenUserModal] = useState<boolean>(false);
const [activeUserId, setActiveUserId] = useState<string>("");
2023-04-20 15:42:18 +00:00
2023-08-14 13:08:28 +00:00
const { userId } = useParams();
2023-09-08 10:17:27 +00:00
useEffect(() => {
handleChangeData();
}, []);
2023-08-14 13:08:28 +00:00
useEffect(() => {
if (userId) {
setActiveUserId(userId);
setOpenUserModal(true);
return;
}
setActiveUserId("");
setOpenUserModal(false);
}, [userId]);
useEffect(() => {
2023-09-01 13:17:24 +00:00
getManagersList().then(([managersListResponse]) => {
if (managersListResponse) {
setManager(managersListResponse.users);
}
2023-09-01 13:17:24 +00:00
});
2023-07-12 10:27:21 +00:00
2023-09-01 13:17:24 +00:00
getRegisteredUsers().then(([registeredUsersResponse]) => {
if (registeredUsersResponse) {
setUsers(registeredUsersResponse.users);
}
2023-09-01 13:17:24 +00:00
});
2023-09-01 13:17:24 +00:00
getRoles().then(([rolesResponse]) => {
if (rolesResponse) {
setRoles(rolesResponse);
}
});
}, [selectedValue]);
2023-04-20 15:42:18 +00:00
2023-09-12 19:55:51 +00:00
const [selectedTariffs, setSelectedTariffs] = useState<GridSelectionModel>([]);
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
2023-09-08 10:17:27 +00:00
sx={{ display: "flex" }}
onClick={handleToggleAccordion}
2023-09-12 19:55:51 +00:00
expandIcon={<ExpandMoreIcon sx={{ color: theme.palette.secondary.main }} />}
2023-04-20 15:42:18 +00:00
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>
</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}
2023-09-08 10:17:27 +00:00
onClick={() => handleChange(radioboxes[index])}
2023-04-20 15:42:18 +00:00
>
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]}
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-07-12 10:27:21 +00:00
<Box
component="section"
sx={{
width: "90%",
mt: "45px",
display: "flex",
justifyContent: "center",
}}
>
<ConditionalRender
isLoading={false}
role={selectedValue}
2023-09-12 19:55:51 +00:00
childrenManager={<ServiceUsersDG users={manager} handleSelectionChange={setSelectedTariffs} />}
childrenUser={<ServiceUsersDG users={users} handleSelectionChange={setSelectedTariffs} />}
/>
</Box>
2023-09-12 19:55:51 +00:00
<ModalUser open={openUserModal} setOpen={setOpenUserModal} userId={activeUserId} />
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;