From 6f81b52cc327372320aab796603dc7da17fccde1 Mon Sep 17 00:00:00 2001 From: Alexandru Munteanu <alexandru.munt@gmail.com> Date: Tue, 11 Sep 2018 10:58:01 +0300 Subject: [PATCH] feat(eqs-decision): update backend for eqs decision --- .../fragments/notifications/notifications.js | 3 + .../src/routes/technicalChecks/patch.js | 21 ++- .../src/components/SubmissionConfirmation.js | 38 +++--- .../UIComponents/EQSDecisionPage.js | 126 +++++++++--------- .../src/redux/technicalCheck.js | 2 + 5 files changed, 105 insertions(+), 85 deletions(-) diff --git a/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js index 00e10fb91..dc3c37671 100644 --- a/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js @@ -83,6 +83,7 @@ module.exports = { baseUrl, collection, subjectBaseText, + title: parsedFragment.title, }) sendAuthorsEmail({ email, @@ -171,6 +172,7 @@ const sendReviewersEmail = async ({ const sendEQSEmail = ({ email, + title, eicName, baseUrl, collection, @@ -190,6 +192,7 @@ const sendEQSEmail = ({ baseUrl, config.get('eqs-decision.url'), { + title, collectionId: collection.id, customId: collection.customId, token: collection.technicalChecks.token, diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js index 453ae84c7..2605a9530 100644 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js @@ -1,4 +1,4 @@ -const { get, isEmpty } = require('lodash') +const { get, find, isEmpty } = require('lodash') const { services } = require('pubsweet-component-helper-service') const { sendNotifications } = require('./notifications/notifications') @@ -18,12 +18,19 @@ const setNewStatus = (step, agree) => { module.exports = ({ Collection, Fragment, User }) => async (req, res) => { const { collectionId } = req.params - const { token, agree, step, comments } = req.body + const { token, agree, step, comments, customId } = req.body try { + const collections = await Collection.all() const collection = await Collection.find(collectionId) const technicalCheckToken = get(collection, `technicalChecks.token`) + if (find(collections, c => c.customId === customId)) { + return res.status(400).json({ + error: `CustomID already assigned to a manuscript.`, + }) + } + if (isEmpty(technicalCheckToken)) { return res.status(400).json({ error: `Manuscript already handled.`, @@ -37,9 +44,15 @@ module.exports = ({ Collection, Fragment, User }) => async (req, res) => { } delete collection.technicalChecks.token - if (step === TECHNICAL_STEPS.EQA && agree) { - collection.technicalChecks.eqa = true + if (agree) { + if (step === TECHNICAL_STEPS.EQA) { + collection.technicalChecks.eqa = true + } + if (step === TECHNICAL_STEPS.EQS) { + collection.customId = customId + } } + collection.status = setNewStatus(step, agree) await collection.save() diff --git a/packages/component-wizard/src/components/SubmissionConfirmation.js b/packages/component-wizard/src/components/SubmissionConfirmation.js index d45145bd2..f258b3153 100644 --- a/packages/component-wizard/src/components/SubmissionConfirmation.js +++ b/packages/component-wizard/src/components/SubmissionConfirmation.js @@ -1,38 +1,36 @@ import React from 'react' import { get } from 'lodash' -import styled from 'styled-components' -import { H1, Button } from '@pubsweet/ui' +import { H2, Button } from '@pubsweet/ui' import { withJournal } from 'xpub-journal' -import { Text, Row } from 'pubsweet-component-faraday-ui' +import { Text, Row, ShadowedBox } from 'pubsweet-component-faraday-ui' const SubmissionConfirmation = ({ history, journal }) => ( - <Root> - <H1>Thank You for Submitting Your Manuscript</H1> - <Text secondary> - Your manuscript has been successfully submitted to{' '} - <b>{get(journal, 'metadata.nameText', '')}</b>. - </Text> + <ShadowedBox center mt={5} width={75}> + <H2>Thank You for Submitting Your Manuscript</H2> + <Row justify="center"> + <Text secondary> + Your manuscript has been successfully submitted to{' '} + <b>{get(journal, 'metadata.nameText', '')}</b>. + </Text> + </Row> - <Row mb={2} mt={2}> - <Text align="center"> + <Row mb={3} mt={2} pl={2} pr={2}> + <Text align="justify"> An acknowledgment email will be sent to all authors when our system has finished processing the submission - at which point a manuscript ID will be assigned, and you will be able to track the manuscript status on your dashboard. </Text> </Row> - <Button onClick={() => history.push('/')} primary> - GO TO DASHBOARD - </Button> - </Root> + <Row justify="center"> + <Button onClick={() => history.push('/')} primary> + GO TO DASHBOARD + </Button> + </Row> + </ShadowedBox> ) export default withJournal(SubmissionConfirmation) // #region styles -const Root = styled.div` - align-items: center; - display: flex; - flex-direction: column; -` // #endregion diff --git a/packages/components-faraday/src/components/UIComponents/EQSDecisionPage.js b/packages/components-faraday/src/components/UIComponents/EQSDecisionPage.js index 398fdf74f..ed37e2070 100644 --- a/packages/components-faraday/src/components/UIComponents/EQSDecisionPage.js +++ b/packages/components-faraday/src/components/UIComponents/EQSDecisionPage.js @@ -38,7 +38,7 @@ const Enhanched = () => ( <Label required>Manuscript ID</Label> <ValidatedField component={TextField} - name="manuscriptId" + name="customId" validate={[required, digitValidator, sizeValidator]} /> </Item> @@ -47,20 +47,38 @@ const Enhanched = () => ( const FormModal = reduxForm({ form: 'eqs', - onSubmit: (values, dispatch, { acceptManuscript }) => { - acceptManuscript(values) + onSubmit: ( + { customId }, + dispatch, + { technicalDecision, params: { collectionId, token }, setSuccess }, + ) => ({ hideModal, setModalError }) => { + technicalDecision({ + token, + customId, + step: 'eqs', + agree: true, + collectionId, + }) + .then(() => { + hideModal() + setSuccess(`Manuscript accepted. Thank you for your technical check!`) + }) + .catch(e => { + setModalError(`There was an error: ${e}`) + }) }, -})(({ isFetching, handleSubmit }) => ( +})(({ isFetching, handleSubmit, technicalDecision, ...formProps }) => ( <OpenModal content={Enhanched} isFetching={isFetching} modalKey="acceptManuscript" - onConfirm={() => handleSubmit()} + onConfirm={modalProps => handleSubmit()(modalProps)} + technicalDecision={technicalDecision} title="Accept Manuscript" > {showModal => ( <Button onClick={showModal} primary> - ACCEPT + YES </Button> )} </OpenModal> @@ -70,41 +88,44 @@ const EQSDecisionPage = ({ params, isFetching, eqsDecision, - errorMessage, successMessage, + rejectManuscript, + technicalDecision, + ...rest }) => ( <ShadowedBox center mt={5}> <H2>Editorial decision</H2> - <Row mt={2}> - <Text secondary> - Please take a decision for the manuscript titled <b>{params.title}</b>. - </Text> - </Row> + {!successMessage && ( + <Row mt={2}> + <Text secondary> + Did manuscript titled <b>{params.title}</b> pass EQS checks? + </Text> + </Row> + )} {successMessage && ( <Row mt={1}> <Text>{successMessage}</Text> </Row> )} - {errorMessage && ( - <Row mt={1}> - <Text error>{errorMessage}</Text> + {isEmpty(successMessage) && ( + <Row justify="space-around" mt={2}> + <OpenModal + isFetching={isFetching} + modalKey="denyManuscript" + onConfirm={rejectManuscript} + subtitle="Are you sure you want to reject this manuscript?" + title="Reject manuscript" + > + {showModal => <Button onClick={showModal}>NO</Button>} + </OpenModal> + <FormModal + isFetching={isFetching} + params={params} + technicalDecision={technicalDecision} + {...rest} + /> </Row> )} - {isEmpty(errorMessage) && - isEmpty(successMessage) && ( - <Row justify="space-around" mt={2}> - <OpenModal - isFetching={isFetching} - modalKey="denyManuscript" - onConfirm={() => {}} - subtitle="Are you sure you want to reject this manuscript?" - title="Reject manuscript" - > - {showModal => <Button onClick={showModal}>REJECT</Button>} - </OpenModal> - <FormModal acceptManuscript={v => {}} isFetching={isFetching} /> - </Row> - )} </ShadowedBox> ) @@ -123,7 +144,6 @@ export default compose( collectionId: null, }), withState('successMessage', 'setSuccess', ''), - withState('errorMessage', 'setError', ''), lifecycle({ componentDidMount() { const { location, setParams } = this.props @@ -134,40 +154,24 @@ export default compose( }, }), withHandlers({ - eqsDecision: ({ - setError, - showModal, - hideModal, + rejectManuscript: ({ setSuccess, technicalDecision, params: { collectionId, token }, - }) => decision => () => { - showModal({ - title: `Are you sure you want to ${ - decision ? 'accept' : 'reject' - } this EQS package?`, - onConfirm: () => { - technicalDecision({ - step: 'eqs', - agree: decision, - collectionId, - token, - }) - .then(() => { - setSuccess( - `Manuscript ${ - decision ? 'accepted' : 'rejected' - }. Thank you for your technical check!`, - ) - hideModal() - }) - .catch(() => { - setError('There was an error. Please try again.') - hideModal() - }) - }, - onCancel: hideModal, + }) => ({ hideModal, setModalError }) => { + technicalDecision({ + token, + step: 'eqs', + agree: false, + collectionId, }) + .then(() => { + hideModal() + setSuccess(`Manuscript rejected. Thank you for your technical check!`) + }) + .catch(e => { + setModalError(`There was an error: ${e}`) + }) }, }), )(EQSDecisionPage) diff --git a/packages/components-faraday/src/redux/technicalCheck.js b/packages/components-faraday/src/redux/technicalCheck.js index 5c8d7b9c2..447674ad7 100644 --- a/packages/components-faraday/src/redux/technicalCheck.js +++ b/packages/components-faraday/src/redux/technicalCheck.js @@ -22,6 +22,7 @@ export const technicalDecision = ({ step, agree, token, + customId, comments, collectionId, }) => dispatch => { @@ -30,6 +31,7 @@ export const technicalDecision = ({ step, token, agree, + customId, comments, }).then( r => { -- GitLab