diff --git a/src/components/UserBadge/UserBadge.tsx b/src/components/UserBadge/UserBadge.tsx index d82c004..b450fc0 100644 --- a/src/components/UserBadge/UserBadge.tsx +++ b/src/components/UserBadge/UserBadge.tsx @@ -8,30 +8,25 @@ import { userHasRoles } from 'helpers'; * Returns the badge for user based on roles */ const UserBadge: React.FC<{ roles: IUserRole[] }> = ({ roles }) => { - if (userHasRoles(roles, [UserRoleEnum.ADMIN])) { + const getCurrentRole = () => { + if (userHasRoles(roles, [UserRoleEnum.ADMIN])) return { name: 'Administrator', color: 'purple' }; + if (userHasRoles(roles, [UserRoleEnum.TEACHER])) return { name: 'Teacher', color: 'orange' }; + if (userHasRoles(roles, [UserRoleEnum.STUDENT])) return { name: 'Student', color: 'blue' }; + }; + + const role = getCurrentRole(); + + if (role !== undefined) { return ( - - Administrator - - ); - } - - if (userHasRoles(roles, [UserRoleEnum.TEACHER])) { - return ( - - Teacher - - ); - } - - if (userHasRoles(roles, [UserRoleEnum.STUDENT])) { - return ( - - Student + + {role.name} ); } + /** + * Cannot find any role for user + */ return null; }; diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index f9d79f2..2824c18 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -63,7 +63,11 @@ export interface IUser { email: string; roles: IUserRole[]; contacts: IUserContacts | null; - courses: UserCourseType[]; + /** + * The field can be undefined if the user + * does not have the STUDENT role + */ + courses?: UserCourseType[]; } export interface IUserContacts { diff --git a/src/pages/profile/components/CourseList/CourseList.tsx b/src/pages/profile/components/CourseList/CourseList.tsx index 534d6a7..850c4a2 100644 --- a/src/pages/profile/components/CourseList/CourseList.tsx +++ b/src/pages/profile/components/CourseList/CourseList.tsx @@ -8,10 +8,14 @@ type CourseListPropsType = { }; /** - * Render the course list on profile page + * Render the course list on profile page for STUDENT role * in "Available courses" tab */ const CourseList: React.FC = ({ courses }) => { + if (courses === undefined) { + return null; + } + return ( }> {courses.map(course => ( diff --git a/src/pages/profile/containers/ConfirmEmailContainer/ConfirmEmailContainer.tsx b/src/pages/profile/containers/ConfirmEmailContainer/ConfirmEmailContainer.tsx index e16513c..2244427 100644 --- a/src/pages/profile/containers/ConfirmEmailContainer/ConfirmEmailContainer.tsx +++ b/src/pages/profile/containers/ConfirmEmailContainer/ConfirmEmailContainer.tsx @@ -10,7 +10,11 @@ import { useErrorHandler } from 'react-error-boundary'; import { ProfilePageViewContext } from 'contexts'; import useIsMountedRef from 'hooks/useIsMountedRef'; -const ConfirmEmailContainer: React.FC<{ data: ConfirmEmailContainerDataType }> = ({ data }) => { +type ConfirmEmailContainerPropsType = { + data: ConfirmEmailContainerDataType; +}; + +const ConfirmEmailContainer: React.FC = ({ data }) => { const { userStore } = useRootStore(); const { setStatusPageView } = useContext(ProfilePageViewContext); const { sendConfirmationCode, loading } = useUpdateUserEmailQuery();