Skip to content

Commit

Permalink
added navigation on submit
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Jan 25, 2016
1 parent 2e87ccd commit d4e6c26
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions blog/src/components/posts_new.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import React, { Component } from 'react';
import React, { Component, PropTypes } from 'react';
import { reduxForm } from 'redux-form';
import { createPost } from '../actions/index';
import { Link } from 'react-router';

class PostsNew extends Component {
static contextTypes = {
router: PropTypes.object
};

onSubmit(props) {
this.props.createPost(props)
.then(() => {
// blog post has been created, navigate the user to the index
// We navigate by calling this.context.router.push with the
// new path to navigate to.
this.context.router.push('/');
});
}

render() {
const { fields: { title, categories, content }, handleSubmit } = this.props;

return (
<form onSubmit={handleSubmit(this.props.createPost)}>
<form onSubmit={handleSubmit(this.onSubmit.bind(this))}>
<h3>Create A New Post</h3>

<div className={`form-group ${title.touched && title.invalid ? 'has-danger' : ''}`}>
Expand Down

0 comments on commit d4e6c26

Please sign in to comment.