File size: 2,100 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React from 'react';
import { connect } from 'react-redux';
import EditPostFormContainer from '../posts/edit_post_form_container';
import { hideModal } from '../../actions/ui_actions';
import { deletePost } from '../../actions/post_actions';

const mapStateToProps = state => ({
  modalType: state.ui.modal.modalType,
  modalProps: state.ui.modal.modalProps
});

const mapDispatchToProps = dispatch => ({
  hideModal: () => dispatch(hideModal()),
  deletePost: postId => dispatch(deletePost(postId))
});

class PostModal extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      modalIsOpen: false
    }
  }
  
  render() {
    if (this.props.modalType === 'edit') {
      return (
        <div className="post-modal show-modal">
          <div className="post-modal-content">
            <span className="close-button" onClick={() => this.props.hideModal()}>&times;</span>
            <EditPostFormContainer post={this.props.modalProps} />
          </div>
        </div>
      );
    } else if (this.props.modalType === 'delete') {
      return (
        <div className="post-modal show-modal">
          <div className="post-modal-content">
            <span className="close-button" onClick={() => this.props.hideModal()}>&times;</span>
            <div className="post-container">
              <div className="post-form-header">
                Delete Post
              </div>
              <div className="post-form-content">
                Deleting this post will remove it from your timeline. This action cannot be undone.
                <div className="post-footer">
                  <button onClick={() => this.props.hideModal()}>Cancel</button>
                  <button onClick={() => {
                    this.props.deletePost(this.props.modalProps.id);
                    this.props.hideModal()
                  }}>Delete</button>
                </div>
              </div>
            </div>
          </div>
        </div>
      );
    }

    return null;
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(PostModal);