mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 10:19:22 +03:00
refactor: user badge && user interface type
This commit is contained in:
parent
e8ca606a20
commit
5a510d77d2
@ -8,30 +8,25 @@ import { userHasRoles } from 'helpers';
|
|||||||
* Returns the badge for user based on roles
|
* Returns the badge for user based on roles
|
||||||
*/
|
*/
|
||||||
const UserBadge: React.FC<{ roles: IUserRole[] }> = ({ 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 (
|
return (
|
||||||
<Badge colorScheme='purple' variant='subtle'>
|
<Badge colorScheme={role.color} variant='subtle'>
|
||||||
Administrator
|
{role.name}
|
||||||
</Badge>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userHasRoles(roles, [UserRoleEnum.TEACHER])) {
|
|
||||||
return (
|
|
||||||
<Badge colorScheme='orange' variant='subtle'>
|
|
||||||
Teacher
|
|
||||||
</Badge>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userHasRoles(roles, [UserRoleEnum.STUDENT])) {
|
|
||||||
return (
|
|
||||||
<Badge colorScheme='orange' variant='subtle'>
|
|
||||||
Student
|
|
||||||
</Badge>
|
</Badge>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cannot find any role for user
|
||||||
|
*/
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -63,7 +63,11 @@ export interface IUser {
|
|||||||
email: string;
|
email: string;
|
||||||
roles: IUserRole[];
|
roles: IUserRole[];
|
||||||
contacts: IUserContacts | null;
|
contacts: IUserContacts | null;
|
||||||
courses: UserCourseType[];
|
/**
|
||||||
|
* The field can be undefined if the user
|
||||||
|
* does not have the STUDENT role
|
||||||
|
*/
|
||||||
|
courses?: UserCourseType[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IUserContacts {
|
export interface IUserContacts {
|
||||||
|
|||||||
@ -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
|
* in "Available courses" tab
|
||||||
*/
|
*/
|
||||||
const CourseList: React.FC<CourseListPropsType> = ({ courses }) => {
|
const CourseList: React.FC<CourseListPropsType> = ({ courses }) => {
|
||||||
|
if (courses === undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing='8' divider={<StackDivider />}>
|
<Stack spacing='8' divider={<StackDivider />}>
|
||||||
{courses.map(course => (
|
{courses.map(course => (
|
||||||
|
|||||||
@ -10,7 +10,11 @@ import { useErrorHandler } from 'react-error-boundary';
|
|||||||
import { ProfilePageViewContext } from 'contexts';
|
import { ProfilePageViewContext } from 'contexts';
|
||||||
import useIsMountedRef from 'hooks/useIsMountedRef';
|
import useIsMountedRef from 'hooks/useIsMountedRef';
|
||||||
|
|
||||||
const ConfirmEmailContainer: React.FC<{ data: ConfirmEmailContainerDataType }> = ({ data }) => {
|
type ConfirmEmailContainerPropsType = {
|
||||||
|
data: ConfirmEmailContainerDataType;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ConfirmEmailContainer: React.FC<ConfirmEmailContainerPropsType> = ({ data }) => {
|
||||||
const { userStore } = useRootStore();
|
const { userStore } = useRootStore();
|
||||||
const { setStatusPageView } = useContext(ProfilePageViewContext);
|
const { setStatusPageView } = useContext(ProfilePageViewContext);
|
||||||
const { sendConfirmationCode, loading } = useUpdateUserEmailQuery();
|
const { sendConfirmationCode, loading } = useUpdateUserEmailQuery();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user