redirect between pages
parent
233d37d373
commit
7a147e1dde
|
@ -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 && <Redirect to="/course" />}
|
||||
<h2>Courses</h2>
|
||||
|
||||
<button
|
||||
style={{ marginBottom: 20 }}
|
||||
className="btn btn-primary add-course"
|
||||
onClick={() => this.setState({ redirectToAddCoursePage: true })}
|
||||
>
|
||||
Add Course
|
||||
</button>
|
||||
|
||||
<CourseList courses={this.props.courses} />
|
||||
</>
|
||||
);
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue