diff --git a/.gitignore b/.gitignore index 4d29575..834b352 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. +.env + # dependencies /node_modules /.pnp diff --git a/src/components/CourseStatusBadge/CourseStatusBadge.tsx b/src/components/CourseStatusBadge/CourseStatusBadge.tsx new file mode 100644 index 0000000..e32832a --- /dev/null +++ b/src/components/CourseStatusBadge/CourseStatusBadge.tsx @@ -0,0 +1,30 @@ +import { Badge } from '@chakra-ui/layout'; +import { CourseStatusEnum } from 'enums'; +import React from 'react'; + +type CourseStatusBadgeProps = { + status: CourseStatusEnum; +}; + +const CourseStatusBadge: React.FC = ({ status }) => { + return ( + <> + {(() => { + switch (status) { + case CourseStatusEnum.PUBLISHED: + return ( + + Published + + ); + case CourseStatusEnum.DRAFT: + return Draft; + default: + return null; + } + })()} + + ); +}; + +export default CourseStatusBadge; diff --git a/src/components/CourseStatusBadge/index.ts b/src/components/CourseStatusBadge/index.ts new file mode 100644 index 0000000..a657fdd --- /dev/null +++ b/src/components/CourseStatusBadge/index.ts @@ -0,0 +1,3 @@ +import CourseStatusBadge from './CourseStatusBadge'; + +export default CourseStatusBadge; diff --git a/src/pages/courses/components/CategoryList/CategoryList.tsx b/src/pages/courses/components/CategoryList/CategoryList.tsx index 6952720..b057fde 100644 --- a/src/pages/courses/components/CategoryList/CategoryList.tsx +++ b/src/pages/courses/components/CategoryList/CategoryList.tsx @@ -4,6 +4,11 @@ import { CoursesPageContext } from 'contexts'; import CategoryItem from './CategoryItem'; import { ICategory } from 'interfaces'; import CategoryListLoading from './CategoryListLoading'; + +/** + * Hooks + */ +import { useErrorHandler } from 'react-error-boundary'; import { useRootStore } from 'hooks/useRootStore'; type CategoryListPropsType = { @@ -12,16 +17,13 @@ type CategoryListPropsType = { }; const CategoryList: React.FC = ({ categories, isLoading }) => { - const { courseStore } = useRootStore(); + const { categoryStore } = useRootStore(); const { selectedCategory, setSelectedCategory } = useContext(CoursesPageContext); + const handleError = useErrorHandler(); - /** - * Handle on changing category - */ useEffect(() => { - console.log(`[LOG:] Selected category: ${selectedCategory?.title}`); - courseStore.loadCourses({ category_id: selectedCategory?.id }); - }, [courseStore, selectedCategory]); + categoryStore.loadCategories().catch(error => handleError(error)); + }, [categoryStore, handleError]); if (isLoading || categories === null) { return ; diff --git a/src/pages/courses/components/CourseList/CourseItem.tsx b/src/pages/courses/components/CourseList/CourseItem.tsx index f4226e8..dab4ad1 100644 --- a/src/pages/courses/components/CourseList/CourseItem.tsx +++ b/src/pages/courses/components/CourseList/CourseItem.tsx @@ -28,6 +28,7 @@ import { ICourse } from 'interfaces'; */ import { useColorMode } from '@chakra-ui/color-mode'; import { useRootStore } from 'hooks/useRootStore'; +import CourseStatusBadge from 'components/CourseStatusBadge'; type CourseItemPropsType = { course: Omit; @@ -97,7 +98,10 @@ const CourseItem: React.FC = ({ course }) => { /> - {course.category.title} + + {course.category.title} + {(me.isAdmin || me.isTeacher) && } + {course.title} diff --git a/src/pages/courses/components/CourseList/CourseList.tsx b/src/pages/courses/components/CourseList/CourseList.tsx index d1d8648..07605e0 100644 --- a/src/pages/courses/components/CourseList/CourseList.tsx +++ b/src/pages/courses/components/CourseList/CourseList.tsx @@ -1,5 +1,5 @@ -import React from 'react'; -import { Grid } from '@chakra-ui/react'; +import React, { useContext, useEffect } from 'react'; +import { Box, Grid, Text } from '@chakra-ui/react'; /** * Types @@ -12,33 +12,58 @@ import { ICourse } from 'interfaces'; import CourseItem from './CourseItem'; import CourseListLoading from './CourseListLoading'; +/** + * Hooks + */ +import { useRootStore } from 'hooks/useRootStore'; + +/** + * Contexts + */ +import { CoursesPageContext } from 'contexts'; + type CourseListPropsType = { courses: Omit[] | null; isLoading: boolean; }; const CourseList: React.FC = ({ courses, isLoading }) => { + const { courseStore } = useRootStore(); + const { selectedCategory } = useContext(CoursesPageContext); + + useEffect(() => { + courseStore.loadCourses({ category_id: selectedCategory?.id }); + }, [courseStore, selectedCategory]); + if (isLoading || courses === null) { return ; } return ( - - {courses.map(course => { - return ; - })} - + <> + {courses.length !== 0 ? ( + + {courses.map(course => ( + + ))} + + ) : ( + + There are no courses in this category. + + )} + ); }; diff --git a/src/pages/courses/index.tsx b/src/pages/courses/index.tsx index 48c567c..574ab06 100644 --- a/src/pages/courses/index.tsx +++ b/src/pages/courses/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React from 'react'; import { observer } from 'mobx-react-lite'; import { Flex, Tabs, TabList, Tab, Box, Heading, Text, Button } from '@chakra-ui/react'; @@ -10,14 +10,13 @@ import { AddIcon } from '@chakra-ui/icons'; */ import CourseList from './components/CourseList'; import CategoryList from './components/CategoryList'; +import LoadingPage from 'components/LoadingPage'; /** * Hooks */ import { useRootStore } from 'hooks/useRootStore'; import { CoursesPageContextProvider } from 'providers'; -import { useErrorHandler } from 'react-error-boundary'; -import LoadingPage from 'components/LoadingPage'; /** * Courses page @@ -28,14 +27,6 @@ const CoursesPage: React.FC = ({ title }) => { categoryStore, courseStore, } = useRootStore(); - const handleError = useErrorHandler(); - - useEffect(() => { - if (me !== null) { - categoryStore.loadCategories().catch(error => handleError(error)); - // courseStore.loadCourses().catch(error => handleError(error)); - } - }, [me, categoryStore, handleError]); if (me === null) return ; diff --git a/src/pages/profile/components/UpdateUserContactsForm/UpdateUserContactsForm.tsx b/src/pages/profile/components/UpdateUserContactsForm/UpdateUserContactsForm.tsx index 08756e6..b796ccd 100644 --- a/src/pages/profile/components/UpdateUserContactsForm/UpdateUserContactsForm.tsx +++ b/src/pages/profile/components/UpdateUserContactsForm/UpdateUserContactsForm.tsx @@ -53,7 +53,7 @@ const UpdateUserContactsForm: React.FC = ({ contact
- + My Contacts diff --git a/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx b/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx index a3fce50..979ec1e 100644 --- a/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx +++ b/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx @@ -12,7 +12,7 @@ const UserAccountInfo: React.FC = ({ user }) => { return ( - + Account information }>