-
-
Notifications
You must be signed in to change notification settings - Fork 204
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 fix/users-search-by-fullname
- Loading branch information
Showing
76 changed files
with
3,309 additions
and
1,543 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,50 @@ | ||
import { Button, Modal, Row, Typography, message } from 'antd'; | ||
import * as React from 'react'; | ||
import { Modal, Typography, message } from 'antd'; | ||
import { StudentSearch } from 'components/StudentSearch'; | ||
import { useCallback, useState } from 'react'; | ||
import { CourseService } from 'services/course'; | ||
|
||
const { Text } = Typography; | ||
|
||
type State = { | ||
isModalOpened: boolean; | ||
studentGithubId: string | null; | ||
}; | ||
|
||
type Props = { | ||
mentorGithuId: string; | ||
mentorGithuId: string | null; | ||
courseId: number; | ||
open: boolean; | ||
onClose: () => void; | ||
}; | ||
|
||
class AssignStudentModal extends React.PureComponent<Props, State> { | ||
state: State = { | ||
isModalOpened: false, | ||
studentGithubId: null, | ||
}; | ||
|
||
openModal = () => { | ||
this.setState({ isModalOpened: true }); | ||
}; | ||
|
||
closeModal = () => { | ||
this.setState({ isModalOpened: false }); | ||
}; | ||
|
||
addStudent = async () => { | ||
const { mentorGithuId } = this.props; | ||
const { studentGithubId } = this.state; | ||
export function AssignStudentModal(props: Props) { | ||
const [studentGithubId, setStudentGithubId] = useState<string | null>(null); | ||
|
||
const addStudent = useCallback(async () => { | ||
if (!studentGithubId) { | ||
return; | ||
} | ||
|
||
this.reset(); | ||
|
||
try { | ||
await new CourseService(this.props.courseId).updateStudent(studentGithubId, { mentorGithuId }); | ||
message.success('Success'); | ||
await new CourseService(props.courseId).updateStudent(studentGithubId, { mentorGithuId: props.mentorGithuId }); | ||
props.onClose(); | ||
message.success('Student has been added to mentor'); | ||
} catch (e) { | ||
message.error(`${e}`); | ||
} | ||
}; | ||
|
||
reset = () => { | ||
this.setState({ isModalOpened: false, studentGithubId: null }); | ||
}; | ||
|
||
handleStudentSelect = (githubId: string) => { | ||
this.setState({ studentGithubId: githubId ?? null }); | ||
}; | ||
|
||
render() { | ||
const { mentorGithuId, courseId } = this.props; | ||
const { isModalOpened } = this.state; | ||
|
||
return ( | ||
<> | ||
<Button type="link" shape="circle" onClick={this.openModal}> | ||
Add Student | ||
</Button> | ||
<Modal | ||
title={ | ||
<> | ||
Assign Student to <Text underline>{mentorGithuId}</Text> | ||
</> | ||
} | ||
open={isModalOpened} | ||
onOk={this.addStudent} | ||
onCancel={this.reset} | ||
> | ||
<Row> | ||
<StudentSearch | ||
style={{ width: '100%' }} | ||
keyField="githubId" | ||
onChange={this.handleStudentSelect} | ||
courseId={courseId} | ||
/> | ||
</Row> | ||
</Modal> | ||
</> | ||
); | ||
} | ||
}, [props.mentorGithuId, studentGithubId]); | ||
|
||
return ( | ||
<Modal | ||
title={ | ||
<> | ||
<Text>Assign Student to</Text> <Text underline>{props.mentorGithuId}</Text> | ||
</> | ||
} | ||
open={props.open} | ||
onOk={addStudent} | ||
onCancel={props.onClose} | ||
> | ||
<StudentSearch | ||
style={{ width: '100%' }} | ||
keyField="githubId" | ||
onChange={setStudentGithubId} | ||
courseId={props.courseId} | ||
/> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default AssignStudentModal; |
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,2 +1,2 @@ | ||
export { default as AssignStudentModal } from './AssignStudentModal'; | ||
export { AssignStudentModal } from './AssignStudentModal'; | ||
export { DashboardDetails } from './DashboardDetails'; |
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
Oops, something went wrong.