Skip to content
Snippets Groups Projects
Commit 03951dd7 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

refactor(various): remove unused code; create faraday-selectors

parent 982eb178
No related branches found
No related tags found
1 merge request!10Sprint #12
{
"name": "pubsweet-component-faraday-selectors",
"version": "0.0.1",
"main": "src",
"license": "MIT"
}
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'
}
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)
......
......@@ -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')
......
import React from 'react'
import withFactory from './withFactory'
const TestComponent = ({ ceva, ...rest }) => <div>{ceva}</div>
export default withFactory(props => ({
ceva: 'hai sa vedem',
}))(TestComponent)
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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment