Skip to content

Commit

Permalink
feat: create students list page (#2503)
Browse files Browse the repository at this point in the history
* feat: create students list page

* fix: lint

* fix: review
  • Loading branch information
valerydluski authored Jul 7, 2024
1 parent 3e61912 commit c3acac8
Show file tree
Hide file tree
Showing 17 changed files with 781 additions and 41 deletions.
209 changes: 209 additions & 0 deletions client/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7015,6 +7015,99 @@ export interface UserNotificationsDto {
*/
'connections': object;
}
/**
*
* @export
* @interface UserStudentCourseDto
*/
export interface UserStudentCourseDto {
/**
*
* @type {string}
* @memberof UserStudentCourseDto
*/
'alias': string;
/**
*
* @type {string}
* @memberof UserStudentCourseDto
*/
'name': string;
/**
*
* @type {boolean}
* @memberof UserStudentCourseDto
*/
'hasCertificate': boolean;
}
/**
*
* @export
* @interface UserStudentDto
*/
export interface UserStudentDto {
/**
* User id
* @type {number}
* @memberof UserStudentDto
*/
'id': number;
/**
* User github id
* @type {string}
* @memberof UserStudentDto
*/
'githubId': string;
/**
* User full name
* @type {string}
* @memberof UserStudentDto
*/
'fullName': string;
/**
* User country
* @type {object}
* @memberof UserStudentDto
*/
'country': object;
/**
* User city
* @type {object}
* @memberof UserStudentDto
*/
'city': object;
/**
* User on going courses
* @type {Array<UserStudentCourseDto>}
* @memberof UserStudentDto
*/
'onGoingCourses': Array<UserStudentCourseDto>;
/**
* User previous courses
* @type {Array<UserStudentCourseDto>}
* @memberof UserStudentDto
*/
'previousCourses': Array<UserStudentCourseDto>;
}
/**
*
* @export
* @interface UserStudentsDto
*/
export interface UserStudentsDto {
/**
*
* @type {Array<UserStudentDto>}
* @memberof UserStudentsDto
*/
'content': Array<UserStudentDto>;
/**
*
* @type {PaginationMetaDto}
* @memberof UserStudentsDto
*/
'pagination': PaginationMetaDto;
}
/**
*
* @export
Expand Down Expand Up @@ -15738,6 +15831,74 @@ export const StudentsApiAxiosParamCreator = function (configuration?: Configurat



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @param {string} current
* @param {string} pageSize
* @param {string} [student]
* @param {string} [country]
* @param {string} [city]
* @param {string} [ongoingCourses]
* @param {string} [previousCourses]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getUserStudents: async (current: string, pageSize: string, student?: string, country?: string, city?: string, ongoingCourses?: string, previousCourses?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'current' is not null or undefined
assertParamExists('getUserStudents', 'current', current)
// verify required parameter 'pageSize' is not null or undefined
assertParamExists('getUserStudents', 'pageSize', pageSize)
const localVarPath = `/students`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

if (current !== undefined) {
localVarQueryParameter['current'] = current;
}

if (pageSize !== undefined) {
localVarQueryParameter['pageSize'] = pageSize;
}

if (student !== undefined) {
localVarQueryParameter['student'] = student;
}

if (country !== undefined) {
localVarQueryParameter['country'] = country;
}

if (city !== undefined) {
localVarQueryParameter['city'] = city;
}

if (ongoingCourses !== undefined) {
localVarQueryParameter['ongoingCourses'] = ongoingCourses;
}

if (previousCourses !== undefined) {
localVarQueryParameter['previousCourses'] = previousCourses;
}



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Expand Down Expand Up @@ -15767,6 +15928,22 @@ export const StudentsApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.getStudent(studentId, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @param {string} current
* @param {string} pageSize
* @param {string} [student]
* @param {string} [country]
* @param {string} [city]
* @param {string} [ongoingCourses]
* @param {string} [previousCourses]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getUserStudents(current: string, pageSize: string, student?: string, country?: string, city?: string, ongoingCourses?: string, previousCourses?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<UserStudentsDto>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getUserStudents(current, pageSize, student, country, city, ongoingCourses, previousCourses, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
}
};

Expand All @@ -15786,6 +15963,21 @@ export const StudentsApiFactory = function (configuration?: Configuration, baseP
getStudent(studentId: number, options?: any): AxiosPromise<StudentDto> {
return localVarFp.getStudent(studentId, options).then((request) => request(axios, basePath));
},
/**
*
* @param {string} current
* @param {string} pageSize
* @param {string} [student]
* @param {string} [country]
* @param {string} [city]
* @param {string} [ongoingCourses]
* @param {string} [previousCourses]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getUserStudents(current: string, pageSize: string, student?: string, country?: string, city?: string, ongoingCourses?: string, previousCourses?: string, options?: any): AxiosPromise<UserStudentsDto> {
return localVarFp.getUserStudents(current, pageSize, student, country, city, ongoingCourses, previousCourses, options).then((request) => request(axios, basePath));
},
};
};

Expand All @@ -15806,6 +15998,23 @@ export class StudentsApi extends BaseAPI {
public getStudent(studentId: number, options?: AxiosRequestConfig) {
return StudentsApiFp(this.configuration).getStudent(studentId, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @param {string} current
* @param {string} pageSize
* @param {string} [student]
* @param {string} [country]
* @param {string} [city]
* @param {string} [ongoingCourses]
* @param {string} [previousCourses]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof StudentsApi
*/
public getUserStudents(current: string, pageSize: string, student?: string, country?: string, city?: string, ongoingCourses?: string, previousCourses?: string, options?: AxiosRequestConfig) {
return StudentsApiFp(this.configuration).getUserStudents(current, pageSize, student, country, city, ongoingCourses, previousCourses, options).then((request) => request(this.axios, this.basePath));
}
}


