import React from 'react' import { connect } from 'react-redux' import { actions } from 'pubsweet-client' import { ConnectPage } from 'xpub-connect' import { selectCurrentUser, selectCollection, selectFragment, } from 'xpub-selectors' import { replace } from 'react-router-redux' import { compose, lifecycle, withHandlers } from 'recompose' import ManuscriptLayout from './ManuscriptLayout' import { parseSearchParams } from './utils' import { reviewerDecision } from '../../../components-faraday/src/redux/reviewers' export default compose( ConnectPage(({ match }) => [ actions.getCollection({ id: match.params.project }), actions.getFragment( { id: match.params.project }, { id: match.params.version }, ), ]), connect( (state, { match }) => ({ currentUser: selectCurrentUser(state), project: selectCollection(state, match.params.project), version: selectFragment(state, match.params.version), }), { reviewerDecision, replace, updateVersion: actions.updateFragment }, ), lifecycle({ componentDidMount() { const { reviewerDecision, replace, location, match, project } = this.props const collectionId = match.params.project const { agree, invitationId } = parseSearchParams(location.search) if (agree === 'true') { reviewerDecision(invitationId, collectionId, true) replace(location.pathname) } }, }), withHandlers({ updateManuscript: ({ updateVersion, project, version }) => data => updateVersion(project, { id: version.id, ...data, }), }), )(ManuscriptLayout)