From e8ca606a20646e1b8ea49e2ecec1f25a41190c65 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Thu, 9 Sep 2021 20:52:55 +0300 Subject: [PATCH] feat: added course list in profile page --- src/interfaces/index.ts | 21 +++++- .../components/CourseList/CourseItem.tsx | 43 ++++++++++++ .../components/CourseList/CourseList.tsx | 24 +++++++ .../profile/components/CourseList/index.ts | 3 + .../UpdateUserContactsForm.tsx | 2 +- .../UserAccountInfo/UserAccountInfo.tsx | 2 +- src/pages/profile/index.tsx | 65 +++++++++---------- src/stores/UserStore.ts | 2 +- 8 files changed, 125 insertions(+), 37 deletions(-) create mode 100644 src/pages/profile/components/CourseList/CourseItem.tsx create mode 100644 src/pages/profile/components/CourseList/CourseList.tsx create mode 100644 src/pages/profile/components/CourseList/index.ts diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index c0a7a84..f9d79f2 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -19,6 +19,9 @@ export interface ICourse { category: ICategory; lessons: ILesson[]; students: Pick; + students_count: string; + likes_count: string; + lessons_count: string; created_at: string; updated_at: string; } @@ -36,6 +39,22 @@ export interface ICategory { description: string; } +/** + * User with available course + */ +export type UserCourseType = Pick< + ICourse, + | 'id' + | 'title' + | 'description' + | 'category' + | 'students_count' + | 'likes_count' + | 'lessons_count' + | 'created_at' + | 'updated_at' +>; + export interface IUser { id: string; fullname: string; @@ -44,7 +63,7 @@ export interface IUser { email: string; roles: IUserRole[]; contacts: IUserContacts | null; - courses: Pick[]; + courses: UserCourseType[]; } export interface IUserContacts { diff --git a/src/pages/profile/components/CourseList/CourseItem.tsx b/src/pages/profile/components/CourseList/CourseItem.tsx new file mode 100644 index 0000000..2e19976 --- /dev/null +++ b/src/pages/profile/components/CourseList/CourseItem.tsx @@ -0,0 +1,43 @@ +import React from 'react'; +import { Text, Badge, Link, Box, Flex } from '@chakra-ui/layout'; +import { Link as ReactRouterLink } from 'react-router-dom'; +import { MdVideoLibrary, MdGroup, MdThumbUp } from 'react-icons/md'; +import { UserCourseType } from 'interfaces'; + +type CourseItemPropsType = { + course: UserCourseType; +}; + +const CourseItem: React.FC = ({ course }) => { + return ( + + + + {course.title} + + + + {course.category.title} + + + + {course.description} + + + + {course.lessons_count} lessons + + + + {course.students_count} students + + + + {course.likes_count} likes + + + + ); +}; + +export default CourseItem; diff --git a/src/pages/profile/components/CourseList/CourseList.tsx b/src/pages/profile/components/CourseList/CourseList.tsx new file mode 100644 index 0000000..534d6a7 --- /dev/null +++ b/src/pages/profile/components/CourseList/CourseList.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import { IUser } from 'interfaces'; +import { Stack, StackDivider } from '@chakra-ui/layout'; +import CourseItem from './CourseItem'; + +type CourseListPropsType = { + courses: IUser['courses']; +}; + +/** + * Render the course list on profile page + * in "Available courses" tab + */ +const CourseList: React.FC = ({ courses }) => { + return ( + }> + {courses.map(course => ( + + ))} + + ); +}; + +export default CourseList; diff --git a/src/pages/profile/components/CourseList/index.ts b/src/pages/profile/components/CourseList/index.ts new file mode 100644 index 0000000..0b4872f --- /dev/null +++ b/src/pages/profile/components/CourseList/index.ts @@ -0,0 +1,3 @@ +import CourseList from './CourseList'; + +export default CourseList; diff --git a/src/pages/profile/components/UpdateUserContactsForm/UpdateUserContactsForm.tsx b/src/pages/profile/components/UpdateUserContactsForm/UpdateUserContactsForm.tsx index afc8c1b..08756e6 100644 --- a/src/pages/profile/components/UpdateUserContactsForm/UpdateUserContactsForm.tsx +++ b/src/pages/profile/components/UpdateUserContactsForm/UpdateUserContactsForm.tsx @@ -52,7 +52,7 @@ const UpdateUserContactsForm: React.FC = ({ contact return (
- + My Contacts diff --git a/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx b/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx index 5044f8c..0ae4166 100644 --- a/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx +++ b/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx @@ -11,7 +11,7 @@ const UserAccountInfo: React.FC = ({ user }) => { const { setStatusPageView } = useContext(ProfilePageViewContext); return ( - + Account information diff --git a/src/pages/profile/index.tsx b/src/pages/profile/index.tsx index 6ec04ed..fbac1c4 100644 --- a/src/pages/profile/index.tsx +++ b/src/pages/profile/index.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useState } from 'react'; +import { observer } from 'mobx-react'; import { Box, Heading, @@ -11,24 +12,42 @@ import { Tab, TabPanels, TabPanel, - Stack, - StackDivider, } from '@chakra-ui/react'; -import { IPageProps } from 'interfaces'; -import { ProfilePageStatusType } from 'types'; -import { useRootStore } from 'hooks/useRootStore'; -import { useHistory } from 'react-router-dom'; -import { observer } from 'mobx-react'; -import { ProfilePageViewContext } from 'contexts'; import { userHasRoles } from 'helpers'; + +/** + * Types + */ +import { ProfilePageStatusType } from 'types'; +import { IPageProps } from 'interfaces'; +import { UserRoleEnum } from 'enums'; + +/** + * Components + */ +import CourseList from './components/CourseList'; import UserBadge from 'components/UserBadge'; import LoadingPage from './components/LoadingPage'; import UserAccountInfo from './components/UserAccountInfo'; import UpdateUserContactsForm from './components/UpdateUserContactsForm'; + +/** + * Containers + */ import UpdatePasswordContainer from './containers/UpdatePasswordContainer'; import UpdateEmailContainer from './containers/UpdateEmailContainer'; import ConfirmEmailContainer from './containers/ConfirmEmailContainer'; -import { UserRoleEnum } from 'enums'; + +/** + * Hooks + */ +import { useRootStore } from 'hooks/useRootStore'; +import { useHistory } from 'react-router-dom'; + +/** + * Contexts + */ +import { ProfilePageViewContext } from 'contexts'; /** * Profile page @@ -117,35 +136,15 @@ const ProfilePage: React.FC = () => { {isStudent && Available courses} - + - + {isStudent && ( - - - }> - {userStore.me.courses.map(course => ( - { - history.push(`/course/${course.id}`); - }} - > - - {course.title} - - {course.description} - - ))} - - + + )} diff --git a/src/stores/UserStore.ts b/src/stores/UserStore.ts index 43d975c..c3e2460 100644 --- a/src/stores/UserStore.ts +++ b/src/stores/UserStore.ts @@ -47,7 +47,7 @@ export default class UserStore { data: { id, first_name, last_name, email, roles, contacts, courses }, } = result; - console.log(result); + console.log(`[UserStore]: Fetched authorized user data.`, result); runInAction(() => { this.me = {