diff --git a/src/App.tsx b/src/App.tsx index 3f411c0..6570971 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { BrowserRouter as Router, Switch } from 'react-router-dom'; +import { Router, Switch } from 'react-router-dom'; /** * Components @@ -14,17 +14,22 @@ import MainPage from 'pages/main'; import CoursesPage from 'pages/courses'; import MessagesPage from 'pages/messages'; import ProfilePage from 'pages/profile'; +import ControlPage from 'pages/control'; import AuthPage from 'pages/auth'; import NotFoundPage from 'pages/404'; +import { UserRoleEnum } from 'enums'; +import { useRootStore } from 'hooks/useRootStore'; const App = () => { + const { uiStore } = useRootStore(); return ( - + - + + diff --git a/src/components/Auth/AuthForm.tsx b/src/components/Auth/AuthForm.tsx index e1fa620..c609ec1 100644 --- a/src/components/Auth/AuthForm.tsx +++ b/src/components/Auth/AuthForm.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { MdAccountCircle, MdVpnKey } from 'react-icons/md'; import { FormControl, FormLabel, InputGroup, Input, InputLeftElement, Button, Icon, useToast } from '@chakra-ui/react'; import { useRootStore } from 'hooks/useRootStore'; -import { useHistory } from 'react-router-dom'; import { observer } from 'mobx-react'; import { SubmitHandler, useForm } from 'react-hook-form'; import { useErrorHandler } from 'react-error-boundary'; @@ -15,14 +14,12 @@ type AuthInputs = { const AuthForm: React.FC = () => { const { register, reset, handleSubmit } = useForm(); const { authStore } = useRootStore(); - const history = useHistory(); const handleError = useErrorHandler(); const toast = useToast(); const onSubmit: SubmitHandler = async data => { try { await authStore.login(data.login, data.password); - history.push('/'); toast({ title: `👋 Welcome back!`, description: 'You are successfully logged in.', diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index b7b8267..77e2aa5 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -5,6 +5,7 @@ import UserInfo from './User/UserInfo'; import UserNotifications from './User/UserNotifications'; import useWindowDimensions from 'hooks/useWindowDimensions'; import NavMobile from '../Nav/Mobile/Nav'; +import { observer } from 'mobx-react'; const Header: React.FC = () => { const { isDesktop } = useWindowDimensions(); @@ -45,4 +46,4 @@ const Header: React.FC = () => { ); }; -export default Header; +export default observer(Header); diff --git a/src/components/Header/User/UserInfo.tsx b/src/components/Header/User/UserInfo.tsx index d76adff..61291e2 100644 --- a/src/components/Header/User/UserInfo.tsx +++ b/src/components/Header/User/UserInfo.tsx @@ -18,7 +18,7 @@ import { MdSettings, MdExitToApp } from 'react-icons/md'; import { observer } from 'mobx-react'; import { useRootStore } from 'hooks/useRootStore'; import { useHistory, Link } from 'react-router-dom'; -import UserBadge from 'components/Header/User/UserBadge'; +import UserBadge from 'components/User/UserBadge'; const UserInfo: React.FC = () => { const { authStore, userStore } = useRootStore(); @@ -36,7 +36,7 @@ const UserInfo: React.FC = () => { }; if (userStore.me === null) { - return ; + return ; } return ( diff --git a/src/components/Header/User/UserNotifications.tsx b/src/components/Header/User/UserNotifications.tsx index f906cb7..79d776f 100644 --- a/src/components/Header/User/UserNotifications.tsx +++ b/src/components/Header/User/UserNotifications.tsx @@ -1,9 +1,18 @@ import React from 'react'; import { Box } from '@chakra-ui/layout'; +import { Skeleton } from '@chakra-ui/skeleton'; import { Button } from '@chakra-ui/button'; import { MdNotifications } from 'react-icons/md'; +import { useRootStore } from 'hooks/useRootStore'; +import { observer } from 'mobx-react'; const UserNotifications: React.FC = () => { + const { userStore } = useRootStore(); + + if (userStore.me === null) { + return ; + } + return (