import React from 'react'; import { observer } from 'mobx-react'; import * as helpres from '@educt/helpers'; import { Redirect } from 'react-router-dom'; import { Flex, Box, Text, Heading, Button, Grid, GridItem, Divider, AvatarGroup, Avatar } from '@chakra-ui/react'; import { MdPlayCircleOutline } from 'react-icons/md'; import { Tabs, TabList, TabPanels, Tab, TabPanel } from '@chakra-ui/react'; /** * Types */ import type { IPageProps } from '@educt/interfaces'; /** * Components */ import { CourseBackgroundImage, CourseHeader, CourseHeading, CourseInfo, LessonItem, LessonList } from '.'; import { PageWrapper, PageContent } from '@educt/components/PageElements'; import LoadingPage from '@educt/components/LoadingPage'; /** * Hooks */ import { useHistory, useParams } from 'react-router-dom'; import { useFetchCourse } from '@educt/hooks/queries'; import { useRootStore } from '@educt/hooks/useRootStore'; import { Helmet } from 'react-helmet'; import { EditButton } from '@educt/components/Buttons'; const CoursePage: React.FC = () => { const { userStore: { me }, } = useRootStore(); const params = useParams<{ id: string }>(); const { error, data: course, isLoading } = useFetchCourse(params.id); const history = useHistory(); if (error?.response?.status === 404) { return ; } if (!me || !course || isLoading) return ; const isCourseAvailable = helpres.userHasCourse(course, me.courses); const isEmptyLessons = course.lessons.length === 0; const isEmptyStudents = course.students.length === 0; const handleWatchCourse = () => history.push(`/lesson/${course.lessons[0].id}`); const handleEditCourse = () => history.push(`/courses/edit/${course.id}`); return ( {course.title} Last update: {new Date(course.updated_at).toLocaleDateString()} {(me.isAdmin || me.isTeacher) && } About About this course {course.description} {!isEmptyStudents ? ( Students: {course.students.map(student => ( ))} ) : ( 0 students )} What you'll learn. {course.education_description} Content {course.lessons_count} lessons {!isEmptyLessons ? ( ) : ( There are no lessons here yet )} ); }; export default observer(CoursePage);