Expand Down
5 changes: 3 additions & 2 deletions client/src/components/GithubUserLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { GithubAvatar } from './GithubAvatar';
type Props = {
value: string;
isUserIconHidden?: boolean;
fullName?: string;
};

export function GithubUserLink({ value, isUserIconHidden = false }: Props) {
export function GithubUserLink({ value, isUserIconHidden = false, fullName }: Props) {
return (
<div className="link-user">
<a target="_blank" className="link-user-profile" href={`/profile?githubId=${value}`}>
Expand All @@ -15,7 +16,7 @@ export function GithubUserLink({ value, isUserIconHidden = false }: Props) {
<GithubAvatar githubId={value} size={24} />{' '}
</>
)}
{value}
{fullName || value}
</a>{' '}
<a target="_blank" className="link-user-github" href={`https://github.com/${value}`}>
<GithubFilled />
Expand Down
8 changes: 8 additions & 0 deletions client/src/components/Sider/data/menuItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ProfileFilled from '@ant-design/icons/ProfileFilled';
import TeamOutlined from '@ant-design/icons/TeamOutlined';
import UserOutlined from '@ant-design/icons/UserOutlined';
import FileTextOutlined from '@ant-design/icons/FileTextOutlined';
import QqOutlined from '@ant-design/icons/QqOutlined';
import { DiscordOutlined } from 'components/Icons/DiscordOutlined';
import { Session } from 'components/withSession';
import {
Expand Down Expand Up @@ -136,6 +137,13 @@ const adminMenuItems: AdminMenuItemsData[] = [
href: '/admin/prompts',
access: session => isAdmin(session),
},
{
name: 'Students',
key: 'students',
icon: <QqOutlined />,
href: '/admin/students',
access: session => isAdmin(session) || isHirer(session),
},
];

export function getAdminMenuItems(session: Session): MenuItemsRenderData[] {
Expand Down
41 changes: 19 additions & 22 deletions client/src/modules/Course/contexts/SessionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ type Props = React.PropsWithChildren<{
course?: ProfileCourseDto;
adminOnly?: boolean;
anyCoursePowerUser?: boolean;
hirerOnly?: boolean;
}>;

const AccessDeniedWarning = () => (
<Result
status="warning"
title="You don't have required role to access this page"
extra={
<Button type="primary" key="console" onClick={() => window.history.back()}>
Go Back
</Button>
}
/>
);

export function SessionProvider(props: Props) {
const { allowedRoles, anyCoursePowerUser } = props;
const activeCourse = useActiveCourseContext().course;
Expand Down Expand Up @@ -49,17 +62,11 @@ export function SessionProvider(props: Props) {
}, [error]);

if (session && props.adminOnly && !session.isAdmin) {
return (
<Result
status="warning"
title="You don't have required role to access this page"
extra={
<Button type="primary" key="console" onClick={() => window.history.back()}>
Go Back
</Button>
}
/>
);
return <AccessDeniedWarning />;
}

if (session && props.hirerOnly && !session.isHirer && !session.isAdmin) {
return <AccessDeniedWarning />;
}

if (session && allowedRoles && course) {
Expand All @@ -72,17 +79,7 @@ export function SessionProvider(props: Props) {
const isAnyCoursePowerUser = anyCoursePowerUser && allowedRoles.some(role => hasRoleInAnyCourse(session, role));

if (!hasRoleInCurrentCourse && !isAnyCoursePowerUser) {
return (
<Result
status="warning"
title="You don't have required role to access this page"
extra={
<Button type="primary" key="console" onClick={() => window.history.back()}>
Go Back
</Button>
}
/>
);
return <AccessDeniedWarning />;
}
}
}
Expand Down
Loading

0 comments on commit c3acac8

Please sign in to comment.