From c0018973858d959854cae26bf19d8cd9fc8b9ef5 Mon Sep 17 00:00:00 2001
From: Alexandru Munteanu <alexandru.munt@gmail.com>
Date: Tue, 5 Jun 2018 13:14:48 +0300
Subject: [PATCH] fix(manuscript-details): hide reviewers and redirect on
 network error

---
 packages/component-faraday-selectors/src/index.js     | 10 +++++++++-
 .../src/components/ManuscriptLayout.js                |  8 +++++++-
 .../src/components/ManuscriptPage.js                  | 11 ++++++++++-
 .../src/components/UIComponents/NotFound.js           |  4 ++--
 packages/xpub-faraday/config/default.js               |  2 +-
 5 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js
index dff83853c..144d06d42 100644
--- a/packages/component-faraday-selectors/src/index.js
+++ b/packages/component-faraday-selectors/src/index.js
@@ -76,6 +76,14 @@ export const canSeeEditorialComments = (state, collectionId) => {
   const collection = state.collections.find(c => c.id === collectionId)
   const isStaff = currentUserIs(state, 'staff')
   if (!isStaff) return false
-  if (editorialStatuses.includes(collection.status)) return false
+  if (editorialStatuses.includes(get(collection, 'status'))) return false
   return true
 }
+
+export const getPubsweetError = state => get(state, 'error')
+
+export const canSeeReviewersReports = (state, collectionId) => {
+  const isHE = isHEToManuscript(state, collectionId)
+  const isEiC = currentUserIs(state, 'adminEiC')
+  return isHE || isEiC
+}
diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js
index ea6b9532e..ad31c596c 100644
--- a/packages/component-manuscript/src/components/ManuscriptLayout.js
+++ b/packages/component-manuscript/src/components/ManuscriptLayout.js
@@ -1,5 +1,6 @@
 import React, { Fragment } from 'react'
 import { isEmpty } from 'lodash'
+import { Redirect } from 'react-router-dom'
 
 import {
   Root,
@@ -26,13 +27,16 @@ const ManuscriptLayout = ({
   history,
   currentUser,
   editorInChief,
+  pubsweetError,
   updateManuscript,
+  canSeeReviewersReports,
   canSeeEditorialComments,
   editorialRecommendations,
   project = {},
   version = {},
 }) => (
   <Root>
+    {pubsweetError && <Redirect to="not-found" />}
     {!isEmpty(project) && !isEmpty(version) ? (
       <Fragment>
         <Container flex={3}>
@@ -54,7 +58,9 @@ const ManuscriptLayout = ({
             version={version}
           />
           <ManuscriptDetails collection={project} fragment={version} />
-          <ReviewsAndReports project={project} version={version} />
+          {canSeeReviewersReports && (
+            <ReviewsAndReports project={project} version={version} />
+          )}
           {canSeeEditorialComments &&
             editorialRecommendations.length > 0 && (
               <EditorialComments
diff --git a/packages/component-manuscript/src/components/ManuscriptPage.js b/packages/component-manuscript/src/components/ManuscriptPage.js
index e807da967..6825aef0a 100644
--- a/packages/component-manuscript/src/components/ManuscriptPage.js
+++ b/packages/component-manuscript/src/components/ManuscriptPage.js
@@ -28,7 +28,11 @@ import {
 
 import ManuscriptLayout from './ManuscriptLayout'
 import { parseSearchParams, redirectToError } from './utils'
-import { canSeeEditorialComments } from '../../../component-faraday-selectors'
+import {
+  getPubsweetError,
+  canSeeReviewersReports,
+  canSeeEditorialComments,
+} from '../../../component-faraday-selectors'
 
 export default compose(
   setDisplayName('ManuscriptPage'),
@@ -45,10 +49,15 @@ export default compose(
   connect(
     (state, { match }) => ({
       currentUser: selectCurrentUser(state),
+      pubsweetError: getPubsweetError(state),
       handlingEditors: selectHandlingEditors(state),
       version: selectFragment(state, match.params.version),
       project: selectCollection(state, match.params.project),
       editorialRecommendations: selectEditorialRecommendations(state),
+      canSeeReviewersReports: canSeeReviewersReports(
+        state,
+        match.params.project,
+      ),
       canSeeEditorialComments: canSeeEditorialComments(
         state,
         match.params.project,
diff --git a/packages/components-faraday/src/components/UIComponents/NotFound.js b/packages/components-faraday/src/components/UIComponents/NotFound.js
index 6a4ed011b..d2f0e78ec 100644
--- a/packages/components-faraday/src/components/UIComponents/NotFound.js
+++ b/packages/components-faraday/src/components/UIComponents/NotFound.js
@@ -12,8 +12,8 @@ const NotFound = ({ history }) => (
       The page you are looking for might have been removed, had its name
       changed, or is temporarily unavailable.
     </H3>
-    <Button onClick={history.goBack} primary>
-      Back
+    <Button onClick={() => history.push('/')} primary>
+      Go to dashboard
     </Button>
   </Root>
 )
diff --git a/packages/xpub-faraday/config/default.js b/packages/xpub-faraday/config/default.js
index 4ee45fea3..70c2472c5 100644
--- a/packages/xpub-faraday/config/default.js
+++ b/packages/xpub-faraday/config/default.js
@@ -44,7 +44,7 @@ module.exports = {
   'pubsweet-client': {
     API_ENDPOINT: '/api',
     'login-redirect': '/',
-    'redux-log': false,
+    'redux-log': true,
     theme: process.env.PUBSWEET_THEME,
   },
   'mail-transport': {
-- 
GitLab