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

73 lines
2.4 KiB
React
Raw Normal View History

2016-08-08 11:18:21 +09:00
import Telescope from 'meteor/nova:lib';
2016-03-29 10:13:35 +09:00
import React, { PropTypes, Component } from 'react';
2016-06-09 17:42:20 +09:00
import { FormattedMessage, intlShape } from 'react-intl';
import NovaForm from "meteor/nova:forms";
2016-06-23 11:40:35 +09:00
import Posts from "meteor/nova:posts";
import { withRouter } from 'react-router'
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
2016-11-04 14:38:31 +09:00
class PostsEditForm extends Component {
2016-03-29 10:13:35 +09:00
2016-05-20 09:33:55 +09:00
renderAdminArea() {
return (
<Telescope.components.CanDo action="posts.edit.all">
<div className="posts-edit-form-admin">
<div className="posts-edit-form-id">ID: {this.props.post._id}</div>
<Telescope.components.PostsStats post={this.props.post} />
</div>
</Telescope.components.CanDo>
2016-05-20 09:33:55 +09:00
)
}
2016-03-29 10:13:35 +09:00
render() {
2016-03-29 10:13:35 +09:00
return (
<div className="posts-edit-form">
{this.renderAdminArea()}
<NovaForm
collection={Posts}
mutationName="postsEdit"
document={this.props.post}
resultQuery={Posts.graphQLQueries.single}
successCallback={post => {
this.context.closeCallback();
this.props.flash(this.context.intl.formatMessage({id: "posts.edit_success"}, {title: post.title}), 'success');
}}
removeSuccessCallback={({documentId, documentTitle}) => {
if (typeof this.context.closeCallback === "function") {
this.context.closeCallback();
} else {
// post edit form is being included from a single post, redirect to index
this.props.router.push('/');
}
const deleteDocumentSuccess = this.context.intl.formatMessage({id: 'posts.delete_success'}, {title: documentTitle});
this.props.flash(deleteDocumentSuccess, "success");
this.context.events.track("post deleted", {'_id': documentId});
}}
2016-03-29 10:13:35 +09:00
/>
</div>
);
2016-03-29 10:13:35 +09:00
}
}
2016-04-14 10:12:35 +09:00
PostsEditForm.propTypes = {
2016-11-04 14:14:19 +01:00
flash: React.PropTypes.func,
post: React.PropTypes.object.isRequired,
2016-03-29 10:13:35 +09:00
}
2016-04-14 10:12:35 +09:00
PostsEditForm.contextTypes = {
2016-06-09 17:42:20 +09:00
currentUser: React.PropTypes.object,
actions: React.PropTypes.object,
events: React.PropTypes.object,
closeCallback: React.PropTypes.func,
2016-06-09 17:42:20 +09:00
intl: intlShape
}
2016-03-29 10:13:35 +09:00
const mapStateToProps = state => ({ messages: state.messages });
const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch);
module.exports = withRouter(connect(mapStateToProps, mapDispatchToProps)(PostsEditForm));