diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js index c02738c3496a6555c600151ee557cfe13ed6fc55..527861a2f908403d9e0aa00fc7c239df2e3f28d6 100644 --- a/packages/component-manuscript/src/components/ManuscriptLayout.js +++ b/packages/component-manuscript/src/components/ManuscriptLayout.js @@ -35,7 +35,6 @@ const ManuscriptLayout = ({ getSignedUrl, editorInChief, handlingEditors, - createRecommendation, editorialRecommendations, journal = {}, collection = {}, @@ -59,7 +58,6 @@ const ManuscriptLayout = ({ shouldReview, submittedOwnRecommendation, reviewerReports, - onEditorialRecommendation, reviewerRecommendations, toggleReviewerDetails, reviewerDetailsExpanded, @@ -67,6 +65,7 @@ const ManuscriptLayout = ({ toggleEditorialComments, submitRevision, inviteReviewer, + recommendationHandle, }) => ( <Root pb={30}> {!isEmpty(collection) && !isEmpty(fragment) ? ( @@ -205,7 +204,9 @@ const ManuscriptLayout = ({ hasReviewerReports={reviewerRecommendations.length > 0} highlight={reviewerRecommendations.length > 0} modalKey="heRecommendation" - onRecommendationSubmit={onEditorialRecommendation} + onRecommendationSubmit={ + recommendationHandle.onEditorialRecommendation + } /> )} @@ -216,7 +217,7 @@ const ManuscriptLayout = ({ highlight={editorialRecommendations.length > 0} messagesLabel={messagesLabel} mt={2} - submitDecision={createRecommendation} + submitDecision={recommendationHandle.createRecommendation} /> )} </Fragment> diff --git a/packages/component-manuscript/src/components/ManuscriptPage.js b/packages/component-manuscript/src/components/ManuscriptPage.js index 5fd6b730f5fc68a7f685ab3a4bec6722105b78bf..2dc4481e221450dbac99107b24d6bf1ff42a34df 100644 --- a/packages/component-manuscript/src/components/ManuscriptPage.js +++ b/packages/component-manuscript/src/components/ManuscriptPage.js @@ -27,7 +27,6 @@ import { clearCustomError, } from 'pubsweet-components-faraday/src/redux/errors' import { - createRecommendation, selectReviewRecommendations, selectEditorialRecommendations, } from 'pubsweet-components-faraday/src/redux/recommendations' @@ -65,8 +64,8 @@ import { import ManuscriptLayout from './ManuscriptLayout' import withInviteReviewer from '../inviteReviewer/withInviteReviewer' import withSubmitRevision from '../submitRevision/withSubmitRevision' +import withHandleRecommendation from '../handleRecommendation/withHandleRecommendation' import { - parseEicDecision, parseSearchParams, redirectToError, getPublonsReviewers, @@ -284,28 +283,6 @@ export default compose( modalProps.hideModal() }) .catch(handleError(modalProps.setModalError)), - createRecommendation: ({ - fragment, - collection, - fetchUpdatedCollection, - }) => (values, modalProps) => { - const recommendation = parseEicDecision(values) - modalProps.setFetching(true) - createRecommendation({ - recommendation, - fragmentId: fragment.id, - collectionId: collection.id, - }) - .then(() => { - modalProps.setFetching(false) - modalProps.hideModal() - fetchUpdatedCollection() - }) - .catch(err => { - modalProps.setFetching(false) - handleError(modalProps.setModalError)(err) - }) - }, onHEResponse: ({ history, collection, @@ -334,27 +311,6 @@ export default compose( handleError(setModalError)(err) }) }, - onEditorialRecommendation: ({ - fragment, - collection, - fetchUpdatedCollection, - }) => (recommendation, { hideModal, setFetching, setModalError }) => { - setFetching(true) - createRecommendation({ - recommendation, - fragmentId: fragment.id, - collectionId: collection.id, - }) - .then(r => { - setFetching(false) - hideModal() - fetchUpdatedCollection() - }) - .catch(e => { - setFetching(false) - handleError(setModalError)(e) - }) - }, }), fromRenderProps(RemoteOpener, ({ toggle, expanded }) => ({ toggleAssignHE: toggle, @@ -388,6 +344,7 @@ export default compose( })), withInviteReviewer, withSubmitRevision, + withHandleRecommendation, lifecycle({ componentDidMount() { const { diff --git a/packages/component-manuscript/src/components/utils.js b/packages/component-manuscript/src/components/utils.js index 8d9a2d6cc3ad46d4304e2fc07dcfb57731c49c3b..e579d683636db3dfcb7917c961dd8d9f5a02eff8 100644 --- a/packages/component-manuscript/src/components/utils.js +++ b/packages/component-manuscript/src/components/utils.js @@ -293,18 +293,6 @@ export const requiredFiles = (values, formValues) => { return undefined } -// new stuff -export const parseEicDecision = ({ decision, message }) => ({ - recommendation: decision, - recommendationType: 'editorRecommendation', - comments: [ - { - public: decision !== 'return-to-handling-editor', - content: message, - }, - ], -}) - // handle publons export const getPublonsReviewers = fragmentId => apiGet(`/fragments/${fragmentId}/publons`) diff --git a/packages/component-manuscript/src/handleRecommendation/handleRecommendation.api.js b/packages/component-manuscript/src/handleRecommendation/handleRecommendation.api.js new file mode 100644 index 0000000000000000000000000000000000000000..5109ba04f4a9a96f2ebd5f0337cbd7eb28e7f751 --- /dev/null +++ b/packages/component-manuscript/src/handleRecommendation/handleRecommendation.api.js @@ -0,0 +1,11 @@ +import { create } from 'pubsweet-client/src/helpers/api' + +export const createRecommendation = ({ + fragmentId, + collectionId, + recommendation, +}) => + create( + `/collections/${collectionId}/fragments/${fragmentId}/recommendations`, + recommendation, + ) diff --git a/packages/component-manuscript/src/handleRecommendation/utils.js b/packages/component-manuscript/src/handleRecommendation/utils.js new file mode 100644 index 0000000000000000000000000000000000000000..700c21bd54d2660975186b3be24130f9002aff78 --- /dev/null +++ b/packages/component-manuscript/src/handleRecommendation/utils.js @@ -0,0 +1,10 @@ +export const parseEicDecision = ({ decision, message }) => ({ + recommendation: decision, + recommendationType: 'editorRecommendation', + comments: [ + { + public: decision !== 'return-to-handling-editor', + content: message, + }, + ], +}) diff --git a/packages/component-manuscript/src/handleRecommendation/withHandleRecommendation.js b/packages/component-manuscript/src/handleRecommendation/withHandleRecommendation.js new file mode 100644 index 0000000000000000000000000000000000000000..020d7e45d83fb81dc3741476545ef7704f91affb --- /dev/null +++ b/packages/component-manuscript/src/handleRecommendation/withHandleRecommendation.js @@ -0,0 +1,59 @@ +import { pick } from 'lodash' +import { withHandlers, withProps, compose } from 'recompose' +import { handleError, withFetching } from 'pubsweet-component-faraday-ui' +import { parseEicDecision } from './utils' +import { createRecommendation } from './handleRecommendation.api' + +export default compose( + withFetching, + withHandlers({ + createRecommendation: ({ + fragment, + collection, + fetchUpdatedCollection, + }) => (values, modalProps) => { + const recommendation = parseEicDecision(values) + modalProps.setFetching(true) + createRecommendation({ + recommendation, + fragmentId: fragment.id, + collectionId: collection.id, + }) + .then(() => { + modalProps.setFetching(false) + modalProps.hideModal() + fetchUpdatedCollection() + }) + .catch(err => { + modalProps.setFetching(false) + handleError(modalProps.setModalError)(err) + }) + }, + onEditorialRecommendation: ({ + fragment, + collection, + fetchUpdatedCollection, + }) => (recommendation, { hideModal, setFetching, setModalError }) => { + setFetching(true) + createRecommendation({ + recommendation, + fragmentId: fragment.id, + collectionId: collection.id, + }) + .then(r => { + setFetching(false) + hideModal() + fetchUpdatedCollection() + }) + .catch(e => { + setFetching(false) + handleError(setModalError)(e) + }) + }, + }), + withProps(props => ({ + recommendationHandle: { + ...pick(props, ['createRecommendation', 'onEditorialRecommendation']), + }, + })), +) diff --git a/packages/component-manuscript/src/inviteReviewer/withInviteReviewer.js b/packages/component-manuscript/src/inviteReviewer/withInviteReviewer.js index 87470cf50ac72ecd50306856c56667dfa19d49ee..fd06ce32bca143179b44ea9ec0408b5adc1fb256 100644 --- a/packages/component-manuscript/src/inviteReviewer/withInviteReviewer.js +++ b/packages/component-manuscript/src/inviteReviewer/withInviteReviewer.js @@ -2,11 +2,7 @@ import { get, pick } from 'lodash' import { withRouter } from 'react-router-dom' import { compose, withHandlers, withProps } from 'recompose' import { handleError, withFetching } from 'pubsweet-component-faraday-ui' -import { - inviteReviewer, - revokeReviewer, - reviewerDecision, -} from 'pubsweet-components-faraday/src/redux/reviewers' +import { inviteReviewer, revokeReviewer, reviewerDecision } from './invite.api' export default compose( withFetching,