import React, { PropTypes, Component } from 'react';
import { intlShape } from 'react-intl';
import { Messages } from "meteor/nova:core";
import NovaForm from "meteor/nova:forms";
import { withRouter } from 'react-router'

const PostsNewForm = (props, context) => {
  
  const router = props.router;

  return (
    <Telescope.components.CanCreatePost>
      <div className="posts-new-form">
        <NovaForm 
          collection={Posts} 
          currentUser={context.currentUser}
          methodName="posts.new"
          successCallback={(post)=>{
            Messages.flash(context.intl.formatMessage({id: "posts.created_message"}), "success");
            router.push({pathName: Posts.getPageUrl(post)});
          }}
        />
      </div>
    </Telescope.components.CanCreatePost>
  )
}

PostsNewForm.contextTypes = {
  currentUser: React.PropTypes.object,
  intl: intlShape
};

PostsNewForm.displayName = "PostsNewForm";

module.exports = withRouter(PostsNewForm);
export default withRouter(PostsNewForm);