-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into rs-app-2497
- Loading branch information
Showing
13 changed files
with
433 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
client/src/modules/MentorTasksReview/components/AssignReviewerModal/AssignReviewerModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
1 change: 1 addition & 0 deletions
1
client/src/modules/MentorTasksReview/components/AssignReviewerModal/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './AssignReviewerModal'; |
42 changes: 31 additions & 11 deletions
42
client/src/modules/MentorTasksReview/components/ReviewsTable/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> | ||
</> | ||
); | ||
} |
Oops, something went wrong.