File size: 916 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { createPost } from '../../actions/post_actions';
import PostForm from './post_form';

const mapStateToProps = (state, ownProps) => {
  const authorId = state.session.currentUserId;
  const url = ownProps.match.params.userUrl;
  let recipientId;
  
  if (url === undefined) {
    recipientId = authorId;
  } else {
    recipientId = state.entities.userUrls[url];
  }
  
  return ({
    userUrls: state.entities.userUrls,
    post: {
      authorId,
      recipientId,
      body: '' 
    },
    formType: 'Make Post',
    formButtonText: 'Post',
    author: state.entities.users[authorId],
    recipient: state.entities.users[recipientId]
  });
};

const mapDispatchToProps = dispatch => ({
  action: post => dispatch(createPost(post))
});

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(PostForm));