From 3bf2eee43d64019fdecd2392f1a2cca3e08241be Mon Sep 17 00:00:00 2001 From: ArtChaos189 Date: Fri, 5 May 2023 15:07:37 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D1=8E?= =?UTF-8?q?=D0=B7=D0=B5=D1=80=D0=BE=D0=B2=20=D0=B2=20=D0=B0=D0=B4=D0=BC?= =?UTF-8?q?=D0=B8=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/roles.ts | 2 + src/index.tsx | 3 +- src/pages/Setting/ConditionalRender.tsx | 28 ++-- src/pages/dashboard/Content/Users.tsx | 202 ++++++++++++++++-------- 4 files changed, 153 insertions(+), 82 deletions(-) diff --git a/src/api/roles.ts b/src/api/roles.ts index 89014c4..78f454e 100644 --- a/src/api/roles.ts +++ b/src/api/roles.ts @@ -21,6 +21,8 @@ export const MOCK_DATA_USERS = [ export type TMockData = typeof MOCK_DATA_USERS; +export type UsersType = { login: string; email: string; phoneNumber: string; isDeleted: boolean; createdAt: string }[]; + export const getRoles_mock = (): Promise => { return new Promise((resolve) => { setTimeout(() => { diff --git a/src/index.tsx b/src/index.tsx index 04899f0..cfeaa9e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,8 +7,6 @@ import { ThemeProvider } from "@mui/material/styles"; import { SnackbarProvider } from "notistack"; -import theme from "./theme"; - import PublicRoute from "@kitUI/publicRoute"; import PrivateRoute from "@kitUI/privateRoute"; @@ -26,6 +24,7 @@ import PromocodeManagement from "@pages/dashboard/Content/PromocodeManagement"; import { SettingRoles } from "@pages/Setting/SettingRoles"; import Support from "@pages/dashboard/Content/Support/Support"; +import theme from "./theme"; import "./index.css"; const componentsArray = [ diff --git a/src/pages/Setting/ConditionalRender.tsx b/src/pages/Setting/ConditionalRender.tsx index 8ed1537..bcefab4 100644 --- a/src/pages/Setting/ConditionalRender.tsx +++ b/src/pages/Setting/ConditionalRender.tsx @@ -3,6 +3,7 @@ import React, { useEffect, useState } from "react"; type ConditionalRenderProps = { isLoading: boolean; + role: string; childrenUser?: JSX.Element; childrenAdmin?: JSX.Element; childrenManager?: JSX.Element; @@ -10,25 +11,26 @@ type ConditionalRenderProps = { const ConditionalRender = ({ isLoading, + role, childrenUser, childrenAdmin, childrenManager, }: ConditionalRenderProps): JSX.Element => { - const [role, setRole] = useState(""); + // const [role, setRole] = useState(""); - useEffect(() => { - const axiosAccount = async () => { - try { - const { data } = await axios.get("https://admin.pena.digital/user/643e23f3dba63ba17272664d"); - setRole(data.role); - } catch (error) { - console.error("Ошибка при получение роли пользавателя"); - } - }; - axiosAccount(); - }, [role]); + // useEffect(() => { + // const axiosAccount = async () => { + // try { + // const { data } = await axios.get("https://admin.pena.digital/user/643e23f3dba63ba17272664d"); + // setRole(data.role); + // } catch (error) { + // console.error("Ошибка при получение роли пользавателя"); + // } + // }; + // axiosAccount(); + // }, [role]); - if (isLoading) { + if (!isLoading) { if (role === "admin") { return childrenAdmin ? childrenAdmin :
Администратор
; } diff --git a/src/pages/dashboard/Content/Users.tsx b/src/pages/dashboard/Content/Users.tsx index 816a0aa..c613ee0 100644 --- a/src/pages/dashboard/Content/Users.tsx +++ b/src/pages/dashboard/Content/Users.tsx @@ -1,6 +1,7 @@ import * as React from "react"; import { useNavigate } from "react-router-dom"; import { Box, Typography, TextField, Button } from "@mui/material"; +import axios from "axios"; import Table from "@mui/material/Table"; import TableHead from "@mui/material/TableHead"; import TableBody from "@mui/material/TableBody"; @@ -13,14 +14,18 @@ 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"; + import theme from "../../../theme"; -import axios from "axios"; +import ConditionalRender from "@root/pages/Setting/ConditionalRender"; const Users: React.FC = () => { - const radioboxes = ["a", "b", "c"]; + const radioboxes = ["admin", "manager", "user"]; - const [selectedValue, setSelectedValue] = React.useState("a"); + const [selectedValue, setSelectedValue] = React.useState("admin"); const handleChange = (event: React.ChangeEvent) => { setSelectedValue(event.target.value); }; @@ -57,20 +62,30 @@ const Users: React.FC = () => { handleChangeData(); const [roles, setRoles] = React.useState([]); + const [users, setUsers] = React.useState(); React.useEffect(() => { const axiosRoles = async () => { - const response = await axios({ + const { data } = await axios({ method: "get", url: "https://admin.pena.digital/strator/role/", }); - return response; + setRoles(data); }; - axiosRoles().then((result) => { - setRoles(result.data); - }); + const gettingRegisteredUsers = async () => { + const { data } = await axios({ + method: "get", + url: "https://hub.pena.digital/user/", + }); + setUsers(data); + }; + + gettingRegisteredUsers(); + axiosRoles(); }, []); + console.log(users); + return (