diff --git a/src/App.js b/src/App.js
index 92c83ef..49ee5eb 100644
--- a/src/App.js
+++ b/src/App.js
@@ -8,7 +8,7 @@ import locale from "antd/lib/locale/ru_RU"
import Login from './pages/Login'
import Main from './pages/Main'
import { OpenAPI } from './services/api'
-import { PrivateRoute } from './components/PrivateRoute'
+import { PrivateRoute } from './components/Private'
//OpenAPI.BASE = 'http://localhost:3000'
OpenAPI.TOKEN = localStorage['token']
diff --git a/src/components/Private/PrivateContent.jsx b/src/components/Private/PrivateContent.jsx
new file mode 100644
index 0000000..878644f
--- /dev/null
+++ b/src/components/Private/PrivateContent.jsx
@@ -0,0 +1,24 @@
+const admins = ['администратор', 'админ', 'admin']
+
+export const isInRole = (roles) => {
+ if(!roles?.length)
+ return true
+ const role = localStorage['roleName']?.toLowerCase()
+ if(admins.indexOf(role) > -1)
+ return true
+ for(const r of roles)
+ if(r.toLowerCase() === role)
+ return true
+ return false
+}
+
+export const privateContent = (roles, children) => {
+ if(isInRole(roles))
+ return children
+ else
+ return null
+}
+
+export const PrivateContent = ({roles, children}) => {
+ return privateContent(roles, children)
+}
\ No newline at end of file
diff --git a/src/components/Private/PrivateMenuItem.jsx b/src/components/Private/PrivateMenuItem.jsx
new file mode 100644
index 0000000..070866f
--- /dev/null
+++ b/src/components/Private/PrivateMenuItem.jsx
@@ -0,0 +1,11 @@
+import { Menu } from "antd";
+import { isInRole } from './PrivateContent'
+
+export const PrivateMenuItem = ({ children, roles, ...other }) => {
+ if(!isInRole(roles))
+ return null
+
+ return
+ {children}
+ ;
+}
diff --git a/src/components/PrivateRoute.jsx b/src/components/Private/PrivateRoute.jsx
similarity index 100%
rename from src/components/PrivateRoute.jsx
rename to src/components/Private/PrivateRoute.jsx
diff --git a/src/components/Private/index.ts b/src/components/Private/index.ts
new file mode 100644
index 0000000..c813da3
--- /dev/null
+++ b/src/components/Private/index.ts
@@ -0,0 +1,3 @@
+export {PrivateRoute} from './PrivateRoute'
+export {privateContent, PrivateContent} from './PrivateContent'
+export {PrivateMenuItem} from './PrivateMenuItem'
\ No newline at end of file
diff --git a/src/pages/Documents/menuItems.jsx b/src/pages/Documents/menuItems.jsx
index 59068a9..7abf3c7 100644
--- a/src/pages/Documents/menuItems.jsx
+++ b/src/pages/Documents/menuItems.jsx
@@ -1,10 +1,11 @@
-import { Menu } from "antd";
+//import { Menu } from "antd";
import { FolderOutlined } from "@ant-design/icons";
import { Link, Route} from "react-router-dom";
import DocumentsTemplate from './DocumentsTemplate'
+import {PrivateMenuItem} from '../../components/Private'
export const documentCategories = [
- {id:1, key:'fluidService', title:'Растворный сервис'},
+ {id:1, key:'fluidService', title:'Растворный сервис'/*, roles:['ff']*/},
{id:2, key:'cementing', title:'Цементирование'},
{id:3, key:'nnb', title:'ННБ'},
{id:4, key:'gti', title:'ГТИ'},
@@ -14,11 +15,11 @@ export const documentCategories = [
]
const makeMenuItem = (keyValue, rootPath, title, other) => (
-
{title}
- )
+ )
const makeRouteItem = (keyValue, rootPath, other) => (
-
-
+ return
@@ -107,6 +106,4 @@ export default function Well() {
- >
- );
}