From 31834fdb5927256011f37d794852739b8ae3e108 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 11 Apr 2020 23:56:50 +0300 Subject: [PATCH] ManageCoursePage state --- src/components/courses/ManageCoursePage.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/components/courses/ManageCoursePage.js b/src/components/courses/ManageCoursePage.js index e7387ca..455eb97 100644 --- a/src/components/courses/ManageCoursePage.js +++ b/src/components/courses/ManageCoursePage.js @@ -1,11 +1,16 @@ -import React, { useEffect } from "react"; +import React, { useEffect, useState } 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"; +import CourseForm from "./CourseForm"; +import { newCourse } from "../../../tools/mockData"; + +function ManageCoursePage({ courses, authors, actions, ...props }) { + const [course, setCourse] = useState({ ...props.course }); + const [errors, setErrors] = useState({}); -function ManageCoursePage({ courses, authors, actions }) { useEffect(() => { if (courses.length === 0) { actions.loadCourses().catch((error) => { @@ -20,14 +25,11 @@ function ManageCoursePage({ courses, authors, actions }) { } }, []); - return ( - <> -

Manage course

- - ); + return ; } ManageCoursePage.propTypes = { + course: PropTypes.object.isRequired, courses: PropTypes.array.isRequired, authors: PropTypes.array.isRequired, actions: PropTypes.object.isRequired @@ -35,6 +37,7 @@ ManageCoursePage.propTypes = { function mapStateToProps(state) { return { + course: newCourse, courses: state.courses, authors: state.authors };