diff --git a/packages/component-faraday-selectors/package.json b/packages/component-faraday-selectors/package.json new file mode 100644 index 0000000000000000000000000000000000000000..4374d892ab72e0f1423b44a5ca8ae329f6ee739b --- /dev/null +++ b/packages/component-faraday-selectors/package.json @@ -0,0 +1,6 @@ +{ + "name": "pubsweet-component-faraday-selectors", + "version": "0.0.1", + "main": "src", + "license": "MIT" +} diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js new file mode 100644 index 0000000000000000000000000000000000000000..52c72aad6b34dafd24410ea89c7f21c9a2eecb9b --- /dev/null +++ b/packages/component-faraday-selectors/src/index.js @@ -0,0 +1,18 @@ +import { get } from 'lodash' + +export 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 const canMakeRecommendation = (state, project) => { + const isHE = isHEToManuscript(state, project.id) + return isHE && get(project, 'status') === 'reviewCompleted' +} diff --git a/packages/component-manuscript/src/components/SideBarActions.js b/packages/component-manuscript/src/components/SideBarActions.js index 2e61402208fc3076b1c8351701cb6ec2689b0da8..a8cc8acf2ddb7f726b4b0f7fe75bf044d920b561 100644 --- a/packages/component-manuscript/src/components/SideBarActions.js +++ b/packages/component-manuscript/src/components/SideBarActions.js @@ -1,13 +1,13 @@ import React from 'react' -import { get } from 'lodash' +import { compose } from 'recompose' 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 './' +import { canMakeRecommendation } from '../../../component-faraday-selectors/src' const SideBarActions = ({ project, @@ -36,25 +36,9 @@ const SideBarActions = ({ </Root> ) -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', + canMakeRecommendation: canMakeRecommendation(state, project), })), )(SideBarActions) diff --git a/packages/components-faraday/src/components/Dashboard/DashboardCard.js b/packages/components-faraday/src/components/Dashboard/DashboardCard.js index 720c6ea6fb6a4335cc6f0a8b463df109f4ce7d35..a9af74ea59255fb0238aace27fcb77aa9a5384e4 100644 --- a/packages/components-faraday/src/components/Dashboard/DashboardCard.js +++ b/packages/components-faraday/src/components/Dashboard/DashboardCard.js @@ -4,7 +4,7 @@ import { connect } from 'react-redux' import PropTypes from 'prop-types' import { Button, Icon, th } from '@pubsweet/ui' import styled, { css, withTheme } from 'styled-components' -import { compose, getContext, withHandlers, withProps } from 'recompose' +import { compose, getContext, withHandlers } from 'recompose' import { withModal, ConfirmationModal, @@ -18,6 +18,7 @@ import { currentUserIs } from '../../redux/users' import { selectInvitation } from '../../redux/reviewers' import { ReviewerDecision, HandlingEditorSection } from './' import { parseVersion, parseJournalIssue, mapStatusToLabel } from './../utils' +import { canMakeRecommendation } from '../../../../component-faraday-selectors/src' import { ReviewerBreakdown } from '../Invitations' import { Recommendation } from '../MakeRecommendation' @@ -166,17 +167,17 @@ const DashboardCard = ({ ) : null } -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, - ) +// 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 -} +// return userInvitation ? userInvitation.isAccepted : false +// } export default compose( getContext({ journal: PropTypes.object, currentUser: PropTypes.object }), @@ -188,12 +189,9 @@ export default compose( connect((state, { project }) => ({ isHE: currentUserIs(state, 'handlingEditor'), invitation: selectInvitation(state, project.id), - isHEToManuscript: isHEToManuscript(state, project.id), - })), - withProps(({ isHEToManuscript, project }) => ({ - canMakeRecommendation: - isHEToManuscript && get(project, 'status') === 'reviewCompleted', + canMakeRecommendation: canMakeRecommendation(state, project), })), + withHandlers({ canInviteReviewers: ({ currentUser, project }) => () => { const handlingEditor = get(project, 'handlingEditor') diff --git a/packages/components-faraday/src/components/Dashboard/TestComponent.js b/packages/components-faraday/src/components/Dashboard/TestComponent.js deleted file mode 100644 index 1a5c24a811476ed5286658e720b0d33116cfc767..0000000000000000000000000000000000000000 --- a/packages/components-faraday/src/components/Dashboard/TestComponent.js +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react' - -import withFactory from './withFactory' - -const TestComponent = ({ ceva, ...rest }) => <div>{ceva}</div> - -export default withFactory(props => ({ - ceva: 'hai sa vedem', -}))(TestComponent) diff --git a/packages/components-faraday/src/components/Dashboard/withFactory.js b/packages/components-faraday/src/components/Dashboard/withFactory.js deleted file mode 100644 index 30fffc01c4f7c155094f0199bfe60e37fcad90b2..0000000000000000000000000000000000000000 --- a/packages/components-faraday/src/components/Dashboard/withFactory.js +++ /dev/null @@ -1,13 +0,0 @@ -import { createFactory } from 'react' - -const withFactory = propsMapper => BaseComponent => { - const factory = createFactory(BaseComponent) - const WithFactory = props => - factory( - typeof propsMapper === 'function' ? propsMapper(props) : propsMapper, - ) - - return WithFactory -} - -export default withFactory