From f64b58673e7fb587af8f4ec2f751068c12cde14b Mon Sep 17 00:00:00 2001
From: Bogdan Cochior <bogdan.cochior@thinslices.com>
Date: Wed, 9 May 2018 17:16:18 +0300
Subject: [PATCH] feat(report): hide form when report is submitted

---
 .../src/components/ReviewsAndReports.js       | 24 ++++++++++++++-----
 .../src/redux/recommendations.js              |  8 +++++++
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/packages/component-manuscript/src/components/ReviewsAndReports.js b/packages/component-manuscript/src/components/ReviewsAndReports.js
index 8e27da044..276f718be 100644
--- a/packages/component-manuscript/src/components/ReviewsAndReports.js
+++ b/packages/component-manuscript/src/components/ReviewsAndReports.js
@@ -1,8 +1,9 @@
 import React, { Fragment } from 'react'
+import { head } from 'lodash'
 import { th } from '@pubsweet/ui'
 import { connect } from 'react-redux'
 import styled from 'styled-components'
-import { compose, withHandlers, lifecycle } from 'recompose'
+import { compose, withHandlers, lifecycle, withProps } from 'recompose'
 import { ReviewerBreakdown } from 'pubsweet-components-faraday/src/components/Invitations'
 import ReviewersDetailsList from 'pubsweet-components-faraday/src/components/Reviewers/ReviewersDetailsList'
 import ReviewerReportForm from 'pubsweet-component-manuscript/src/components/ReviewerReportForm'
@@ -39,6 +40,7 @@ const ReviewsAndReports = ({
   recommendations = [],
   isReviewer,
   currentUserIs,
+  report,
 }) => (
   <Fragment>
     {currentUserIs('staff') && (
@@ -60,11 +62,18 @@ const ReviewsAndReports = ({
     {isReviewer && (
       <Root id="review-report">
         <Expandable label="Your Report" startExpanded>
-          <ReviewerReportForm
-            project={project}
-            recommendations={recommendations}
-            version={version}
-          />
+          {report ? (
+            <div>
+              You have a submitted report with recommendation{' '}
+              {report.recommendation}
+            </div>
+          ) : (
+            <ReviewerReportForm
+              project={project}
+              recommendations={recommendations}
+              version={version}
+            />
+          )}
         </Expandable>
       </Root>
     )}
@@ -86,6 +95,9 @@ export default compose(
       getCollectionReviewers(project.id)
     },
   }),
+  withProps(({ recommendations = [] }) => ({
+    report: head(recommendations.filter(r => r.submittedOn)),
+  })),
   lifecycle({
     componentDidMount() {
       const { getReviewers } = this.props
diff --git a/packages/components-faraday/src/redux/recommendations.js b/packages/components-faraday/src/redux/recommendations.js
index 381cceb15..38c278451 100644
--- a/packages/components-faraday/src/redux/recommendations.js
+++ b/packages/components-faraday/src/redux/recommendations.js
@@ -5,6 +5,7 @@ import { create, update } from 'pubsweet-client/src/helpers/api'
 const REQUEST = 'recommendations/REQUEST'
 const ERROR = 'recommendations/ERROR'
 
+const GET_FRAGMENT_SUCCESS = 'GET_FRAGMENT_SUCCESS'
 const GET_RECOMMENDATIONS_SUCCESS = 'recommendations/GET_SUCCESS'
 const CREATE_RECOMMENDATION_SUCCESS = 'recommendations/CREATE_SUCCESS'
 const UPDATE_RECOMMENDATION_SUCCESS = 'recommendations/UPDATE_SUCCESS'
@@ -117,6 +118,13 @@ export default (state = initialState, action = {}) => {
         fetching: false,
         error: action.error,
       }
+    case GET_FRAGMENT_SUCCESS:
+      return {
+        ...state,
+        fetching: false,
+        error: null,
+        recommendations: get(action, 'fragment.recommendations'),
+      }
     case GET_RECOMMENDATIONS_SUCCESS:
       return {
         ...state,
-- 
GitLab