Skip to content
Snippets Groups Projects
Commit 8219e815 authored by Anca Ursachi's avatar Anca Ursachi
Browse files

refactor(ManuscriptHeader): Create a new const that holds the value used in...

refactor(ManuscriptHeader): Create a new const that holds the value used in two places and move erro
parent d5621eaa
No related branches found
No related tags found
3 merge requests!176Sprint 24,!171Sprint 24,!168Hin 845 revoke and assign he fix
import { get, chain, find } from 'lodash' import { get, chain, find } from 'lodash'
export const handleError = fn => e => { export const handleError = fn => e => {
const errorForAuthorWhenHEWasRevoked = fn(get(JSON.parse(e.response), 'error', 'Oops! Something went wrong!'))
'Your Handling Editor was changed. A new handling editor will be assigned to your manuscript soon. Sorry for the inconvenience.'
let error = get(
JSON.parse(e.response),
'error',
'Oops! Something went wrong!',
)
if (error === 'No revision has been found.') {
error = errorForAuthorWhenHEWasRevoked
}
fn(error)
} }
export const getReportComments = ({ report, isPublic = false }) => export const getReportComments = ({ report, isPublic = false }) =>
......
...@@ -135,27 +135,22 @@ export default compose( ...@@ -135,27 +135,22 @@ export default compose(
if (pendingInvitation.userId === currentUserId) { if (pendingInvitation.userId === currentUserId) {
return <Text ml={1}>Invited</Text> return <Text ml={1}>Invited</Text>
} }
if ( const invitedHeId =
(get(pendingInvitation, 'userId', false) || get(pendingInvitation, 'userId', false) ||
get(heInvitation, 'userId', false)) && get(heInvitation, 'userId', false)
(admin || editorInChief)
) { if (invitedHeId && (admin || editorInChief)) {
const person = chain(handlingEditors) const person = chain(handlingEditors)
.filter( .filter(he => he.id === invitedHeId)
he =>
he.id ===
(get(heInvitation, 'userId', false) ||
get(pendingInvitation, 'userId', false)),
)
.map(he => ({ ...he, name: `${he.firstName} ${he.lastName}` })) .map(he => ({ ...he, name: `${he.firstName} ${he.lastName}` }))
.first() .first()
.value() .value()
let invitedPerson = {} let invitedHe = {}
if (get(pendingInvitation, 'userId', false)) { if (get(pendingInvitation, 'userId', false)) {
invitedPerson = pendingInvitation invitedHe = pendingInvitation
} else if (get(heInvitation, 'userId', false)) { } else if (get(heInvitation, 'userId', false)) {
invitedPerson = heInvitation invitedHe = heInvitation
} }
return ( return (
<PersonInvitation <PersonInvitation
...@@ -163,7 +158,7 @@ export default compose( ...@@ -163,7 +158,7 @@ export default compose(
isLatestVersion={isLatestVersion} isLatestVersion={isLatestVersion}
ml={1} ml={1}
withName withName
{...invitedPerson} {...invitedHe}
onResend={resendInvitation} onResend={resendInvitation}
onRevoke={revokeInvitation} onRevoke={revokeInvitation}
person={person} person={person}
......
...@@ -24,7 +24,8 @@ module.exports = models => async (req, res) => { ...@@ -24,7 +24,8 @@ module.exports = models => async (req, res) => {
fragment = await models.Fragment.find(fragmentId) fragment = await models.Fragment.find(fragmentId)
if (!fragment.revision) { if (!fragment.revision) {
return res.status(400).json({ return res.status(400).json({
error: 'No revision has been found.', error:
'Your Handling Editor was changed. A new handling editor will be assigned to your manuscript soon. Sorry for the inconvenience.',
}) })
} }
......
...@@ -148,7 +148,9 @@ describe('Patch fragments route handler', () => { ...@@ -148,7 +148,9 @@ describe('Patch fragments route handler', () => {
expect(res.statusCode).toBe(400) expect(res.statusCode).toBe(400)
const data = JSON.parse(res._getData()) const data = JSON.parse(res._getData())
expect(data.error).toEqual('No revision has been found.') expect(data.error).toEqual(
'Your Handling Editor was changed. A new handling editor will be assigned to your manuscript soon. Sorry for the inconvenience.',
)
}) })
it('should return an error when the user is inactive', async () => { it('should return an error when the user is inactive', async () => {
const { inactiveUser } = testFixtures.users const { inactiveUser } = testFixtures.users
......
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