Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ManuscriptLayout.js 7.23 KiB
import React, { Fragment } from 'react'
import styled from 'styled-components'
import { isEmpty, get } from 'lodash'
import {
  Text,
  paddingHelper,
  ReviewerDetails,
  AuthorReviews,
  HERecommendation,
  ManuscriptHeader,
  ManuscriptAssignHE,
  ManuscriptMetadata,
  ManuscriptDetailsTop,
  ResponseToInvitation,
  ManuscriptEicDecision,
  SubmitRevision,
} from 'pubsweet-component-faraday-ui'

import ReviewerReportCard from './ReviewReportCard'
import ReviewerReportForm from './ReviewerReportForm'
import EditorialCommentCard from './EditorialCommentCard'

const messagesLabel = {
  'return-to-handling-editor': 'Comments for Handling Editor',
  reject: 'Comments for Author',
}

const cannotViewReviewersDetails = ['revisionRequested', 'pendingApproval']

const ManuscriptLayout = ({
  history,
  currentUser,
  getSignedUrl,
  editorInChief,
  handlingEditors,
  editorialRecommendations,
  journal = {},
  collection = {},
  fragment = {},
  changeForm,
  isFetching,
  isFetchingData,
  publonsFetching,
  fetchingError,
  formValues,
  heExpanded,
  toggleAssignHE,
  toggleHEResponse,
  heResponseExpanded,
  toggleReviewerResponse,
  invitationsWithReviewers,
  publonReviewers,
  reviewerResponseExpanded,
  pendingOwnRecommendation,
  toggleReviewerRecommendations,
  reviewerRecommendationExpanded,
  shouldReview,
  submittedOwnRecommendation,
  reviewerReports,
  reviewerRecommendations,
  toggleReviewerDetails,
  reviewerDetailsExpanded,
  editorialCommentsExpanded,
  toggleEditorialComments,
  submitRevision,
  inviteReviewer,
  recommendationHandler,
  inviteHandlingEditor,
  versions,
  isLatestVersion,
}) => (
  <Root pb={30}>
    {!isEmpty(collection) && !isEmpty(fragment) ? (
      <Fragment>
        <ManuscriptDetailsTop
          collection={collection}
          currentUser={currentUser}
          fragment={fragment}
          getSignedUrl={getSignedUrl}
          history={history}
          versions={versions}
        />
        <ManuscriptHeader
          collection={collection}
          currentUser={currentUser}
          editorInChief={editorInChief}
          fragment={fragment}
          handlingEditors={handlingEditors}
          inviteHE={toggleAssignHE}
          isFetching={isFetchingData.editorsFetching}
          isLatestVersion={isLatestVersion}
          journal={journal}
          resendInvitation={inviteHandlingEditor.assignHE}
          revokeInvitation={inviteHandlingEditor.revokeHE}
          versions={versions}
        />

        <ManuscriptMetadata
          currentUser={currentUser}
          fragment={fragment}
          getSignedUrl={getSignedUrl}
        />

        {get(currentUser, 'permissions.canViewEditorialComments', true) && (
          <EditorialCommentCard
            collection={collection}
            expanded={editorialCommentsExpanded}
            journal={journal}
            reports={editorialRecommendations}
            toggle={toggleEditorialComments}
          />
        )}

        {get(currentUser, 'permissions.authorCanViewReportsDetails', false) && (
          <AuthorReviews
            currentUser={currentUser}
            journal={journal}
            reports={reviewerReports}
          />
        )}

        {submittedOwnRecommendation && (
          <ReviewerReportCard
            getSignedUrl={getSignedUrl}
            journal={journal}
            report={submittedOwnRecommendation}
            token={get(currentUser, 'token')}
          />
        )}

        {shouldReview && (
          <ReviewerReportForm
            changeForm={changeForm}
            expanded={reviewerRecommendationExpanded}
            formValues={get(formValues, 'reviewerReport', {})}
            modalKey="reviewer-report"
            project={collection}
            review={pendingOwnRecommendation}
            toggle={toggleReviewerRecommendations}
            token={get(currentUser, 'token')}
            version={fragment}
          />
        )}

        {get(currentUser, 'isInvitedHE', false) && (
          <ResponseToInvitation
            commentsOn="decline"
            expanded={heResponseExpanded}
            formValues={formValues.responseToInvitation}
            label="Do you agree to be the handling editor for this manuscript?"
            onResponse={inviteHandlingEditor.onHEResponse}
            title="Respond to Editorial Invitation"
            toggle={toggleHEResponse}
          />
        )}

        {get(currentUser, 'isInvitedToReview', false) && (
          <ResponseToInvitation
            expanded={reviewerResponseExpanded}
            label="Do you agree to review this manuscript?"
            onResponse={inviteReviewer.onReviewerResponse}
            title="Respond to Invitation to Review"
            toggle={toggleReviewerResponse}
          />
        )}

        <ManuscriptAssignHE
          assignHE={inviteHandlingEditor.assignHE}
          currentUser={currentUser}
          expanded={heExpanded}
          handlingEditors={handlingEditors}
          isFetching={isFetchingData.editorsFetching}
          toggle={toggleAssignHE}
        />

        {get(currentUser, 'permissions.canViewReviewersDetails', false) && (
          <ReviewerDetails
            currentUser={currentUser}
            expanded={reviewerDetailsExpanded}
            fetchingError={fetchingError}
            fragment={fragment}
            getSignedUrl={getSignedUrl}
            highlight={
              reviewerReports.length === 0 &&
              !cannotViewReviewersDetails.includes(
                get(collection, 'status', 'draft'),
              )
            }
            invitations={invitationsWithReviewers}
            isFetching={isFetchingData.publonsFetching}
            isLatestVersion={isLatestVersion}
            journal={journal}
            mb={2}
            publonReviewers={publonReviewers}
            reviewerReports={reviewerReports}
            scrollIntoView
            toggle={toggleReviewerDetails}
            {...inviteReviewer}
          />
        )}

        {get(currentUser, 'permissions.canSubmitRevision', false) && (
          <SubmitRevision {...submitRevision} />
        )}

        {get(currentUser, 'permissions.canMakeHERecommendation', false) &&
          (!invitationsWithReviewers.length ||
            reviewerRecommendations.length > 0) && (
            <HERecommendation
              formValues={get(formValues, 'editorialRecommendation', {})}
              hasReviewerReports={reviewerRecommendations.length > 0}
              highlight={reviewerRecommendations.length > 0}
              modalKey="heRecommendation"
              onRecommendationSubmit={
                recommendationHandler.onEditorialRecommendation
              }
            />
          )}

        {get(currentUser, 'permissions.canMakeDecision', false) && (
          <ManuscriptEicDecision
            collection={collection}
            formValues={get(formValues, 'eicDecision')}
            highlight={editorialRecommendations.length > 0}
            messagesLabel={messagesLabel}
            mt={2}
            submitDecision={recommendationHandler.createRecommendation}
          />
        )}
      </Fragment>
    ) : (
      <Text>Loading...</Text>
    )}
  </Root>
)

export default ManuscriptLayout

// #region styles
const Root = styled.div`
  overflow-y: visible;
  min-height: 70vh;
  ${paddingHelper};
`
// #endregion