Skip to content

Commit

Permalink
Merge branch 'master' into rs-app-2497
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphajax committed Sep 2, 2024
2 parents 384ece8 + 959e354 commit b0192f3
Show file tree
Hide file tree
Showing 13 changed files with 433 additions and 92 deletions.
111 changes: 110 additions & 1 deletion client/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3777,6 +3777,31 @@ export interface MentorRegistryDto {
*/
'comment': string | null;
}
/**
*
* @export
* @interface MentorReviewAssignDto
*/
export interface MentorReviewAssignDto {
/**
*
* @type {number}
* @memberof MentorReviewAssignDto
*/
'courseTaskId': number;
/**
*
* @type {number}
* @memberof MentorReviewAssignDto
*/
'mentorId': number;
/**
*
* @type {number}
* @memberof MentorReviewAssignDto
*/
'studentId': number;
}
/**
*
* @export
Expand All @@ -3790,11 +3815,17 @@ export interface MentorReviewDto {
*/
'id': number;
/**
* Task name
* Course task name
* @type {string}
* @memberof MentorReviewDto
*/
'taskName': string;
/**
* Course task id
* @type {number}
* @memberof MentorReviewDto
*/
'taskId': number;
/**
* Task solution url
* @type {string}
Expand Down Expand Up @@ -3831,6 +3862,12 @@ export interface MentorReviewDto {
* @memberof MentorReviewDto
*/
'student': string;
/**
* Student id
* @type {number}
* @memberof MentorReviewDto
*/
'studentId': number;
/**
* Task solution review date
* @type {string}
Expand Down Expand Up @@ -13379,6 +13416,45 @@ export class GratitudesApi extends BaseAPI {
*/
export const MentorReviewsApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
*
* @param {number} courseId
* @param {MentorReviewAssignDto} mentorReviewAssignDto
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
assignReviewer: async (courseId: number, mentorReviewAssignDto: MentorReviewAssignDto, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'courseId' is not null or undefined
assertParamExists('assignReviewer', 'courseId', courseId)
// verify required parameter 'mentorReviewAssignDto' is not null or undefined
assertParamExists('assignReviewer', 'mentorReviewAssignDto', mentorReviewAssignDto)
const localVarPath = `/course/{courseId}/mentor-reviews`
.replace(`{${"courseId"}}`, encodeURIComponent(String(courseId)));
// 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: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;



localVarHeaderParameter['Content-Type'] = 'application/json';

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

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @param {string} current
Expand Down Expand Up @@ -13456,6 +13532,17 @@ export const MentorReviewsApiAxiosParamCreator = function (configuration?: Confi
export const MentorReviewsApiFp = function(configuration?: Configuration) {
const localVarAxiosParamCreator = MentorReviewsApiAxiosParamCreator(configuration)
return {
/**
*
* @param {number} courseId
* @param {MentorReviewAssignDto} mentorReviewAssignDto
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async assignReviewer(courseId: number, mentorReviewAssignDto: MentorReviewAssignDto, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.assignReviewer(courseId, mentorReviewAssignDto, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @param {string} current
Expand All @@ -13482,6 +13569,16 @@ export const MentorReviewsApiFp = function(configuration?: Configuration) {
export const MentorReviewsApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
const localVarFp = MentorReviewsApiFp(configuration)
return {
/**
*
* @param {number} courseId
* @param {MentorReviewAssignDto} mentorReviewAssignDto
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
assignReviewer(courseId: number, mentorReviewAssignDto: MentorReviewAssignDto, options?: any): AxiosPromise<void> {
return localVarFp.assignReviewer(courseId, mentorReviewAssignDto, options).then((request) => request(axios, basePath));
},
/**
*
* @param {string} current
Expand All @@ -13507,6 +13604,18 @@ export const MentorReviewsApiFactory = function (configuration?: Configuration,
* @extends {BaseAPI}
*/
export class MentorReviewsApi extends BaseAPI {
/**
*
* @param {number} courseId
* @param {MentorReviewAssignDto} mentorReviewAssignDto
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof MentorReviewsApi
*/
public assignReviewer(courseId: number, mentorReviewAssignDto: MentorReviewAssignDto, options?: AxiosRequestConfig) {
return MentorReviewsApiFp(this.configuration).assignReviewer(courseId, mentorReviewAssignDto, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @param {string} current
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/UserSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function UserSearch(props: UserProps) {
{...otherProps}
defaultValue={undefined}
defaultActiveFirstOption={false}
showArrow={defaultValues ? Boolean(defaultValues.length) : false}
suffixIcon={defaultValues ? Boolean(defaultValues.length) : false}
filterOption={false}
onSearch={handleSearch}
placeholder={defaultValues?.length ?? 0 > 0 ? 'Select...' : 'Search...'}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Col, Form, Row, Typography } from 'antd';
import React, { useState } from 'react';
import { ModalSubmitForm } from 'components/Forms/ModalSubmitForm';
import { MentorReviewDto, MentorReviewsApi } from 'api';
import isEmpty from 'lodash/isEmpty';
import { MentorSearch } from 'components/MentorSearch';
import { useActiveCourseContext } from 'modules/Course/contexts';
import { useLoading } from 'components/useLoading';

const mentorReviewsApi = new MentorReviewsApi();

export interface AssignReviewerModalProps {
review: MentorReviewDto | null;
onClose: () => void;
onSubmit: () => void;
}

const { Link } = Typography;

const MODAL_TITLE = 'Assign Reviewer for';
const SUCCESS_MESSAGE = 'Reviewer has been successfully assigned';

function AssignReviewerModal({ review, onClose, onSubmit }: AssignReviewerModalProps) {
const { course } = useActiveCourseContext();
const [loading, withLoading] = useLoading(false);

const [submitted, setSubmitted] = useState(false);
const [errorText, setErrorText] = useState('');

const courseId = course.id;
const { solutionUrl, taskDescriptionUrl, taskName, student, taskId, studentId } = review || {};

const assignReviewer = withLoading(async (courseId, courseTaskId, mentorId, studentId) => {
await mentorReviewsApi.assignReviewer(courseId, { courseTaskId, mentorId, studentId });
});

const handleSubmit = async (values: any) => {
const { mentorId } = values;
try {
if (mentorId) {
await assignReviewer(course.id, taskId, mentorId, studentId);
setSubmitted(true);
onSubmit();
}
} catch (e: any) {
const error = e.response?.data?.message ?? e.message;
setErrorText(error);
}
};

const handleClose = () => {
setErrorText('');
setSubmitted(false);
onClose();
};

return (
<ModalSubmitForm
title={`${MODAL_TITLE} ${student}`}
data={review}
submit={handleSubmit}
close={handleClose}
errorText={errorText}
loading={loading}
submitted={submitted}
successText={SUCCESS_MESSAGE}
open={!isEmpty(review)}
>
<Row>
<Col span={18} offset={3}>
<Form.Item label="Task Name">
<Link href={taskDescriptionUrl} target="_blank">
{taskName}
</Link>
</Form.Item>
<Form.Item label="Submitted Link">
<Link href={solutionUrl} target="_blank">
{solutionUrl}
</Link>
</Form.Item>
<Form.Item name="mentorId" rules={[{ required: true, message: 'Please select mentor' }]} label="Mentor">
<MentorSearch keyField="id" courseId={courseId} />
</Form.Item>
</Col>
</Row>
</ModalSubmitForm>
);
}

export default AssignReviewerModal;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './AssignReviewerModal';
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
import { Table, TablePaginationConfig, TableProps } from 'antd';
import { CourseTaskDto, MentorReviewDto } from 'api';
import { getColumns } from './renderers';
import AssignReviewerModal from '../AssignReviewerModal';
import { useState } from 'react';

type Props = {
content: MentorReviewDto[];
pagination: false | TablePaginationConfig;
handleChange?: TableProps<MentorReviewDto>['onChange'];
handleReviewerAssigned: () => void;
loading?: boolean;
tasks: CourseTaskDto[];
isManager: boolean;
};

export default function MentorReviewsTable({ content, pagination, handleChange, loading, tasks }: Props) {
export default function MentorReviewsTable({
content,
pagination,
handleChange,
handleReviewerAssigned,
loading,
tasks,
isManager,
}: Props) {
const [modalData, setModalData] = useState<MentorReviewDto | null>(null);

const handleClick = (review: MentorReviewDto) => setModalData(review);
const handleClose = () => setModalData(null);

return (
<Table<MentorReviewDto>
showHeader
dataSource={content}
size="small"
columns={getColumns(tasks)}
onChange={handleChange}
rowKey="id"
pagination={pagination}
loading={loading}
/>
<>
<Table<MentorReviewDto>
showHeader
dataSource={content}
size="small"
columns={getColumns(tasks, handleClick, isManager)}
onChange={handleChange}
rowKey="id"
pagination={pagination}
loading={loading}
/>
<AssignReviewerModal review={modalData} onClose={handleClose} onSubmit={handleReviewerAssigned} />
</>
);
}
Loading

0 comments on commit b0192f3

Please sign in to comment.