Vulcan/packages/nova-base-components/lib/posts/PostEditForm.jsx

55 lines
1.4 KiB
React
Raw Normal View History

2016-03-29 10:13:35 +09:00
import React, { PropTypes, Component } from 'react';
import ReactForms from "meteor/utilities:react-form-containers";
const EditDocument = ReactForms.EditDocument;
import Core from "meteor/nova:core";
const Messages = Core.Messages;
import Actions from "../actions.js";
class PostEditForm extends Component{
constructor() {
super();
this.deletePost = this.deletePost.bind(this);
}
deletePost() {
const post = this.props.post;
if (window.confirm(`Delete post “${post.title}”?`)) {
Actions.call('posts.deleteById', post._id, function(){
Messages.flash(`Post “${post.title}” deleted.`, "success");
Events.track("post deleted", {'_id': post._id});
});
}
}
render() {
return (
<div className="edit-post-form">
<div className="modal-form-title edit-post-form-header">
<h3>Edit Post</h3>
<a onClick={this.deletePost} className="delete-post-link"><Icon name="close"/> Delete Post</a>
</div>
<EditDocument
collection={Posts}
document={this.props.post}
currentUser={this.context.currentUser}
methodName="posts.edit"
2016-03-29 17:28:14 +09:00
labelFunction={Telescope.utils.camelToSpaces}
2016-03-29 10:13:35 +09:00
/>
</div>
)
}
}
PostEditForm.propTypes = {
post: React.PropTypes.object.isRequired
}
PostEditForm.contextTypes = {
currentUser: React.PropTypes.object
};
module.exports = PostEditForm;
export default PostEditForm;