diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js index ea5790b14676bae5f84abc8be5f230fb9677c4fa..6508a91a4921237406bd5b9e386e167f1e608977 100644 --- a/packages/component-faraday-selectors/src/index.js +++ b/packages/component-faraday-selectors/src/index.js @@ -24,6 +24,10 @@ export const currentUserIs = ({ currentUser: { user } }, role) => { return isHe case 'staff': return isAdmin || isEic || isHe + case 'isEiC': + return isEic + case 'isAdmin': + return isAdmin case 'adminEiC': return isAdmin || isEic default: @@ -71,6 +75,15 @@ export const canMakeDecision = (state, collection, fragment = {}) => { return isEIC && canMakeDecisionStatuses.includes(status) } +const canEditManuscriptStatuses = ['draft', 'technicalChecks'] +export const canEditManuscript = (state, collection, fragment = {}) => { + if (fragment.id !== last(collection.fragments)) return false + const status = get(collection, 'status') + + const isAdmin = currentUserIs(state, 'isAdmin') + return isAdmin && canEditManuscriptStatuses.includes(status) +} + export const canSeeReviewersReports = (state, collectionId) => { const isHE = isHEToManuscript(state, collectionId) const isEiC = currentUserIs(state, 'adminEiC') diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js index 7c68d8ef1d2db6d3f13592a8afaa2a4a6e0408a7..c0ed8a1f1635315f2e1f5aa3ea048fec535ab306 100644 --- a/packages/component-manuscript/src/components/ManuscriptLayout.js +++ b/packages/component-manuscript/src/components/ManuscriptLayout.js @@ -30,7 +30,6 @@ const ManuscriptLayout = ({ editorInChief, canMakeRevision, editorialRecommendations, - responseToReviewers, hasResponseToReviewers, project = {}, version = {}, diff --git a/packages/component-manuscript/src/components/SideBarActions.js b/packages/component-manuscript/src/components/SideBarActions.js index d5e8b16b033cf934842da48a3126b4fd686545d0..dbfc3d7cd8c6bcbd6f7ce6a70176913185514c9a 100644 --- a/packages/component-manuscript/src/components/SideBarActions.js +++ b/packages/component-manuscript/src/components/SideBarActions.js @@ -1,6 +1,6 @@ import React from 'react' -import { compose } from 'recompose' -import { Icon } from '@pubsweet/ui' +import { compose, withHandlers } from 'recompose' +import { Icon, Button } from '@pubsweet/ui' import { connect } from 'react-redux' import styled from 'styled-components' import { th } from '@pubsweet/ui-toolkit' @@ -11,21 +11,30 @@ import { Recommendation, } from 'pubsweet-components-faraday/src/components' -import { createRevision } from 'pubsweet-component-wizard/src/redux/conversion' - import { canMakeDecision, canMakeRecommendation, + canEditManuscript, } from 'pubsweet-component-faraday-selectors/src' const SideBarActions = ({ project, version, - createRevision, + goToEdit, canMakeDecision, + canEditManuscript, canMakeRecommendation, }) => ( <Root> + {canEditManuscript && ( + <Button + data-test="button-edit-manuscript" + onClick={goToEdit(project, version)} + primary + > + Edit + </Button> + )} {canMakeDecision && ( <Decision collectionId={project.id} @@ -55,15 +64,18 @@ const SideBarActions = ({ export default compose( withRouter, - connect( - (state, { project, version }) => ({ - canMakeDecision: canMakeDecision(state, project, version), - canMakeRecommendation: canMakeRecommendation(state, project, version), - }), - (dispatch, { project, version, history }) => ({ - createRevision: () => dispatch(createRevision(project, version, history)), - }), - ), + connect((state, { project, version }) => ({ + canMakeDecision: canMakeDecision(state, project, version), + canMakeRecommendation: canMakeRecommendation(state, project, version), + canEditManuscript: canEditManuscript(state, project, version), + })), + withHandlers({ + goToEdit: ({ history }) => (project, version) => () => { + history.push(`/projects/${project.id}/versions/${version.id}/submit`, { + editMode: true, + }) + }, + }), )(SideBarActions) // #region styled-components diff --git a/packages/component-wizard/src/components/SubmissionWizard.js b/packages/component-wizard/src/components/SubmissionWizard.js index 162de41426cb1e4d6ab014aeac2c8e9f6c632031..76ea5eadbacef57a645c6a36255b53b9c7f1ea55 100644 --- a/packages/component-wizard/src/components/SubmissionWizard.js +++ b/packages/component-wizard/src/components/SubmissionWizard.js @@ -10,7 +10,13 @@ import { DragDropContext } from 'react-dnd' import { Icon, Button } from '@pubsweet/ui' import HTML5Backend from 'react-dnd-html5-backend' import { selectCollection, selectFragment } from 'xpub-selectors' -import { withStateHandlers, compose, toClass, withProps } from 'recompose' +import { + withStateHandlers, + compose, + toClass, + withProps, + withHandlers, +} from 'recompose' import { withModal, @@ -44,9 +50,11 @@ const NewWizard = ({ step, history, prevStep, + isEditMode, isLastStep, isFirstStep, handleSubmit, + getButtonText, journal: { manuscriptTypes = [] }, ...rest }) => ( @@ -76,7 +84,7 @@ const NewWizard = ({ >{`< BACK`}</Button> )} <Button data-test="submission-next" onClick={handleSubmit} primary> - {isLastStep ? `SUBMIT MANUSCRIPT` : `NEXT STEP >`} + {getButtonText()} </Button> </ButtonContainer> </Row> @@ -132,13 +140,22 @@ export default compose( }, ), withProps(setInitialValues), - withProps(({ formValues, formSyncErrors, submitFailed, step }) => ({ + withProps(({ formValues, formSyncErrors, submitFailed, step, location }) => ({ isFirstStep: step === 0, isLastStep: step === wizardSteps.length - 1, filesError: submitFailed && get(formSyncErrors, 'files', ''), authorsError: submitFailed && get(formSyncErrors, 'authors', ''), hasConflicts: get(formValues, 'conflicts.hasConflicts', 'no') === 'yes', + isEditMode: get(location, 'state.editMode', false), })), + withHandlers({ + getButtonText: ({ isLastStep, isEditMode }) => () => { + if (isEditMode && isLastStep) { + return 'SAVE CHANGES' + } + return isLastStep ? `SUBMIT MANUSCRIPT` : `NEXT STEP >` + }, + }), withModal(() => ({ modalComponent: ModalWrapper, })), diff --git a/packages/component-wizard/src/components/utils.js b/packages/component-wizard/src/components/utils.js index 27f14a882079cbb52d613d6f26e4385bc87c0315..eaef4c5aa092b554fae967b24d7755f0f5665ebc 100644 --- a/packages/component-wizard/src/components/utils.js +++ b/packages/component-wizard/src/components/utils.js @@ -82,6 +82,7 @@ export const onSubmit = ( nextStep, showModal, hideModal, + isEditMode, setModalError, autosaveRequest, autosaveSuccess, @@ -93,7 +94,7 @@ export const onSubmit = ( ) => { if (step !== 2) { nextStep() - } else { + } else if (!isEditMode) { showModal({ title: 'By submitting the manuscript you agree to the following statements:', @@ -119,5 +120,7 @@ export const onSubmit = ( }, onCancel: hideModal, }) + } else { + history.goBack() } } diff --git a/packages/xpub-faraday/config/default.js b/packages/xpub-faraday/config/default.js index d967fc6b6759301fb5cefe810713b65ab691aa83..7ed508e70cd8daf96855461bdca80167a16ff59d 100644 --- a/packages/xpub-faraday/config/default.js +++ b/packages/xpub-faraday/config/default.js @@ -46,7 +46,7 @@ module.exports = { API_ENDPOINT: '/api', baseUrl: process.env.CLIENT_BASE_URL || 'http://localhost:3000', 'login-redirect': '/', - 'redux-log': process.env.NODE_ENV === 'development', + 'redux-log': process.env.NODE_ENV !== 'production', theme: process.env.PUBSWEET_THEME, }, orcid: {