diff --git a/src/components/UserBadge/UserBadge.tsx b/src/components/UserBadge/UserBadge.tsx index 19fb6a7..d82c004 100644 --- a/src/components/UserBadge/UserBadge.tsx +++ b/src/components/UserBadge/UserBadge.tsx @@ -25,7 +25,11 @@ const UserBadge: React.FC<{ roles: IUserRole[] }> = ({ roles }) => { } if (userHasRoles(roles, [UserRoleEnum.STUDENT])) { - return Student; + return ( + + Student + + ); } return null; diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index 3f1f3b1..c0a7a84 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -11,6 +11,31 @@ export interface IAppConfig { links: LinkType[]; } +export interface ICourse { + id: string; + title: string; + description: string; + teacher: Pick; + category: ICategory; + lessons: ILesson[]; + students: Pick; + created_at: string; + updated_at: string; +} + +export interface ILesson { + id: string; + course_id: string; + title: string; + description: string; +} + +export interface ICategory { + id: string; + title: string; + description: string; +} + export interface IUser { id: string; fullname: string; @@ -19,6 +44,7 @@ export interface IUser { email: string; roles: IUserRole[]; contacts: IUserContacts | null; + courses: Pick[]; } export interface IUserContacts { diff --git a/src/pages/profile/index.tsx b/src/pages/profile/index.tsx index a2e8765..6ec04ed 100644 --- a/src/pages/profile/index.tsx +++ b/src/pages/profile/index.tsx @@ -11,6 +11,8 @@ import { Tab, TabPanels, TabPanel, + Stack, + StackDivider, } from '@chakra-ui/react'; import { IPageProps } from 'interfaces'; import { ProfilePageStatusType } from 'types'; @@ -18,6 +20,7 @@ import { useRootStore } from 'hooks/useRootStore'; import { useHistory } from 'react-router-dom'; import { observer } from 'mobx-react'; import { ProfilePageViewContext } from 'contexts'; +import { userHasRoles } from 'helpers'; import UserBadge from 'components/UserBadge'; import LoadingPage from './components/LoadingPage'; import UserAccountInfo from './components/UserAccountInfo'; @@ -25,6 +28,7 @@ import UpdateUserContactsForm from './components/UpdateUserContactsForm'; import UpdatePasswordContainer from './containers/UpdatePasswordContainer'; import UpdateEmailContainer from './containers/UpdateEmailContainer'; import ConfirmEmailContainer from './containers/ConfirmEmailContainer'; +import { UserRoleEnum } from 'enums'; /** * Profile page @@ -45,6 +49,8 @@ const ProfilePage: React.FC = () => { return ; } + const isStudent = userHasRoles(userStore.me.roles, [UserRoleEnum.STUDENT]); + return ( {statusPageView.status === 'default' && ( @@ -108,6 +114,7 @@ const ProfilePage: React.FC = () => { Account information My contacts + {isStudent && Available courses} @@ -116,6 +123,31 @@ const ProfilePage: React.FC = () => { + {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 0b2a69e..43d975c 100644 --- a/src/stores/UserStore.ts +++ b/src/stores/UserStore.ts @@ -44,9 +44,11 @@ export default class UserStore { try { const result = await this.userService.fetchMe(); const { - data: { id, first_name, last_name, email, roles, contacts }, + data: { id, first_name, last_name, email, roles, contacts, courses }, } = result; + console.log(result); + runInAction(() => { this.me = { id, @@ -56,6 +58,7 @@ export default class UserStore { email, roles, contacts, + courses, }; });