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

feat(submit-revision): update make revision selector

parent 59881d7f
No related branches found
No related tags found
1 merge request!14Sprint #15
...@@ -75,6 +75,7 @@ export const canSeeReviewersReports = (state, collectionId) => { ...@@ -75,6 +75,7 @@ export const canSeeReviewersReports = (state, collectionId) => {
export const canMakeRevision = (state, collection, fragment) => { export const canMakeRevision = (state, collection, fragment) => {
const currentUserId = get(state, 'currentUser.user.id') const currentUserId = get(state, 'currentUser.user.id')
return ( return (
get(fragment, 'revision') &&
collection.status === 'revisionRequested' && collection.status === 'revisionRequested' &&
fragment.owners.map(o => o.id).includes(currentUserId) fragment.owners.map(o => o.id).includes(currentUserId)
) )
......
...@@ -27,6 +27,7 @@ const ManuscriptLayout = ({ ...@@ -27,6 +27,7 @@ const ManuscriptLayout = ({
history, history,
currentUser, currentUser,
editorInChief, editorInChief,
canMakeRevision,
editorialRecommendations, editorialRecommendations,
project = {}, project = {},
version = {}, version = {},
...@@ -56,7 +57,7 @@ const ManuscriptLayout = ({ ...@@ -56,7 +57,7 @@ const ManuscriptLayout = ({
fragment={version} fragment={version}
startExpanded={isEmpty(version.revision)} startExpanded={isEmpty(version.revision)}
/> />
{version.revision && ( {canMakeRevision && (
<SubmitRevision project={project} version={version} /> <SubmitRevision project={project} version={version} />
)} )}
<ReviewsAndReports project={project} version={version} /> <ReviewsAndReports project={project} version={version} />
......
...@@ -29,6 +29,7 @@ import { ...@@ -29,6 +29,7 @@ import {
getHandlingEditors, getHandlingEditors,
selectHandlingEditors, selectHandlingEditors,
} from 'pubsweet-components-faraday/src/redux/editors' } from 'pubsweet-components-faraday/src/redux/editors'
import { canMakeRevision } from 'pubsweet-component-faraday-selectors/src'
import ManuscriptLayout from './ManuscriptLayout' import ManuscriptLayout from './ManuscriptLayout'
import { parseSearchParams, redirectToError } from './utils' import { parseSearchParams, redirectToError } from './utils'
...@@ -64,6 +65,9 @@ export default compose( ...@@ -64,6 +65,9 @@ export default compose(
updateVersion: actions.updateFragment, updateVersion: actions.updateFragment,
}, },
), ),
connect((state, { project, version }) => ({
canMakeRevision: canMakeRevision(state, project, version),
})),
ConnectPage(({ currentUser, handlingEditors, project }) => { ConnectPage(({ currentUser, handlingEditors, project }) => {
const he = get(project, 'handlingEditor') const he = get(project, 'handlingEditor')
if ( if (
......
...@@ -17,7 +17,7 @@ import { ...@@ -17,7 +17,7 @@ import {
canMakeRevision, canMakeRevision,
canMakeDecision, canMakeDecision,
canMakeRecommendation, canMakeRecommendation,
} from '../../../component-faraday-selectors' } from 'pubsweet-component-faraday-selectors/src'
const SideBarActions = ({ const SideBarActions = ({
project, project,
......
import moment from 'moment' import moment from 'moment'
import { get, find, capitalize, omit, isEmpty, debounce } from 'lodash' import {
get,
find,
omit,
chain,
merge,
isEmpty,
debounce,
capitalize,
} from 'lodash'
import { actions } from 'pubsweet-client/src' import { actions } from 'pubsweet-client/src'
import { change as changeForm } from 'redux-form' import { change as changeForm } from 'redux-form'
...@@ -187,14 +196,23 @@ export const onReviewSubmit = ( ...@@ -187,14 +196,23 @@ export const onReviewSubmit = (
}) })
} }
const parseRevision = (values, fragment) => {
const v = chain(values)
.omit('authorForm')
.omit(v => v === '')
.value()
return {
...fragment,
revision: {
...v,
metadata: merge(v.metadata, fragment.metadata),
},
}
}
const _onRevisionChange = (values, dispatch, { project, version }) => { const _onRevisionChange = (values, dispatch, { project, version }) => {
const newValues = omit(values, 'authorForm') dispatch(actions.updateFragment(project, parseRevision(values, version)))
dispatch(
actions.updateFragment(project, {
...version,
revision: newValues,
}),
)
} }
export const onRevisionChange = debounce(_onRevisionChange, 1000, { export const onRevisionChange = debounce(_onRevisionChange, 1000, {
maxWait: 5000, maxWait: 5000,
...@@ -219,12 +237,10 @@ export const onRevisionSubmit = ( ...@@ -219,12 +237,10 @@ export const onRevisionSubmit = (
onConfirm: () => { onConfirm: () => {
submitRevision(project.id, version.id) submitRevision(project.id, version.id)
.then(r => { .then(r => {
dispatch(actions.getFragments({ id: project.id })) dispatch(actions.getFragments({ id: project.id })).then(() => {
return r history.push(`/projects/${r.collectionId}/versions/${r.id}/details`)
}) hideModal()
.then(r => { })
history.push(`/projects/${r.collectionId}/version/${r.id}/details`)
hideModal()
}) })
.catch(e => setModalError('Something went wrong.')) .catch(e => setModalError('Something went wrong.'))
}, },
......
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