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

66 lines
1.8 KiB
React
Raw Normal View History

2016-03-29 10:13:35 +09:00
import React, { PropTypes, Component } from 'react';
import NovaForm from "meteor/nova:forms";
2016-03-29 10:13:35 +09:00
import SmartContainers from "meteor/utilities:react-list-container";
const DocumentContainer = SmartContainers.DocumentContainer;
2016-03-29 10:13:35 +09:00
import Core from "meteor/nova:core";
const Messages = Core.Messages;
import Actions from "../actions.js";
2016-04-14 10:12:35 +09:00
class PostsEditForm extends Component{
2016-03-29 10:13:35 +09:00
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, (error, result) => {
2016-03-29 10:13:35 +09:00
Messages.flash(`Post “${post.title}” deleted.`, "success");
Events.track("post deleted", {'_id': post._id});
});
}
}
render() {
const Icon = Telescope.components.Icon;
2016-03-29 10:13:35 +09:00
return (
<div className="posts-edit-form">
<DocumentContainer
collection={Posts}
publication="posts.single"
selector={{_id: this.props.post._id}}
terms={{_id: this.props.post._id}}
joins={Posts.getJoins()}
component={NovaForm}
componentProps={{
// note: the document prop will be passed from DocumentContainer
collection: Posts,
currentUser: this.context.currentUser,
methodName: "posts.edit",
2016-04-08 10:29:32 +09:00
labelFunction: fieldName => Telescope.utils.getFieldLabel(fieldName, Posts)
}}
2016-03-29 10:13:35 +09:00
/>
2016-04-07 10:33:44 +09:00
<hr/>
<a onClick={this.deletePost} className="delete-post-link"><Icon name="close"/> Delete Post</a>
2016-03-29 10:13:35 +09:00
</div>
)
}
}
2016-04-14 10:12:35 +09:00
PostsEditForm.propTypes = {
2016-03-29 10:13:35 +09:00
post: React.PropTypes.object.isRequired
}
2016-04-14 10:12:35 +09:00
PostsEditForm.contextTypes = {
2016-03-29 10:13:35 +09:00
currentUser: React.PropTypes.object
};
2016-04-14 10:12:35 +09:00
module.exports = PostsEditForm;
export default PostsEditForm;