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

76 lines
2.3 KiB
React
Raw Normal View History

import { Components, registerComponent } from 'meteor/nova:lib';
2016-03-29 10:13:35 +09:00
import React, { PropTypes, Component } from 'react';
import { intlShape } from 'react-intl';
2016-12-20 09:27:16 +09:00
import SmartForm from "meteor/nova:forms";
2016-06-23 11:40:35 +09:00
import Posts from "meteor/nova:posts";
import { withRouter } from 'react-router'
import { ShowIf, withMessages } from 'meteor/nova:core';
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 (
2016-12-01 16:09:54 +09:00
<ShowIf check={Posts.options.mutations.edit.check} document={this.props.post}>
<div className="posts-edit-form-admin">
<div className="posts-edit-form-id">ID: {this.props.post._id}</div>
<Components.PostsStats post={this.props.post} />
</div>
2016-12-01 16:09:54 +09:00
</ShowIf>
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()}
2016-12-20 09:27:16 +09:00
<SmartForm
collection={Posts}
documentId={this.props.post._id}
2016-12-05 16:30:31 +09:00
extraFragment={`
htmlBody
postedAt
user{
_id
__displayName
__emailHash
__slug
}
`}
successCallback={post => {
this.props.flash(this.context.intl.formatMessage({id: "posts.edit_success"}, {title: post.title}), 'success');
}}
removeSuccessCallback={({documentId, documentTitle}) => {
// post edit form is being included from a single post, redirect to index
// note: this.props.params is in the worst case an empty obj (from react-router)
if (this.props.params._id) {
this.props.router.push('/');
}
const deleteDocumentSuccess = this.context.intl.formatMessage({id: 'posts.delete_success'}, {title: documentTitle});
this.props.flash(deleteDocumentSuccess, "success");
// todo: handle events in collection callbacks
// this.context.events.track("post deleted", {_id: documentId});
}}
2016-11-23 11:07:48 +09:00
showRemove={true}
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 = {
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
registerComponent('PostsEditForm', PostsEditForm, withMessages, withRouter);