diff --git a/src/components/courses/CoursesPage.js b/src/components/courses/CoursesPage.js index 637135a..beea601 100644 --- a/src/components/courses/CoursesPage.js +++ b/src/components/courses/CoursesPage.js @@ -5,8 +5,13 @@ import * as authorActions from "../../redux/actions/authorActions"; import PropTypes from "prop-types"; import { bindActionCreators } from "redux"; import CourseList from "./CourseList"; +import { Redirect } from "react-router-dom"; class CoursesPage extends React.Component { + state = { + redirectToAddCoursePage: false + }; + componentDidMount() { const { courses, authors, actions } = this.props; @@ -26,7 +31,17 @@ class CoursesPage extends React.Component { render() { return ( <> + {this.state.redirectToAddCoursePage && }

Courses

+ + + ); diff --git a/src/components/courses/ManageCoursePage.js b/src/components/courses/ManageCoursePage.js index be4e605..37fb0fb 100644 --- a/src/components/courses/ManageCoursePage.js +++ b/src/components/courses/ManageCoursePage.js @@ -7,7 +7,7 @@ import { bindActionCreators } from "redux"; import CourseForm from "./CourseForm"; import { newCourse } from "../../../tools/mockData"; -function ManageCoursePage({ courses, authors, actions, ...props }) { +function ManageCoursePage({ courses, authors, actions, history, ...props }) { const [course, setCourse] = useState({ ...props.course }); const [errors, setErrors] = useState({}); @@ -35,7 +35,9 @@ function ManageCoursePage({ courses, authors, actions, ...props }) { function handleSave(event) { event.preventDefault(); - actions.saveCourse(course); + actions.saveCourse(course).then(() => { + history.push("/courses"); + }); } return ( @@ -53,7 +55,8 @@ ManageCoursePage.propTypes = { course: PropTypes.object.isRequired, courses: PropTypes.array.isRequired, authors: PropTypes.array.isRequired, - actions: PropTypes.object.isRequired + actions: PropTypes.object.isRequired, + history: PropTypes.object.isRequired }; function mapStateToProps(state) {