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';
|
2017-05-19 14:58:37 +09:00
|
|
|
import { intlShape, FormattedMessage } from 'react-intl';
|
2016-06-14 10:01:44 +09:00
|
|
|
import { withRouter } from 'react-router'
|
2016-03-31 09:36:25 +09:00
|
|
|
|
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}
|
2017-05-19 14:58:37 +09:00
|
|
|
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">
|
2017-01-18 12:51:10 +01:00
|
|
|
<Components.SmartForm
|
2016-11-04 14:14:19 +01:00
|
|
|
collection={Posts}
|
2017-01-30 19:46:48 +09:00
|
|
|
mutationFragment={getFragment('PostsPage')}
|
2016-11-04 14:14:19 +01:00
|
|
|
successCallback={post => {
|
2017-01-10 17:49:03 +09:00
|
|
|
props.closeModal();
|
2017-02-16 23:11:47 +09:00
|
|
|
props.router.push({pathname: Posts.getPageUrl(post)});
|
2016-11-04 14:14:19 +01:00
|
|
|
props.flash(context.intl.formatMessage({id: "posts.created_message"}), "success");
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2017-01-18 12:51:10 +01:00
|
|
|
</Components.ShowIf>
|
2016-03-31 09:36:25 +09:00
|
|
|
|
2016-11-05 18:37:46 +09:00
|
|
|
PostsNewForm.propTypes = {
|
2017-05-19 14:42:43 -06:00
|
|
|
closeModal: PropTypes.func,
|
|
|
|
router: PropTypes.object,
|
|
|
|
flash: PropTypes.func,
|
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
|
2016-03-31 09:36:25 +09:00
|
|
|
};
|
|
|
|
|
2016-05-22 16:42:24 +09:00
|
|
|
PostsNewForm.displayName = "PostsNewForm";
|
|
|
|
|
2017-02-02 16:18:33 +01:00
|
|
|
registerComponent('PostsNewForm', PostsNewForm, withRouter, withMessages);
|