From 8219e815ebedab52bfa3ef7e9956eb4e7351be68 Mon Sep 17 00:00:00 2001
From: Anca Ursachi <anca.ursachi@thinslices.com>
Date: Tue, 27 Nov 2018 15:55:22 +0200
Subject: [PATCH] refactor(ManuscriptHeader): Create a new const that holds the
 value used in two places and move erro

---
 .../component-faraday-ui/src/helpers/utils.js | 12 +--------
 .../src/manuscriptDetails/ManuscriptHeader.js | 25 ++++++++-----------
 .../src/routes/fragments/patch.js             |  3 ++-
 .../src/tests/fragments/patch.test.js         |  4 ++-
 4 files changed, 16 insertions(+), 28 deletions(-)

diff --git a/packages/component-faraday-ui/src/helpers/utils.js b/packages/component-faraday-ui/src/helpers/utils.js
index 6ffe4a6db..8b798e34e 100644
--- a/packages/component-faraday-ui/src/helpers/utils.js
+++ b/packages/component-faraday-ui/src/helpers/utils.js
@@ -1,17 +1,7 @@
 import { get, chain, find } from 'lodash'
 
 export const handleError = fn => e => {
-  const errorForAuthorWhenHEWasRevoked =
-    '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)
+  fn(get(JSON.parse(e.response), 'error', 'Oops! Something went wrong!'))
 }
 
 export const getReportComments = ({ report, isPublic = false }) =>
diff --git a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js
index 3c73c09d8..296bebafc 100644
--- a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js
+++ b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js
@@ -135,27 +135,22 @@ export default compose(
       if (pendingInvitation.userId === currentUserId) {
         return <Text ml={1}>Invited</Text>
       }
-      if (
-        (get(pendingInvitation, 'userId', false) ||
-          get(heInvitation, 'userId', false)) &&
-        (admin || editorInChief)
-      ) {
+      const invitedHeId =
+        get(pendingInvitation, 'userId', false) ||
+        get(heInvitation, 'userId', false)
+
+      if (invitedHeId && (admin || editorInChief)) {
         const person = chain(handlingEditors)
-          .filter(
-            he =>
-              he.id ===
-              (get(heInvitation, 'userId', false) ||
-                get(pendingInvitation, 'userId', false)),
-          )
+          .filter(he => he.id === invitedHeId)
           .map(he => ({ ...he, name: `${he.firstName} ${he.lastName}` }))
           .first()
           .value()
 
-        let invitedPerson = {}
+        let invitedHe = {}
         if (get(pendingInvitation, 'userId', false)) {
-          invitedPerson = pendingInvitation
+          invitedHe = pendingInvitation
         } else if (get(heInvitation, 'userId', false)) {
-          invitedPerson = heInvitation
+          invitedHe = heInvitation
         }
         return (
           <PersonInvitation
@@ -163,7 +158,7 @@ export default compose(
             isLatestVersion={isLatestVersion}
             ml={1}
             withName
-            {...invitedPerson}
+            {...invitedHe}
             onResend={resendInvitation}
             onRevoke={revokeInvitation}
             person={person}
diff --git a/packages/component-manuscript-manager/src/routes/fragments/patch.js b/packages/component-manuscript-manager/src/routes/fragments/patch.js
index acd037254..6a3e11ef0 100644
--- a/packages/component-manuscript-manager/src/routes/fragments/patch.js
+++ b/packages/component-manuscript-manager/src/routes/fragments/patch.js
@@ -24,7 +24,8 @@ module.exports = models => async (req, res) => {
     fragment = await models.Fragment.find(fragmentId)
     if (!fragment.revision) {
       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.',
       })
     }
 
diff --git a/packages/component-manuscript-manager/src/tests/fragments/patch.test.js b/packages/component-manuscript-manager/src/tests/fragments/patch.test.js
index f4e2147a5..be867cbe7 100644
--- a/packages/component-manuscript-manager/src/tests/fragments/patch.test.js
+++ b/packages/component-manuscript-manager/src/tests/fragments/patch.test.js
@@ -148,7 +148,9 @@ describe('Patch fragments route handler', () => {
 
     expect(res.statusCode).toBe(400)
     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 () => {
     const { inactiveUser } = testFixtures.users
-- 
GitLab