Newer
Older
import { connect } from 'react-redux'
import { head, get } from 'lodash'
import { actions } from 'pubsweet-client'
import { ConnectPage } from 'xpub-connect'
import { withJournal } from 'xpub-journal'
import { replace } from 'react-router-redux'
import { withRouter } from 'react-router-dom'
import {
selectFragment,
selectCollection,
selectCurrentUser,
} from 'xpub-selectors'
import { get as apiGet } from 'pubsweet-client/src/helpers/api'
import {
compose,
lifecycle,
withState,
withHandlers,
setDisplayName,
} from 'recompose'
import { getSignedUrl } from 'pubsweet-components-faraday/src/redux/files'
import { reviewerDecision } from 'pubsweet-components-faraday/src/redux/reviewers'
import {
hasManuscriptFailure,
clearCustomError,
} from 'pubsweet-components-faraday/src/redux/errors'
import { selectEditorialRecommendations } from 'pubsweet-components-faraday/src/redux/recommendations'
import {
getHandlingEditors,
selectHandlingEditors,
} from 'pubsweet-components-faraday/src/redux/editors'
import ManuscriptLayout from './ManuscriptLayout'
import { parseSearchParams, redirectToError } from './utils'
import { canSeeEditorialComments } from '../../../component-faraday-selectors'
export default compose(
setDisplayName('ManuscriptPage'),
withState('editorInChief', 'setEiC', 'N/A'),
ConnectPage(({ match }) => [
actions.getCollection({ id: match.params.project }),
actions.getFragment(
{ id: match.params.project },
{ id: match.params.version },
),
]),
connect(
(state, { match }) => ({
currentUser: selectCurrentUser(state),
handlingEditors: selectHandlingEditors(state),
hasManuscriptFailure: hasManuscriptFailure(state),
version: selectFragment(state, match.params.version),
project: selectCollection(state, match.params.project),

Alexandru Munteanu
committed
editorialRecommendations: selectEditorialRecommendations(
state,
match.params.version,
),
canSeeEditorialComments: canSeeEditorialComments(
state,
match.params.project,
),
{
replace,
getSignedUrl,
reviewerDecision,
getCollection: actions.getCollection,
updateVersion: actions.updateFragment,
ConnectPage(({ currentUser, handlingEditors, project }) => {
const he = get(project, 'handlingEditor')
if (
!he &&
!handlingEditors.length &&
(get(currentUser, 'admin') || get(currentUser, 'editorInChief'))
) {
return [getHandlingEditors()]
}
return []
}),
withHandlers({
updateManuscript: ({ updateVersion, project, version }) => data =>
updateVersion(project, {
id: version.id,
...data,
}),
setEditorInChief: ({ setEiC }) => eic => {
if (eic) {
const { firstName = '', lastName = '' } = eic
setEiC(`${firstName} ${lastName}`)
}
},
}),
lifecycle({
componentDidMount() {
const {
reviewerDecision,
setEditorInChief,
clearCustomError,
hasManuscriptFailure,
if (hasManuscriptFailure) {
history.push('/not-found')
clearCustomError()
}
const collectionId = match.params.project
const { agree, invitationId } = parseSearchParams(location.search)
if (agree === 'true') {
replace(location.pathname)
reviewerDecision(invitationId, collectionId, true)
.then(() => getCollection({ id: match.params.project }))
.catch(redirectToError(replace))
}
apiGet(`/users?editorInChief=true`).then(res =>
setEditorInChief(head(res.users)),
)
},
}),
)(ManuscriptLayout)