diff --git a/Lab5/data.json b/Lab5/data.json index f7f49a3..c52e769 100644 --- a/Lab5/data.json +++ b/Lab5/data.json @@ -28,27 +28,19 @@ "lines": [ { "typeId": "1", - "price": "ххэ", - "count": "\\жэ", - "sum": "13.12.2023", + "price": "6гор6н", + "count": "апраvfvfg", + "sum": "12.12.2023", "image": "", - "id": 10 + "id": 1 }, { "typeId": "1", - "price": "fds", - "count": "dsfsd", - "sum": "13.12.2023", + "price": "олнрп", + "count": "орпао", + "sum": "16.12.2023", "image": "", - "id": 11 - }, - { - "typeId": "1", - "price": "dfc", - "count": "dcv", - "sum": "14.12.2023", - "image": "", - "id": 12 + "id": 2 } ] } \ No newline at end of file diff --git a/Lab5/src/App.jsx b/Lab5/src/App.jsx index be5c76a..84aa9d5 100644 --- a/Lab5/src/App.jsx +++ b/Lab5/src/App.jsx @@ -3,10 +3,9 @@ import { Container } from 'react-bootstrap'; import { Toaster } from 'react-hot-toast'; import { Outlet } from 'react-router-dom'; import { Provider } from 'react-redux'; -import React, { useEffect } from 'react'; import Footer from './components/footer/Footer.jsx'; import Navigation from './components/navigation/Navigation.jsx'; - +import React, { useEffect } from 'react'; import { BrowserRouter as Router } from 'react-router-dom'; import store from './Reducer/store'; // Путь к вашему store diff --git a/Lab5/src/Reducer/ProtectedRoute.js b/Lab5/src/Reducer/ProtectedRoute.js new file mode 100644 index 0000000..38c5b8e --- /dev/null +++ b/Lab5/src/Reducer/ProtectedRoute.js @@ -0,0 +1,21 @@ +import React from 'react'; +import { Route, Navigate } from 'react-router-dom'; +import { useSelector } from 'react-redux'; + +const ProtectedRoute = ({ element: Element, adminOnly, ...rest }) => { + const user = useSelector((state) => state.user); + + if (!user) { + // Если пользователь не авторизован, перенаправляем на страницу входа + return ; + } + + if (adminOnly && user.status !== 'admin') { + // Если запрошен доступ только для администраторов, но пользователь не администратор + return ; + } + + return } />; +}; + +export default ProtectedRoute; diff --git a/Lab5/src/components/lines/hooks/LinesItemFormHook.js b/Lab5/src/components/lines/hooks/LinesItemFormHook.js index 7cadebc..ef8f010 100644 --- a/Lab5/src/components/lines/hooks/LinesItemFormHook.js +++ b/Lab5/src/components/lines/hooks/LinesItemFormHook.js @@ -17,7 +17,8 @@ const useLinesItemForm = (id, linesChangeHandle) => { const typeId = parseInt(formData.typeId, 10); const { price } = formData; const { count } = formData; - const sum = new Date().toLocaleDateString(); + const sum = item && item.sum ? item.sum : new Date().toLocaleDateString(); + const image = formData.image.startsWith('data:image') ? formData.image : ''; return { typeId: typeId.toString(), diff --git a/Lab5/src/components/lines/table/Lines.jsx b/Lab5/src/components/lines/table/Lines.jsx index 0b0c714..a859821 100644 --- a/Lab5/src/components/lines/table/Lines.jsx +++ b/Lab5/src/components/lines/table/Lines.jsx @@ -35,21 +35,14 @@ const Lines = () => { const navigate = useNavigate(); - const showEditPage = (id) => { - navigate(`/page-edit/${id}`); - }; - return ( <> - -