From a39b12f178e6c299fc9ecb3f01dfe07a11c151f9 Mon Sep 17 00:00:00 2001
From: Bogdan Cochior <bogdan.cochior@thinslices.com>
Date: Tue, 7 Aug 2018 16:45:45 +0300
Subject: [PATCH] feat(HE): add button for HE in heAssigned status

---
 .../component-faraday-selectors/src/index.js  |  4 +-
 .../src/components/SubmitRevision.js          | 73 ++++++++++---------
 .../src/components/Dashboard/DashboardCard.js |  1 +
 .../MakeRecommendation/Recommendation.js      |  2 +
 .../components/MakeRecommendation/StepOne.js  |  8 +-
 .../components/MakeRecommendation/utils.js    |  2 +-
 6 files changed, 52 insertions(+), 38 deletions(-)

diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js
index c5ce6d09d..ea5790b14 100644
--- a/packages/component-faraday-selectors/src/index.js
+++ b/packages/component-faraday-selectors/src/index.js
@@ -7,10 +7,12 @@ export const isHEToManuscript = (state, collectionId) => {
   return get(collection, 'handlingEditor.id') === currentUserId
 }
 
+const canMakeRecommendationStatuses = ['reviewCompleted', 'heAssigned']
 export const canMakeRecommendation = (state, collection, fragment = {}) => {
   if (fragment.id !== last(collection.fragments)) return false
   const isHE = isHEToManuscript(state, collection.id)
-  return isHE && get(collection, 'status') === 'reviewCompleted'
+  const status = get(collection, 'status')
+  return isHE && canMakeRecommendationStatuses.includes(status)
 }
 
 export const currentUserIs = ({ currentUser: { user } }, role) => {
diff --git a/packages/component-manuscript/src/components/SubmitRevision.js b/packages/component-manuscript/src/components/SubmitRevision.js
index a962668fb..afaf7697e 100644
--- a/packages/component-manuscript/src/components/SubmitRevision.js
+++ b/packages/component-manuscript/src/components/SubmitRevision.js
@@ -24,6 +24,7 @@ import {
 import { AuthorList, Files } from 'pubsweet-components-faraday/src/components'
 import { submitRevision } from 'pubsweet-component-wizard/src/redux/conversion'
 import AutosaveIndicator from 'pubsweet-component-wizard/src/components/AutosaveIndicator'
+import { selectReviewRecommendations } from 'pubsweet-components-faraday/src/redux/recommendations'
 import {
   toClass,
   compose,
@@ -60,6 +61,7 @@ const SubmitRevision = ({
   removeFile,
   handleSubmit,
   responseFiles,
+  reviews = [],
   submitFailed,
 }) => (
   <Root>
@@ -108,39 +110,41 @@ const SubmitRevision = ({
           />
         </CustomValidatedField>
       </Expandable>
-      <Expandable label="RESPONSE TO REVIEWER COMMENTS" startExpanded>
-        <Title>Reply text*</Title>
-        <Row>
-          <FullWidth className="full-width">
-            <ValidatedField
-              component={TextAreaField}
-              name="commentsToReviewers"
-              validate={
-                isEmpty(get(formValues, 'files.responseToReviewers'))
-                  ? [required]
-                  : []
-              }
-            />
-          </FullWidth>
-        </Row>
-        <Row left>
-          {responseFiles.map(file => (
-            <FileItem
-              compact
-              id={file.id}
-              key={file.id}
-              {...file}
-              removeFile={removeFile}
-            />
-          ))}
-        </Row>
-        <FilePicker
-          allowedFileExtensions={['pdf', 'doc', 'docx']}
-          onUpload={addFile}
-        >
-          <ActionText left={12}>Upload file</ActionText>
-        </FilePicker>
-      </Expandable>
+      {!isEmpty(reviews) && (
+        <Expandable label="RESPONSE TO REVIEWER COMMENTS" startExpanded>
+          <Title>Reply text*</Title>
+          <Row>
+            <FullWidth className="full-width">
+              <ValidatedField
+                component={TextAreaField}
+                name="commentsToReviewers"
+                validate={
+                  isEmpty(get(formValues, 'files.responseToReviewers'))
+                    ? [required]
+                    : []
+                }
+              />
+            </FullWidth>
+          </Row>
+          <Row left>
+            {responseFiles.map(file => (
+              <FileItem
+                compact
+                id={file.id}
+                key={file.id}
+                {...file}
+                removeFile={removeFile}
+              />
+            ))}
+          </Row>
+          <FilePicker
+            allowedFileExtensions={['pdf', 'doc', 'docx']}
+            onUpload={addFile}
+          >
+            <ActionText left={12}>Upload file</ActionText>
+          </FilePicker>
+        </Expandable>
+      )}
       <SubmitContainer>
         {submitFailed &&
           formError && <Error>There are some errors above.</Error>}
@@ -169,8 +173,9 @@ export default compose(
     modalComponent: ConfirmationModal,
   })),
   connect(
-    state => ({
+    (state, { version }) => ({
       fileFetching: getRequestStatus(state),
+      reviews: selectReviewRecommendations(state, version.id),
       formValues: getFormValues('revision')(state),
       formError: getFormSyncErrors('revision')(state),
     }),
diff --git a/packages/components-faraday/src/components/Dashboard/DashboardCard.js b/packages/components-faraday/src/components/Dashboard/DashboardCard.js
index d0b8f03d4..044a3a21e 100644
--- a/packages/components-faraday/src/components/Dashboard/DashboardCard.js
+++ b/packages/components-faraday/src/components/Dashboard/DashboardCard.js
@@ -74,6 +74,7 @@ const DashboardCard = ({
                   collectionId={project.id}
                   fragmentId={version.id}
                   modalKey={`recommend-${version.id}`}
+                  status={project.status}
                 />
               )}
               <ZipFiles
diff --git a/packages/components-faraday/src/components/MakeRecommendation/Recommendation.js b/packages/components-faraday/src/components/MakeRecommendation/Recommendation.js
index 10d7fc6d9..dff35cbd4 100644
--- a/packages/components-faraday/src/components/MakeRecommendation/Recommendation.js
+++ b/packages/components-faraday/src/components/MakeRecommendation/Recommendation.js
@@ -30,12 +30,14 @@ export default compose(
   })),
   withHandlers({
     showFirstStep: ({
+      status,
       showModal,
       hideModal,
       fragmentId,
       collectionId,
     }) => () => {
       showModal({
+        status,
         hideModal,
         fragmentId,
         collectionId,
diff --git a/packages/components-faraday/src/components/MakeRecommendation/StepOne.js b/packages/components-faraday/src/components/MakeRecommendation/StepOne.js
index 6185a09a1..b6723f9ff 100644
--- a/packages/components-faraday/src/components/MakeRecommendation/StepOne.js
+++ b/packages/components-faraday/src/components/MakeRecommendation/StepOne.js
@@ -7,7 +7,7 @@ import { FormItems } from '../UIComponents'
 
 const { Row, Title, RowItem, RootContainer, CustomRadioGroup } = FormItems
 
-const StepOne = ({ hideModal, disabled, onSubmit }) => (
+const StepOne = ({ hideModal, disabled, onSubmit, status }) => (
   <RootContainer>
     <Title>Recommendation for Next Phase</Title>
     <Row>
@@ -20,7 +20,11 @@ const StepOne = ({ hideModal, disabled, onSubmit }) => (
             >
               <RadioGroup
                 name="decision"
-                options={utils.recommendationOptions}
+                options={
+                  status === 'reviewCompleted'
+                    ? utils.recommendationOptions
+                    : utils.recommendationOptions.slice(1)
+                }
                 {...input}
               />
             </CustomRadioGroup>
diff --git a/packages/components-faraday/src/components/MakeRecommendation/utils.js b/packages/components-faraday/src/components/MakeRecommendation/utils.js
index 2884cdb90..69e5b63f1 100644
--- a/packages/components-faraday/src/components/MakeRecommendation/utils.js
+++ b/packages/components-faraday/src/components/MakeRecommendation/utils.js
@@ -1,8 +1,8 @@
 import { omit } from 'lodash'
 
 export const recommendationOptions = [
-  { value: 'reject', label: 'Reject' },
   { value: 'publish', label: 'Publish' },
+  { value: 'reject', label: 'Reject' },
   { value: 'revise', label: 'Request revision' },
 ]
 
-- 
GitLab