From 6be38c77d08266dec03ae384cdd30e346a67c95c Mon Sep 17 00:00:00 2001 From: Alexandru Munteanu <alexandru.munt@gmail.com> Date: Mon, 21 May 2018 11:51:20 +0300 Subject: [PATCH] feat(manusript-details): show make recommendation only when required --- .../src/components/SideBarActions.js | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/packages/component-manuscript/src/components/SideBarActions.js b/packages/component-manuscript/src/components/SideBarActions.js index ba0da4b51..2e6140220 100644 --- a/packages/component-manuscript/src/components/SideBarActions.js +++ b/packages/component-manuscript/src/components/SideBarActions.js @@ -1,15 +1,23 @@ import React from 'react' -import { th, Icon } from '@pubsweet/ui' +import { get } from 'lodash' +import { connect } from 'react-redux' import styled from 'styled-components' +import { th, Icon } from '@pubsweet/ui' +import { compose, withProps } from 'recompose' import ZipFiles from 'pubsweet-components-faraday/src/components/Files/ZipFiles' import { Recommendation } from 'pubsweet-components-faraday/src/components/MakeRecommendation' import { MakeDecision } from './' -const SideBarActions = ({ project, version, currentUserIs }) => ( +const SideBarActions = ({ + project, + version, + currentUserIs, + canMakeRecommendation, +}) => ( <Root> {currentUserIs('adminEiC') && <MakeDecision />} - {currentUserIs('isHE') && ( + {canMakeRecommendation && ( <Recommendation collectionId={project.id} fragmentId={version.id} @@ -28,7 +36,27 @@ const SideBarActions = ({ project, version, currentUserIs }) => ( </Root> ) -export default SideBarActions +const isHEToManuscript = (state, collectionId) => { + const currentUserId = get(state, 'currentUser.user.id') + const collections = get(state, 'collections') || [] + const collection = collections.find(c => c.id === collectionId) || {} + const collectionInvitations = get(collection, 'invitations') || [] + const userInvitation = collectionInvitations.find( + i => i.role === 'handlingEditor' && i.userId === currentUserId, + ) + + return userInvitation ? userInvitation.isAccepted : false +} + +export default compose( + connect((state, { project }) => ({ + isHEToManuscript: isHEToManuscript(state, project.id), + })), + withProps(({ isHEToManuscript, project }) => ({ + canMakeRecommendation: + isHEToManuscript && get(project, 'status') === 'reviewCompleted', + })), +)(SideBarActions) // #region styled-components const Root = styled.div` -- GitLab