ToastContainer

master
Tudor Stanciu 2020-04-12 01:41:12 +03:00
parent 8b95aec904
commit eca6cbc0b8
2 changed files with 8 additions and 0 deletions

View File

@ -6,6 +6,8 @@ import Header from "./common/Header";
import PageNotFound from "./PageNotFound"; import PageNotFound from "./PageNotFound";
import CoursesPage from "./courses/CoursesPage"; import CoursesPage from "./courses/CoursesPage";
import ManageCoursePage from "./courses/ManageCoursePage"; import ManageCoursePage from "./courses/ManageCoursePage";
import { ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
function App() { function App() {
return ( return (
@ -19,6 +21,7 @@ function App() {
<Route path="/course" component={ManageCoursePage} /> <Route path="/course" component={ManageCoursePage} />
<Route component={PageNotFound} /> <Route component={PageNotFound} />
</Switch> </Switch>
<ToastContainer autoClose={3000} />
</div> </div>
); );
} }

View File

@ -7,10 +7,12 @@ import { bindActionCreators } from "redux";
import CourseForm from "./CourseForm"; import CourseForm from "./CourseForm";
import { newCourse } from "../../../tools/mockData"; import { newCourse } from "../../../tools/mockData";
import Spinner from "../common/Spinner"; import Spinner from "../common/Spinner";
import { toast } from "react-toastify";
function ManageCoursePage({ courses, authors, actions, history, ...props }) { function ManageCoursePage({ courses, authors, actions, history, ...props }) {
const [course, setCourse] = useState({ ...props.course }); const [course, setCourse] = useState({ ...props.course });
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
const [saving, setSaving] = useState(false);
useEffect(() => { useEffect(() => {
if (courses.length === 0) { if (courses.length === 0) {
@ -38,7 +40,9 @@ function ManageCoursePage({ courses, authors, actions, history, ...props }) {
function handleSave(event) { function handleSave(event) {
event.preventDefault(); event.preventDefault();
setSaving(true);
actions.saveCourse(course).then(() => { actions.saveCourse(course).then(() => {
toast.success("Course saved.");
history.push("/courses"); history.push("/courses");
}); });
} }
@ -52,6 +56,7 @@ function ManageCoursePage({ courses, authors, actions, history, ...props }) {
authors={authors} authors={authors}
onChange={handleChange} onChange={handleChange}
onSave={handleSave} onSave={handleSave}
saving={saving}
/> />
); );
} }