feat: setup create course page

This commit is contained in:
Sergey Yarkov 2021-10-18 23:10:41 +03:00
parent 63beba1e0e
commit 9a43ade63a
6 changed files with 51 additions and 5 deletions

View File

@ -22,6 +22,7 @@ import PublicRoute from '@educt/components/PublicRoute';
*/ */
import AuthPage from '@educt/pages/auth/auth'; import AuthPage from '@educt/pages/auth/auth';
import NotFoundPage from '@educt/pages/404/404'; import NotFoundPage from '@educt/pages/404/404';
import CreateCoursePage from '@educt/pages/courses/create/create';
const CoursesPage = React.lazy(() => import('@educt/pages/courses/courses')); const CoursesPage = React.lazy(() => import('@educt/pages/courses/courses'));
const MainPage = React.lazy(() => import('@educt/pages/main/main')); const MainPage = React.lazy(() => import('@educt/pages/main/main'));
const MessagesPage = React.lazy(() => import('@educt/pages/messages/messages')); const MessagesPage = React.lazy(() => import('@educt/pages/messages/messages'));
@ -37,6 +38,12 @@ const App = () => {
<Router history={history}> <Router history={history}>
<Switch> <Switch>
<PrivateRoute exact path='/' component={MainPage} title='Home' /> <PrivateRoute exact path='/' component={MainPage} title='Home' />
<PrivateRoute
path='/courses/create'
component={CreateCoursePage}
title='Create new course'
roles={[UserRoleEnum.ADMIN, UserRoleEnum.TEACHER]}
/>
<PrivateRoute path='/courses' component={CoursesPage} title='Courses' /> <PrivateRoute path='/courses' component={CoursesPage} title='Courses' />
<PrivateRoute path='/messages' component={MessagesPage} title='Messages' /> <PrivateRoute path='/messages' component={MessagesPage} title='Messages' />
<PrivateRoute path='/profile' component={ProfilePage} title='Profile' /> <PrivateRoute path='/profile' component={ProfilePage} title='Profile' />

View File

@ -3,10 +3,16 @@ import { MdAccountCircle, MdCollectionsBookmark, MdGroup, MdHome, MdMessage } fr
import { IAppConfig } from './interfaces'; import { IAppConfig } from './interfaces';
const config: IAppConfig = { const config: IAppConfig = {
/**
* Some info about application
*/
metaData: { metaData: {
appName: 'Educt', appName: 'Educt',
appDescription: 'Learn management system', appDescription: 'Learn management system',
}, },
/**
* Links that are rendered in the navigation
*/
links: [ links: [
{ location: '/', title: 'Main', public: true, icon: MdHome }, { location: '/', title: 'Main', public: true, icon: MdHome },
{ location: '/courses', title: 'Courses', public: true, icon: MdCollectionsBookmark }, { location: '/courses', title: 'Courses', public: true, icon: MdCollectionsBookmark },

View File

@ -21,6 +21,7 @@ import LoadingPage from '@educt/components/LoadingPage';
*/ */
import { useRootStore } from '@educt/hooks/useRootStore'; import { useRootStore } from '@educt/hooks/useRootStore';
import { CoursesPageContextProvider } from '@educt/providers'; import { CoursesPageContextProvider } from '@educt/providers';
import { useHistory, useLocation } from 'react-router';
/** /**
* Courses page * Courses page
@ -31,6 +32,7 @@ const CoursesPage: React.FC<IPageProps> = ({ title }) => {
categoryStore, categoryStore,
courseStore, courseStore,
} = useRootStore(); } = useRootStore();
const history = useHistory();
if (me === null) return <LoadingPage />; if (me === null) return <LoadingPage />;
@ -43,7 +45,12 @@ const CoursesPage: React.FC<IPageProps> = ({ title }) => {
<Text mt='2'>List of all available courses.</Text> <Text mt='2'>List of all available courses.</Text>
</Box> </Box>
{(me.isAdmin || me.isTeacher) && ( {(me.isAdmin || me.isTeacher) && (
<Button variant='outline' colorScheme='blue' leftIcon={<AddIcon />}> <Button
onClick={() => history.push('/courses/create')}
variant='outline'
colorScheme='blue'
leftIcon={<AddIcon />}
>
Create new Create new
</Button> </Button>
)} )}

View File

@ -0,0 +1,26 @@
import React from 'react';
import { Box, Heading, Text } from '@chakra-ui/react';
/**
* Types
*/
import { IPageProps } from '@educt/interfaces';
import { observer } from 'mobx-react-lite';
/**
* Create course page
*/
const CreateCoursePage: React.FC<IPageProps> = ({ title }) => {
return (
<>
<Box>
<Box>
<Heading as='h1'>Create</Heading>
<Text mt='2'>Create new course in the system.</Text>
</Box>
</Box>
</>
);
};
export default CreateCoursePage;

View File

@ -14,6 +14,7 @@ import LoadingPage from './components/LoadingPage';
/** /**
* Containers * Containers
*/ */
import MainContainer from './containers/MainContainer';
import UpdatePasswordContainer from './containers/UpdatePasswordContainer'; import UpdatePasswordContainer from './containers/UpdatePasswordContainer';
import UpdateEmailContainer from './containers/UpdateEmailContainer'; import UpdateEmailContainer from './containers/UpdateEmailContainer';
import ConfirmEmailContainer from './containers/ConfirmEmailContainer'; import ConfirmEmailContainer from './containers/ConfirmEmailContainer';
@ -33,7 +34,6 @@ import { ProfilePageContext } from '@educt/contexts';
* Providers * Providers
*/ */
import { ProfilePageContextProvider } from '@educt/providers'; import { ProfilePageContextProvider } from '@educt/providers';
import MainContainer from './containers/MainContainer';
/** /**
* Profile page * Profile page

View File

@ -1,4 +1,4 @@
import { makeAutoObservable, observable } from 'mobx'; import { makeAutoObservable, observable, runInAction } from 'mobx';
import { createBrowserHistory } from 'history'; import { createBrowserHistory } from 'history';
/** /**
@ -39,8 +39,7 @@ export default class UIStore {
* Pathname changed * Pathname changed
*/ */
this.history.listen(({ pathname }) => { this.history.listen(({ pathname }) => {
console.log(`[history]: pathname changed to "${pathname}"`); this.setLocation(pathname);
this.location = pathname;
}); });
/** /**
@ -50,6 +49,7 @@ export default class UIStore {
} }
public setLocation(location: string): void { public setLocation(location: string): void {
console.log(`[history]: location changed to "${location}"`);
this.location = location; this.location = location;
} }