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

58 lines
1.7 KiB
React
Raw Normal View History

import Telescope from 'meteor/nova:lib';
import NovaForm from "meteor/nova:forms";
import { ShowIf } from 'meteor/nova:core';
import Posts from "meteor/nova:posts";
import React, { PropTypes, Component } from 'react';
2016-06-10 10:25:38 +09:00
import { intlShape } from 'react-intl';
2016-06-14 10:01:44 +09:00
import { withRouter } from 'react-router'
2016-11-07 22:27:34 +09:00
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
2016-12-01 16:09:54 +09:00
import { FormattedMessage } from 'react-intl';
2016-04-14 10:12:35 +09:00
const PostsNewForm = (props, context) => {
return (
2016-12-01 16:09:54 +09:00
<ShowIf
check={Posts.options.mutations.new.check}
failureComponent={<FormattedMessage id="users.cannot_post"/>}
2016-11-04 14:14:19 +01:00
>
<div className="posts-new-form">
<NovaForm
collection={Posts}
queryToUpdate="postsListQuery"
2016-12-05 16:30:31 +09:00
extraFragment={`
htmlBody
postedAt
user{
_id
__displayName
__emailHash
__slug
}
`}
2016-11-04 14:14:19 +01:00
successCallback={post => {
props.router.push({pathname: Posts.getPageUrl(post)});
2016-11-08 14:56:48 +09:00
context.closeCallback();
2016-11-04 14:14:19 +01:00
props.flash(context.intl.formatMessage({id: "posts.created_message"}), "success");
}}
/>
</div>
2016-12-01 16:09:54 +09:00
</ShowIf>
);
};
2016-11-05 18:37:46 +09:00
PostsNewForm.propTypes = {
router: React.PropTypes.object,
2016-11-07 11:46:58 +09:00
flash: React.PropTypes.func,
2016-11-05 18:37:46 +09:00
}
2016-04-14 10:12:35 +09:00
PostsNewForm.contextTypes = {
2016-11-08 14:56:48 +09:00
closeCallback: React.PropTypes.func,
2016-06-10 10:25:38 +09:00
intl: intlShape
};
PostsNewForm.displayName = "PostsNewForm";
2016-11-07 22:27:34 +09:00
const mapStateToProps = state => ({ messages: state.messages });
const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch);
Telescope.registerComponent('PostsNewForm', PostsNewForm, withRouter, connect(mapStateToProps, mapDispatchToProps));