ManageCoursePage
parent
210b0885a1
commit
d29de78333
|
@ -0,0 +1,59 @@
|
|||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { loadCourses } from "../../redux/actions/courseActions";
|
||||
import { loadAuthors } from "../../redux/actions/authorActions";
|
||||
import PropTypes from "prop-types";
|
||||
import { bindActionCreators } from "redux";
|
||||
|
||||
class ManageCoursePage extends React.Component {
|
||||
componentDidMount() {
|
||||
const { courses, authors, actions } = this.props;
|
||||
|
||||
if (courses.length === 0) {
|
||||
actions.loadCourses().catch((error) => {
|
||||
alert("Loading courses failed. " + error);
|
||||
});
|
||||
}
|
||||
|
||||
if (authors.length === 0) {
|
||||
actions.loadAuthors().catch((error) => {
|
||||
alert("Loading authors failed. " + error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
<h2>Manage course</h2>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ManageCoursePage.propTypes = {
|
||||
courses: PropTypes.array.isRequired,
|
||||
authors: PropTypes.array.isRequired,
|
||||
actions: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
courses: state.courses,
|
||||
authors: state.authors
|
||||
};
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators(
|
||||
{
|
||||
loadCourses,
|
||||
loadAuthors
|
||||
},
|
||||
dispatch
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ManageCoursePage);
|
Loading…
Reference in New Issue