From d29de7833388513f9f43d42513de4b165c309700 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 11 Apr 2020 23:29:22 +0300 Subject: [PATCH] ManageCoursePage --- src/components/courses/ManageCoursePage.js | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/components/courses/ManageCoursePage.js diff --git a/src/components/courses/ManageCoursePage.js b/src/components/courses/ManageCoursePage.js new file mode 100644 index 0000000..a0c591a --- /dev/null +++ b/src/components/courses/ManageCoursePage.js @@ -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 ( + <> +

Manage course

+ + ); + } +} + +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);