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']
const ManuscriptLayout = ({
history,
assignHE,
revokeHE,
currentUser,
getSignedUrl,
editorInChief,
......@@ -44,7 +42,6 @@ const ManuscriptLayout = ({
fetchingError,
formValues,
heExpanded,
onHEResponse,
toggleAssignHE,
toggleHEResponse,
heResponseExpanded,
......@@ -66,6 +63,7 @@ const ManuscriptLayout = ({
submitRevision,
inviteReviewer,
recommendationHandle,
inviteHandlingEditor,
}) => (
<Root pb={30}>
{!isEmpty(collection) && !isEmpty(fragment) ? (
......@@ -86,8 +84,8 @@ const ManuscriptLayout = ({
inviteHE={toggleAssignHE}
isFetching={isFetching.editorsFetching}
journal={journal}
resendInvitation={assignHE}
revokeInvitation={revokeHE}
resendInvitation={inviteHandlingEditor.assignHE}
revokeInvitation={inviteHandlingEditor.revokeHE}
/>
<ManuscriptMetadata
......@@ -139,7 +137,7 @@ const ManuscriptLayout = ({
expanded={heResponseExpanded}
formValues={formValues.responseToInvitation}
label="Do you agree to be the handling editor for this manuscript?"
onResponse={onHEResponse}
onResponse={inviteHandlingEditor.onHEResponse}
title="Respond to Editorial Invitation"
toggle={toggleHEResponse}
/>
......@@ -156,7 +154,7 @@ const ManuscriptLayout = ({
)}
<ManuscriptAssignHE
assignHE={assignHE}
assignHE={inviteHandlingEditor.assignHE}
currentUser={currentUser}
expanded={heExpanded}
handlingEditors={handlingEditors}
......
......@@ -65,6 +65,7 @@ import ManuscriptLayout from './ManuscriptLayout'
import withInviteReviewer from '../inviteReviewer/withInviteReviewer'
import withSubmitRevision from '../submitRevision/withSubmitRevision'
import withHandleRecommendation from '../handleRecommendation/withHandleRecommendation'
import withInviteHandlingEditor from '../inviteHandlingEditor/withInviteHandlingEditor'
import {
parseSearchParams,
redirectToError,
......@@ -74,10 +75,7 @@ import {
canAssignHE,
selectFetching,
getHandlingEditors,
assignHandlingEditor,
revokeHandlingEditor,
selectHandlingEditors,
handlingEditorDecision,
} from '../redux/editors'
export default compose(
......@@ -128,7 +126,6 @@ export default compose(
{
changeForm,
clearCustomError,
revokeHandlingEditor,
getUsers: actions.getUsers,
getFragment: actions.getFragment,
getCollection: actions.getCollection,
......@@ -255,62 +252,6 @@ export default compose(
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 }) => ({
toggleAssignHE: toggle,
......@@ -342,6 +283,7 @@ export default compose(
get(currentUser, 'isReviewer', false) &&
isUndefined(submittedOwnRecommendation),
})),
withInviteHandlingEditor,
withInviteReviewer,
withSubmitRevision,
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