Newer
Older
import DegreeCourseItem from "./DegreeCourseItem";
import DeleteDegreeCourseModal from './DeleteDegreeCourseModal'
import EditDegreeCourse from './EditDegreeCourse'
import CreateNewDegreeCourse from './CreateNewDegreeCourse'
import CreateNewApplication from '../ApplicationComponents/CreateNewApplication'
import addIcon from '../../icons/addIcon.png'
import Button from "react-bootstrap/esm/Button";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as degreeCourseManagementActions from '../../actions/DegreeCourseManagementActions'
const mapStateToProps = state => {
return {
showDeleteDegreeCourseModal: state.DegreeCourseReducer.showDeleteDegreeCourseModal,
degreeCourseList: state.DegreeCourseReducer.degreeCourseList,
isAdmin: state.AuthenticationReducer.isAdmin
};
}
const DISPLAY = {
LIST: "list",
EDIT: "edit",
class DegreeCourseManagement extends Component {
constructor(props) {
super(props);
this.state = {
displayingPage: DISPLAY.LIST,
}
this.MapAllDegreeCourses = this.MapAllDegreeCourses.bind(this);
this.handleShowDeleteModal = this.handleShowDeleteModal.bind(this);
this.handleClose = this.handleClose.bind(this);
this.handleSwitchToList = this.handleSwitchToList.bind(this);
this.handleShowCreatePage = this.handleShowCreatePage.bind(this);
this.handleShowEditPage = this.handleShowEditPage.bind(this);
this.handleShowCreateApplication = this.handleShowCreateApplication.bind(this);
}
handleShowDeleteModal(e, dialogModalData) {
e.preventDefault();
const { showDeleteDegreeCourseModalAction } = this.props
showDeleteDegreeCourseModalAction(dialogModalData)
}
handleShowEditPage(e, degreeCourse) {
e.preventDefault();
{
currentDegreeCourse: degreeCourse,
displayingPage: DISPLAY.EDIT
})
}
handleShowCreatePage(e) {
e.preventDefault();
this.setState({ displayingPage: DISPLAY.CREATE })
}
handleSwitchToList() {
this.setState({ displayingPage: DISPLAY.LIST })
}
handleClose() {
const { hideDeleteDegreeCourseModalAction } = this.props;
hideDeleteDegreeCourseModalAction();
}
handleShowCreateApplication(e, degreeCourse) {
e.preventDefault();
this.setState(
{
currentDegreeCourse: degreeCourse,
displayingPage: DISPLAY.APPLICATION
})
}
MapAllDegreeCourses() {
const allDegreeCourses = this.props.degreeCourseList
if (allDegreeCourses) {
var showDeleteDegreeCourseModal = this.props.showDeleteDegreeCourseModal
if (showDeleteDegreeCourseModal === undefined) {
showDeleteDegreeCourseModal = false
}
console.log("deleteModal:" + showDeleteDegreeCourseModal)
var degreeCourses = allDegreeCourses.map(degreeCourse => {
return (
<DegreeCourseItem key={degreeCourse.id} degreeCourse={degreeCourse} handleShowDeleteModal={this.handleShowDeleteModal} handleShowEditPage={this.handleShowEditPage} handleShowCreateApplication={this.handleShowCreateApplication} />
)
})
return degreeCourses
}
}
var addButton
if (this.props.isAdmin) {
addButton =
<Button onClick={this.handleShowCreatePage}>
<img alt="Add-DegreeCourse-Button" src={addIcon} style={{ width: '2rem' }}></img>
</Button>
}
var workspace
switch (this.state.displayingPage) {
case DISPLAY.LIST:
workspace =
<div id="DegreeCourseManagementPageListComponent">
{this.MapAllDegreeCourses()}
<DeleteDegreeCourseModal />
workspace = <CreateNewDegreeCourse goBack={this.handleSwitchToList} />
workspace = <EditDegreeCourse id="DegreeCourseManagementPageEditComponent" goBack={this.handleSwitchToList} editDegreeCourse={this.state.currentDegreeCourse} />
break
case DISPLAY.APPLICATION:
workspace = <CreateNewApplication id="" degreeCourse={this.state.currentDegreeCourse} goBack={this.handleSwitchToList} />
workspace =
<>
{addButton}
<div id="DegreeCourseManagementPageListComponent">
{this.MapAllDegreeCourses()}
<DeleteDegreeCourseModal />
</div>
</>
<div id="DegreeCourseManagementPage" style={{ height: '50vw', backgroundColor: '#2b3648', padding: '2rem' }}>
{workspace}
const mapDispatchToProps = dispatch => bindActionCreators({
showDeleteDegreeCourseModalAction: degreeCourseManagementActions.getShowDeleteDegreeCourseModalAction,
hideDeleteDegreeCourseModalAction: degreeCourseManagementActions.getHideDeleteDegreeCourseModalAction
}, dispatch)
const ConnectedDegreeCourseManagement = connect(mapStateToProps, mapDispatchToProps)(DegreeCourseManagement)
export default ConnectedDegreeCourseManagement