Skip to content
Snippets Groups Projects
Commit 869ce297 authored by Daniel Sandu's avatar Daniel Sandu
Browse files

refactor(handleRecommendation): merge with develop

parents f4df4eab e06a37c1
No related branches found
No related tags found
1 merge request!116Hin 1071
...@@ -29,8 +29,6 @@ const cannotViewReviewersDetails = ['revisionRequested', 'pendingApproval'] ...@@ -29,8 +29,6 @@ const cannotViewReviewersDetails = ['revisionRequested', 'pendingApproval']
const ManuscriptLayout = ({ const ManuscriptLayout = ({
history, history,
assignHE,
revokeHE,
currentUser, currentUser,
getSignedUrl, getSignedUrl,
editorInChief, editorInChief,
...@@ -44,7 +42,6 @@ const ManuscriptLayout = ({ ...@@ -44,7 +42,6 @@ const ManuscriptLayout = ({
fetchingError, fetchingError,
formValues, formValues,
heExpanded, heExpanded,
onHEResponse,
toggleAssignHE, toggleAssignHE,
toggleHEResponse, toggleHEResponse,
heResponseExpanded, heResponseExpanded,
...@@ -66,6 +63,7 @@ const ManuscriptLayout = ({ ...@@ -66,6 +63,7 @@ const ManuscriptLayout = ({
submitRevision, submitRevision,
inviteReviewer, inviteReviewer,
recommendationHandle, recommendationHandle,
inviteHandlingEditor,
}) => ( }) => (
<Root pb={30}> <Root pb={30}>
{!isEmpty(collection) && !isEmpty(fragment) ? ( {!isEmpty(collection) && !isEmpty(fragment) ? (
...@@ -86,8 +84,8 @@ const ManuscriptLayout = ({ ...@@ -86,8 +84,8 @@ const ManuscriptLayout = ({
inviteHE={toggleAssignHE} inviteHE={toggleAssignHE}
isFetching={isFetching.editorsFetching} isFetching={isFetching.editorsFetching}
journal={journal} journal={journal}
resendInvitation={assignHE} resendInvitation={inviteHandlingEditor.assignHE}
revokeInvitation={revokeHE} revokeInvitation={inviteHandlingEditor.revokeHE}
/> />
<ManuscriptMetadata <ManuscriptMetadata
...@@ -139,7 +137,7 @@ const ManuscriptLayout = ({ ...@@ -139,7 +137,7 @@ const ManuscriptLayout = ({
expanded={heResponseExpanded} expanded={heResponseExpanded}
formValues={formValues.responseToInvitation} formValues={formValues.responseToInvitation}
label="Do you agree to be the handling editor for this manuscript?" label="Do you agree to be the handling editor for this manuscript?"
onResponse={onHEResponse} onResponse={inviteHandlingEditor.onHEResponse}
title="Respond to Editorial Invitation" title="Respond to Editorial Invitation"
toggle={toggleHEResponse} toggle={toggleHEResponse}
/> />
...@@ -156,7 +154,7 @@ const ManuscriptLayout = ({ ...@@ -156,7 +154,7 @@ const ManuscriptLayout = ({
)} )}
<ManuscriptAssignHE <ManuscriptAssignHE
assignHE={assignHE} assignHE={inviteHandlingEditor.assignHE}
currentUser={currentUser} currentUser={currentUser}
expanded={heExpanded} expanded={heExpanded}
handlingEditors={handlingEditors} handlingEditors={handlingEditors}
......
...@@ -65,6 +65,7 @@ import ManuscriptLayout from './ManuscriptLayout' ...@@ -65,6 +65,7 @@ import ManuscriptLayout from './ManuscriptLayout'
import withInviteReviewer from '../inviteReviewer/withInviteReviewer' import withInviteReviewer from '../inviteReviewer/withInviteReviewer'
import withSubmitRevision from '../submitRevision/withSubmitRevision' import withSubmitRevision from '../submitRevision/withSubmitRevision'
import withHandleRecommendation from '../handleRecommendation/withHandleRecommendation' import withHandleRecommendation from '../handleRecommendation/withHandleRecommendation'
import withInviteHandlingEditor from '../inviteHandlingEditor/withInviteHandlingEditor'
import { import {
parseSearchParams, parseSearchParams,
redirectToError, redirectToError,
...@@ -74,10 +75,7 @@ import { ...@@ -74,10 +75,7 @@ import {
canAssignHE, canAssignHE,
selectFetching, selectFetching,
getHandlingEditors, getHandlingEditors,
assignHandlingEditor,
revokeHandlingEditor,
selectHandlingEditors, selectHandlingEditors,
handlingEditorDecision,
} from '../redux/editors' } from '../redux/editors'
export default compose( export default compose(
...@@ -128,7 +126,6 @@ export default compose( ...@@ -128,7 +126,6 @@ export default compose(
{ {
changeForm, changeForm,
clearCustomError, clearCustomError,
revokeHandlingEditor,
getUsers: actions.getUsers, getUsers: actions.getUsers,
getFragment: actions.getFragment, getFragment: actions.getFragment,
getCollection: actions.getCollection, getCollection: actions.getCollection,
...@@ -255,62 +252,6 @@ export default compose( ...@@ -255,62 +252,6 @@ export default compose(
setEiC(`${firstName} ${lastName}`) setEiC(`${firstName} ${lastName}`)
} }
}, },
assignHE: ({
setFetching,
fetchUpdatedCollection,
collection: { id: collectionId },
}) => (email, modalProps) =>
assignHandlingEditor({
email,
collectionId,
})
.then(() => {
fetchUpdatedCollection()
modalProps.hideModal()
})
.catch(handleError(modalProps.setModalError)),
revokeHE: ({
getCollection,
revokeHandlingEditor,
collection: { id: collectionId },
}) => (invitationId, modalProps) =>
revokeHandlingEditor({
invitationId,
collectionId,
})
.then(() => {
getCollection({ id: collectionId })
modalProps.hideModal()
})
.catch(handleError(modalProps.setModalError)),
onHEResponse: ({
history,
collection,
pendingHEInvitation,
fetchUpdatedCollection,
}) => (values, { hideModal, setModalError, setFetching }) => {
const isAccepted = get(values, 'decision', 'decline') === 'accept'
setFetching(true)
return handlingEditorDecision({
isAccepted,
collectionId: collection.id,
reason: get(values, 'reason', ''),
invitationId: pendingHEInvitation.id,
})
.then(() => {
setFetching(false)
hideModal()
if (isAccepted) {
fetchUpdatedCollection()
} else {
history.replace('/')
}
})
.catch(err => {
setFetching(false)
handleError(setModalError)(err)
})
},
}), }),
fromRenderProps(RemoteOpener, ({ toggle, expanded }) => ({ fromRenderProps(RemoteOpener, ({ toggle, expanded }) => ({
toggleAssignHE: toggle, toggleAssignHE: toggle,
...@@ -342,6 +283,7 @@ export default compose( ...@@ -342,6 +283,7 @@ export default compose(
get(currentUser, 'isReviewer', false) && get(currentUser, 'isReviewer', false) &&
isUndefined(submittedOwnRecommendation), isUndefined(submittedOwnRecommendation),
})), })),
withInviteHandlingEditor,
withInviteReviewer, withInviteReviewer,
withSubmitRevision, withSubmitRevision,
withHandleRecommendation, withHandleRecommendation,
......
import { create, update, remove } from 'pubsweet-client/src/helpers/api'
export const handlingEditorDecision = ({
reason,
isAccepted,
collectionId,
invitationId,
}) =>
update(`/collections/${collectionId}/invitations/${invitationId}`, {
isAccepted,
reason,
})
export const assignHandlingEditor = ({ email, collectionId }) =>
create(`/collections/${collectionId}/invitations`, {
email,
role: 'handlingEditor',
}).then(
res => res,
err => {
throw err
},
)
export const revokeHandlingEditor = ({ invitationId, collectionId }) =>
remove(`/collections/${collectionId}/invitations/${invitationId}`).then(
res => res,
err => {
throw err
},
)
import { compose, withHandlers, withProps } from 'recompose'
import { get, pick } from 'lodash'
import { withRouter } from 'react-router-dom'
import { handleError, withFetching } from 'pubsweet-component-faraday-ui'
import {
handlingEditorDecision,
assignHandlingEditor,
revokeHandlingEditor,
} from './inviteHE.api'
export default compose(
withFetching,
withRouter,
withHandlers({
assignHE: ({
fetchUpdatedCollection,
collection: { id: collectionId },
}) => (email, modalProps) =>
assignHandlingEditor({
email,
collectionId,
})
.then(() => {
fetchUpdatedCollection()
modalProps.hideModal()
})
.catch(handleError(modalProps.setModalError)),
revokeHE: ({ getCollection, collection: { id: collectionId } }) => (
invitationId,
modalProps,
) =>
revokeHandlingEditor({
invitationId,
collectionId,
})
.then(() => {
getCollection({ id: collectionId })
modalProps.hideModal()
})
.catch(handleError(modalProps.setModalError)),
onHEResponse: ({
history,
collection,
pendingHEInvitation,
fetchUpdatedCollection,
}) => (values, { hideModal, setModalError, setFetching }) => {
const isAccepted = get(values, 'decision', 'decline') === 'accept'
setFetching(true)
return handlingEditorDecision({
isAccepted,
collectionId: collection.id,
reason: get(values, 'reason', ''),
invitationId: pendingHEInvitation.id,
})
.then(() => {
setFetching(false)
hideModal()
if (isAccepted) {
fetchUpdatedCollection()
} else {
history.replace('/')
}
})
.catch(err => {
setFetching(false)
handleError(setModalError)(err)
})
},
}),
withProps(props => ({
inviteHandlingEditor: {
...pick(props, ['assignHE', 'revokeHE', 'onHEResponse']),
},
})),
)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment