diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js index ad31c596ca12353cde5542e16f7f0e4c3bfcc543..ea6b9532eb0b048a250ae750f0d4c6357c9faf44 100644 --- a/packages/component-manuscript/src/components/ManuscriptLayout.js +++ b/packages/component-manuscript/src/components/ManuscriptLayout.js @@ -1,6 +1,5 @@ import React, { Fragment } from 'react' import { isEmpty } from 'lodash' -import { Redirect } from 'react-router-dom' import { Root, @@ -27,16 +26,13 @@ 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}> @@ -58,9 +54,7 @@ const ManuscriptLayout = ({ version={version} /> <ManuscriptDetails collection={project} fragment={version} /> - {canSeeReviewersReports && ( - <ReviewsAndReports project={project} version={version} /> - )} + <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 6825aef0a32ea3d3c45ca5fbe816b21d9f87f96b..df4b1eaac76cebaf609b4b5fe0d5768e25eb2979 100644 --- a/packages/component-manuscript/src/components/ManuscriptPage.js +++ b/packages/component-manuscript/src/components/ManuscriptPage.js @@ -20,6 +20,10 @@ import { } from 'recompose' import { getSignedUrl } from 'pubsweet-components-faraday/src/redux/files' import { reviewerDecision } from 'pubsweet-components-faraday/src/redux/reviewers' +import { + hasManuscriptFailure, + clearCustomError, +} from 'pubsweet-components-faraday/src/redux/errors' import { selectEditorialRecommendations } from 'pubsweet-components-faraday/src/redux/recommendations' import { getHandlingEditors, @@ -28,11 +32,7 @@ import { import ManuscriptLayout from './ManuscriptLayout' import { parseSearchParams, redirectToError } from './utils' -import { - getPubsweetError, - canSeeReviewersReports, - canSeeEditorialComments, -} from '../../../component-faraday-selectors' +import { canSeeEditorialComments } from '../../../component-faraday-selectors' export default compose( setDisplayName('ManuscriptPage'), @@ -49,15 +49,11 @@ export default compose( connect( (state, { match }) => ({ currentUser: selectCurrentUser(state), - pubsweetError: getPubsweetError(state), handlingEditors: selectHandlingEditors(state), + hasManuscriptFailure: hasManuscriptFailure(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, @@ -66,6 +62,7 @@ export default compose( { replace, getSignedUrl, + clearCustomError, reviewerDecision, getCollection: actions.getCollection, updateVersion: actions.updateFragment, @@ -100,11 +97,19 @@ export default compose( const { match, replace, + history, location, getCollection, reviewerDecision, setEditorInChief, + clearCustomError, + hasManuscriptFailure, } = this.props + if (hasManuscriptFailure) { + history.push('/not-found') + clearCustomError() + } + const collectionId = match.params.project const { agree, invitationId } = parseSearchParams(location.search) if (agree === 'true') { diff --git a/packages/component-manuscript/src/components/ReviewsAndReports.js b/packages/component-manuscript/src/components/ReviewsAndReports.js index 133f314ff9523e01e8b75bf5be344bb2a805d961..b498bf92a2eab8ad79f3071057a1adf539c29efd 100644 --- a/packages/component-manuscript/src/components/ReviewsAndReports.js +++ b/packages/component-manuscript/src/components/ReviewsAndReports.js @@ -16,7 +16,7 @@ import { selectRecommendations } from 'pubsweet-components-faraday/src/redux/rec import { Tabs, Expandable } from '../molecules' import { ReviewReportCard, ReviewerReportForm } from './' -import { currentUserIs } from '../../../component-faraday-selectors' +import { canSeeReviewersReports } from '../../../component-faraday-selectors' const getTabSections = (collectionId, reviewers, recommendations = []) => [ { @@ -47,16 +47,16 @@ const ReviewsAndReports = ({ report, project, version, - isStaff, isReviewer, mappedReviewers, mappedRecommendations, + canSeeReviewersReports, review = {}, reviewers = [], recommendations = [], }) => ( <Fragment> - {isStaff && ( + {canSeeReviewersReports && ( <Root> <Expandable label="Reviewers & Reports" @@ -102,10 +102,10 @@ export default compose( connect( (state, { project }) => ({ reviewers: selectReviewers(state), - isStaff: currentUserIs(state, 'staff'), recommendations: selectRecommendations(state), fetchingReviewers: selectFetchingReviewers(state), isReviewer: currentUserIsReviewer(state, project.id), + canSeeReviewersReports: canSeeReviewersReports(state, project.id), }), { getCollectionReviewers }, ), @@ -130,8 +130,8 @@ export default compose( })), lifecycle({ componentDidMount() { - const { getReviewers } = this.props - getReviewers() + const { getReviewers, canSeeReviewersReports } = this.props + canSeeReviewersReports && getReviewers() }, }), )(ReviewsAndReports) diff --git a/packages/components-faraday/src/index.js b/packages/components-faraday/src/index.js index d21969e7b792fa03fadc8e92f38152c12935abb4..0eb9c3b474d2da621536bec68cbe2541141b9544 100644 --- a/packages/components-faraday/src/index.js +++ b/packages/components-faraday/src/index.js @@ -3,8 +3,9 @@ module.exports = { components: [() => require('./components')], reducers: { authors: () => require('./redux/authors').default, - files: () => require('./redux/files').default, + customError: () => require('./redux/errors').default, editors: () => require('./redux/editors').default, + files: () => require('./redux/files').default, reviewers: () => require('./redux/reviewers').default, recommendations: () => require('./redux/recommendations').default, }, diff --git a/packages/components-faraday/src/redux/errors.js b/packages/components-faraday/src/redux/errors.js new file mode 100644 index 0000000000000000000000000000000000000000..00a4efa1c7f3c3fd27237a30ad9d5303fb5aab9e --- /dev/null +++ b/packages/components-faraday/src/redux/errors.js @@ -0,0 +1,17 @@ +export const hasManuscriptFailure = state => + state.customError === 'manuscriptFailure' + +export const clearCustomError = () => ({ + type: 'CLEAR_CUSTOM_ERROR', +}) + +export default (state = '', action) => { + switch (action.type) { + case 'CLEAR_CUSTOM_ERROR': + return '' + case 'GET_FRAGMENT_FAILURE': + return 'manuscriptFailure' + default: + return state + } +} diff --git a/packages/components-faraday/src/redux/index.js b/packages/components-faraday/src/redux/index.js index 12a9544f097bb4a8b08317dad23152255879d3fe..9e0c549f2498178e77b7c129e3ce4f0ee5c53bae 100644 --- a/packages/components-faraday/src/redux/index.js +++ b/packages/components-faraday/src/redux/index.js @@ -1,5 +1,6 @@ +export { default as files } from './files' +export { default as errors } from './errors' export { default as authors } from './authors' export { default as editors } from './editors' -export { default as files } from './files' export { default as reviewers } from './reviewers' export { default as recommendations } from './recommendations'