forked from VulcanJS/Vulcan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostsEditForm.jsx
63 lines (54 loc) · 2.12 KB
/
PostsEditForm.jsx
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
import { Components, registerComponent, getFragment, withMessages } from 'meteor/nova:core';
import React, { PropTypes, Component } from 'react';
import { intlShape } from 'react-intl';
import Posts from "meteor/nova:posts";
import { withRouter } from 'react-router'
class PostsEditForm extends Component {
renderAdminArea() {
return (
<Components.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>
</Components.ShowIf>
)
}
render() {
return (
<div className="posts-edit-form">
{this.renderAdminArea()}
<Components.SmartForm
collection={Posts}
documentId={this.props.post._id}
mutationFragment={getFragment('PostsPage')}
successCallback={post => {
this.props.closeModal();
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});
}}
showRemove={true}
/>
</div>
);
}
}
PostsEditForm.propTypes = {
closeModal: React.PropTypes.func,
flash: React.PropTypes.func,
post: React.PropTypes.object.isRequired,
}
PostsEditForm.contextTypes = {
intl: intlShape
}
registerComponent('PostsEditForm', PostsEditForm, withMessages, withRouter);