From 8a650a6b9ec6f1167589f339cd71b1ad54e7fc8a Mon Sep 17 00:00:00 2001
From: Zakharov_Rostislav
Date: Fri, 22 Dec 2023 13:27:30 +0400
Subject: [PATCH] lab8 some minor fixes
---
.../components/users/userPage/UserPageInfo.jsx | 3 ++-
ReactLibrary/src/pages/AdminPage.jsx | 17 +++++++++++++++--
ReactLibrary/src/pages/BooksTable.jsx | 15 +++++++++++++++
ReactLibrary/src/pages/UserPage.jsx | 9 +++------
4 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/ReactLibrary/src/components/users/userPage/UserPageInfo.jsx b/ReactLibrary/src/components/users/userPage/UserPageInfo.jsx
index 8471e76..ba08bdf 100644
--- a/ReactLibrary/src/components/users/userPage/UserPageInfo.jsx
+++ b/ReactLibrary/src/components/users/userPage/UserPageInfo.jsx
@@ -20,7 +20,8 @@ const UserPageInfo = () => {
-
+ {user.role === 'admin'
+ && }
>
);
diff --git a/ReactLibrary/src/pages/AdminPage.jsx b/ReactLibrary/src/pages/AdminPage.jsx
index 8cb37dc..d7f36a7 100644
--- a/ReactLibrary/src/pages/AdminPage.jsx
+++ b/ReactLibrary/src/pages/AdminPage.jsx
@@ -1,7 +1,22 @@
import { Button } from 'react-bootstrap';
import { Link } from 'react-router-dom';
+import AuthorizationForm from '../components/users/authorization/form/AuthorizationForm.jsx';
+import useUserObject from '../components/users/hooks/UserObjectHook';
+import ErrorPage from './ErrorPage.jsx';
const AdminPage = () => {
+ const id = parseInt(localStorage.getItem('userId'), 10);
+ const { user } = useUserObject(id);
+ if (!id) {
+ return (
+
+ );
+ }
+ if (user && user.role && user.role !== 'admin') {
+ return (
+
+ );
+ }
return (
<>
@@ -13,8 +28,6 @@ const AdminPage = () => {
-
-
>
);
diff --git a/ReactLibrary/src/pages/BooksTable.jsx b/ReactLibrary/src/pages/BooksTable.jsx
index 39a862a..a6d33f1 100644
--- a/ReactLibrary/src/pages/BooksTable.jsx
+++ b/ReactLibrary/src/pages/BooksTable.jsx
@@ -1,6 +1,21 @@
import Lines from '../components/lines/table/Lines.jsx';
+import AuthorizationForm from '../components/users/authorization/form/AuthorizationForm.jsx';
+import useUserObject from '../components/users/hooks/UserObjectHook';
+import ErrorPage from './ErrorPage.jsx';
const BooksTable = () => {
+ const id = parseInt(localStorage.getItem('userId'), 10);
+ const { user } = useUserObject(id);
+ if (!id) {
+ return (
+
+ );
+ }
+ if (user && user.role && user.role !== 'admin') {
+ return (
+
+ );
+ }
return (
<>
diff --git a/ReactLibrary/src/pages/UserPage.jsx b/ReactLibrary/src/pages/UserPage.jsx
index 0c627c7..b6aed8b 100644
--- a/ReactLibrary/src/pages/UserPage.jsx
+++ b/ReactLibrary/src/pages/UserPage.jsx
@@ -1,18 +1,15 @@
import AuthorizationForm from '../components/users/authorization/form/AuthorizationForm.jsx';
import UserPageInfo from '../components/users/userPage/UserPageInfo.jsx';
-// import useAuthorization from '../components/users/context_hooks/AuthorizationHook';
const UserPage = () => {
- // let { id } = useAuthorization();
- let id = localStorage.getItem('userId');
- id = parseInt(id, 10);
+ const id = parseInt(localStorage.getItem('userId'), 10);
if (!id) {
return (
-
+
);
}
return (
-
+
);
};