Skip to content

Commit

Permalink
added create post action creator
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Apr 20, 2017
1 parent 55def6c commit 525205f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions blog/src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';

export const FETCH_POSTS = 'fetch_posts';
export const CREATE_POST = 'create_post';

const ROOT_URL = 'http://reduxblog.herokuapp.com/api';
const API_KEY = '?key=PAPERCLIP1234';
Expand All @@ -13,3 +14,12 @@ export function fetchPosts() {
payload: request
};
}

export function createPost(values) {
const request = axios.post(`${ROOT_URL}/posts${API_KEY}`, values);

return {
type: CREATE_POST,
payload: request
};
}
9 changes: 6 additions & 3 deletions blog/src/components/posts_new.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { Component } from 'react';
import { Field, reduxForm } from 'redux-form';
import { Link } from 'react-router-dom';
import { connect } from 'react-redux';
import { createPost } from '../actions';

class PostsNew extends Component {
renderField(field) {
Expand All @@ -23,8 +25,7 @@ class PostsNew extends Component {
}

onSubmit(values) {
// this === component
console.log(values);
this.props.createPost(values);
}

render() {
Expand Down Expand Up @@ -77,4 +78,6 @@ function validate(values) {
export default reduxForm({
validate,
form: 'PostsNewForm'
})(PostsNew);
})(
connect(null,{ createPost })(PostsNew)
);

0 comments on commit 525205f

Please sign in to comment.