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

477 lines
13 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-04-20 15:42:18 +00:00
import { useNavigate } 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 ClearIcon from "@mui/icons-material/Clear";
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";
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-08-02 12:11:37 +00:00
import { makeRequest } from "@frontend/kitui";
2023-07-25 07:47:20 +00:00
type RegisteredUsersResponse = {
tatalPages: number;
users: UserType[];
};
2022-09-08 17:21:17 +00:00
2023-07-12 10:27:21 +00:00
const baseUrl =
process.env.NODE_ENV === "production" ? "" : "https://admin.pena.digital";
2023-04-20 15:42:18 +00:00
const Users: React.FC = () => {
// 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>([]);
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
useEffect(() => {
async function axiosRoles() {
try {
2023-07-12 10:27:21 +00:00
const rolesResponse = await makeRequest<never, TMockData>({
method: "get",
2023-07-12 10:27:21 +00:00
url: baseUrl + "/strator/role/",
});
2023-07-12 10:27:21 +00:00
setRoles(rolesResponse);
} catch (error) {
console.error("Ошибка при получении ролей!");
}
}
async function gettingRegisteredUsers() {
try {
2023-07-25 07:47:20 +00:00
const { users } = await makeRequest<never, RegisteredUsersResponse>({
method: "get",
2023-07-12 10:27:21 +00:00
url: baseUrl + "/user/",
});
2023-07-12 10:27:21 +00:00
2023-07-25 07:47:20 +00:00
setUsers(users);
} catch (error) {
console.error("Ошибка при получении пользователей!");
}
}
async function gettingListManagers() {
try {
2023-07-25 07:47:20 +00:00
const { users } = await makeRequest<never, RegisteredUsersResponse>({
method: "get",
2023-07-12 10:27:21 +00:00
url: baseUrl + "/user/",
});
2023-07-12 10:27:21 +00:00
2023-07-25 07:47:20 +00:00
setManager(users);
} catch (error) {
console.error("Ошибка при получении менеджеров!");
}
}
gettingListManagers();
gettingRegisteredUsers();
axiosRoles();
}, [selectedValue]);
2023-04-20 15:42:18 +00:00
2023-07-12 10:27:21 +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
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",
}}
>
2023-07-12 10:27:21 +00:00
<ClearIcon
sx={{ color: theme.palette.secondary.main }}
onClick={() => handleChangeAccordion("")}
/>
2023-04-20 15:42:18 +00:00
</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-07-12 10:27:21 +00:00
<Box
component="section"
sx={{
width: "90%",
mt: "45px",
display: "flex",
justifyContent: "center",
}}
>
<ConditionalRender
isLoading={false}
role={selectedValue}
childrenManager={
<ServiceUsersDG
users={manager}
2023-07-12 10:27:21 +00:00
handleSelectionChange={setSelectedTariffs}
2023-08-14 11:58:12 +00:00
onRowClick={(userId) => {
setActiveUserId(userId);
setOpenUserModal(true);
}}
/>
}
childrenUser={
<ServiceUsersDG
users={users}
2023-07-12 10:27:21 +00:00
handleSelectionChange={setSelectedTariffs}
2023-08-14 11:58:12 +00:00
onRowClick={(userId) => {
setActiveUserId(userId);
setOpenUserModal(true);
}}
/>
}
/>
</Box>
2023-08-14 11:58:12 +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;