diff --git a/index.html b/index.html index 836380b..da14758 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,7 @@ + TicketsBook diff --git a/public/logo.ico b/public/logo.ico new file mode 100644 index 0000000..7366766 Binary files /dev/null and b/public/logo.ico differ diff --git a/src/components/cart/Cart.jsx b/src/components/cart/Cart.jsx index 59677f7..8b9b188 100644 --- a/src/components/cart/Cart.jsx +++ b/src/components/cart/Cart.jsx @@ -1,5 +1,5 @@ import { Card, Button, ButtonGroup } from 'react-bootstrap'; -import { Link } from 'react-router-dom'; +import { Link, useNavigate } from 'react-router-dom'; import { DashLg, PlusLg, XLg } from 'react-bootstrap-icons'; import { useEffect, useState } from 'react'; import { Form, } from 'react-bootstrap'; @@ -8,6 +8,8 @@ import useCart from './CartHook'; const Cart = () => { + const navigate = useNavigate(); + const [validated, setValidated] = useState(false); const [name, setName] = useState(''); const [surname, setSurname] = useState(''); @@ -54,7 +56,7 @@ const Cart = () => { const handleLogout = () => { localStorage.removeItem('user'); - history.push('/'); + navigate('/index.jsx'); }; const { diff --git a/src/components/lines/serverCatalog/Catalog.css b/src/components/lines/serverCatalog/Catalog.css index 6d20261..d453478 100644 --- a/src/components/lines/serverCatalog/Catalog.css +++ b/src/components/lines/serverCatalog/Catalog.css @@ -37,7 +37,7 @@ body{ border: 4px solid #1b1818; border-radius: 5px; max-width: 100%; - height: 35vh; + height: 30%; margin-bottom: 2%; } diff --git a/src/components/navigation/Navigation.jsx b/src/components/navigation/Navigation.jsx index 923b34c..e8662de 100644 --- a/src/components/navigation/Navigation.jsx +++ b/src/components/navigation/Navigation.jsx @@ -3,14 +3,10 @@ import { Container, Nav, Navbar } from 'react-bootstrap'; import { Link, useLocation } from 'react-router-dom'; import './Navigation.css'; import Menu from '../menuWrapper/menuWrapper'; +import useUser from '../users/userHook'; const Navigation = ({ routes }) => { - const storedUserData = localStorage.getItem('user'); - const storedUser = storedUserData ? JSON.parse(storedUserData) : {}; - const userName = storedUser && storedUser.handle ? storedUser.handle : ''; - const isAdmin = userName.toLowerCase() === 'admin'; - - console.log(localStorage); + const {isAdmin, userName} = useUser(); const location = useLocation(); const pages = routes.filter((route) => Object.prototype.hasOwnProperty.call(route, 'title')); diff --git a/src/components/users/UserContext.jsx b/src/components/users/UserContext.jsx index a1a8097..963e089 100644 --- a/src/components/users/UserContext.jsx +++ b/src/components/users/UserContext.jsx @@ -11,9 +11,13 @@ export const UserProvider = ({ children }) => { saveUser(user || null); }, [user]); - return - {children} - ; + const userContextValue = { user, dispatch }; + + return ( + + {children} + + ); }; UserProvider.propTypes = { diff --git a/src/components/users/userHook.js b/src/components/users/userHook.js index 1dc464b..68a11b4 100644 --- a/src/components/users/userHook.js +++ b/src/components/users/userHook.js @@ -3,17 +3,14 @@ import { userLogin, userLogout } from './userReducer.js'; import UserContext from './UserContext.jsx'; const useUser = () => { - const context = useContext(UserContext); - - if (!context) { - throw new Error('useUser должен использоваться внутри UserProvider'); - } - - const { dispatch } = useContext(UserContext); + const {user, dispatch} = useContext(UserContext); return { + isAdmin : user?.handle || null === 'admin', + userName : user?.handle || null, userLogout: () => dispatch(userLogout()), userLogin: (user) => dispatch(userLogin(user)), + }; }; diff --git a/src/pages/Into.jsx b/src/pages/Into.jsx index 7868bd3..c8470a1 100644 --- a/src/pages/Into.jsx +++ b/src/pages/Into.jsx @@ -35,6 +35,7 @@ const PersonalAccountLogin = () => { } else if (result === 3) { userLogin(formData); navigate('/myTickets'); + } } };