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

41 lines
1.4 KiB
React
Raw Normal View History

2017-03-23 16:27:59 +09:00
import { Components, registerComponent, getRawComponent, getFragment, withMessages } from 'meteor/vulcan:core';
import Posts from "meteor/vulcan:posts";
2017-05-19 14:42:43 -06:00
import React from 'react';
import PropTypes from 'prop-types';
import { intlShape, FormattedMessage } from 'react-intl';
2016-06-14 10:01:44 +09:00
import { withRouter } from 'react-router'
2017-03-29 22:36:17 +09:00
const PostsNewForm = (props, context) =>
<Components.ShowIf
2016-12-01 16:09:54 +09:00
check={Posts.options.mutations.new.check}
failureComponent={<div><p className="posts-new-form-message"><FormattedMessage id="posts.sign_up_or_log_in_first" /></p><Components.AccountsLoginForm /></div>}
2016-11-04 14:14:19 +01:00
>
<div className="posts-new-form">
<Components.SmartForm
2016-11-04 14:14:19 +01:00
collection={Posts}
mutationFragment={getFragment('PostsPage')}
2016-11-04 14:14:19 +01:00
successCallback={post => {
props.closeModal();
props.router.push({pathname: props.redirect || Posts.getPageUrl(post)});
2016-11-04 14:14:19 +01:00
props.flash(context.intl.formatMessage({id: "posts.created_message"}), "success");
}}
/>
</div>
</Components.ShowIf>
2016-11-05 18:37:46 +09:00
PostsNewForm.propTypes = {
closeModal: React.PropTypes.func,
2016-11-05 18:37:46 +09:00
router: React.PropTypes.object,
2016-11-07 11:46:58 +09:00
flash: React.PropTypes.func,
redirect: React.PropTypes.string,
2016-11-05 18:37:46 +09:00
}
2016-04-14 10:12:35 +09:00
PostsNewForm.contextTypes = {
2017-05-19 14:42:43 -06:00
closeCallback: PropTypes.func,
2016-06-10 10:25:38 +09:00
intl: intlShape
};
PostsNewForm.displayName = "PostsNewForm";
registerComponent('PostsNewForm', PostsNewForm, withRouter, withMessages);