diff --git a/packages/component-manuscript/src/components/SideBarActions.js b/packages/component-manuscript/src/components/SideBarActions.js index ba0da4b513a84efbc2e01a4f432cfb050d5719e5..2e61402208fc3076b1c8351701cb6ec2689b0da8 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`