Skip to content
Snippets Groups Projects

HIN-974

Merged Alexandru Munteanu requested to merge HIN-974 into develop
27 files
+ 1103
702
Compare changes
  • Side-by-side
  • Inline
Files
27
import { get, last, chain } from 'lodash'
import { get, has, last, chain } from 'lodash'
import { selectCurrentUser } from 'xpub-selectors'
export const isHEToManuscript = (state, collectionId) => {
@@ -8,18 +8,6 @@ export const isHEToManuscript = (state, collectionId) => {
return get(collection, 'handlingEditor.id') === currentUserId
}
const canMakeRecommendationStatuses = [
'heAssigned',
'underReview',
'reviewCompleted',
]
export const canMakeRecommendation = (state, collection, fragment = {}) => {
if (fragment.id !== last(get(collection, 'fragments', []))) return false
const isHE = isHEToManuscript(state, get(collection, 'id', ''))
const status = get(collection, 'status', 'draft')
return isHE && canMakeRecommendationStatuses.includes(status)
}
export const currentUserIs = ({ currentUser: { user } }, role) => {
const isAdmin = get(user, 'admin')
const isEic = get(user, 'editorInChief')
@@ -228,3 +216,49 @@ export const getInvitationsWithReviewersForFragment = (state, fragmentId) =>
),
}))
.value()
// #region Editorial and reviewer recommendations
export const getFragmentRecommendations = (state, fragmentId) =>
get(state, `fragments.${fragmentId}.recommendations`, [])
export const getFragmentReviewerRecommendations = (state, fragmentId) =>
getFragmentRecommendations(state, fragmentId).filter(
r => r.recommendationType === 'review',
)
const getOwnRecommendations = (state, fragmentId) =>
chain(state)
.get(`fragments.${fragmentId}.recommendations`, [])
.filter(r => r.userId === get(state, 'currentUser.user.id', ''))
.value()
export const getOwnPendingRecommendation = (state, fragmentId) =>
chain(getOwnRecommendations(state, fragmentId))
.find(
r =>
r.userId === get(state, 'currentUser.user.id', '') &&
!has(r, 'submittedOn'),
)
.value()
export const getOwnSubmittedRecommendation = (state, fragmentId) =>
chain(getOwnRecommendations(state, fragmentId))
.find(
r =>
r.userId === get(state, 'currentUser.user.id', '') &&
has(r, 'submittedOn'),
)
.value()
const canMakeRecommendationStatuses = [
'heAssigned',
'underReview',
'reviewCompleted',
]
export const canMakeRecommendation = (state, collection, fragment = {}) => {
if (fragment.id !== last(get(collection, 'fragments', []))) return false
const isHE = isHEToManuscript(state, get(collection, 'id', ''))
const status = get(collection, 'status', 'draft')
return isHE && canMakeRecommendationStatuses.includes(status)
}
// #endregion