diff --git a/packages/component-email/src/routes/emails/notifications.js b/packages/component-email/src/routes/emails/notifications.js index 23fea64c842350cd283d72b55f58c1b86a920d95..e5783fd5e02ea2586a854a7836fb2096495c2fb0 100644 --- a/packages/component-email/src/routes/emails/notifications.js +++ b/packages/component-email/src/routes/emails/notifications.js @@ -11,7 +11,7 @@ const { getEmailCopy } = require('./emailCopy') module.exports = { async sendNotifications({ user, baseUrl, role, UserModel }) { const userHelper = new User({ UserModel }) - const { firstName, lastName } = await userHelper.getEditorInChief() + const { firstName, lastName } = await userHelper.getEditorsInChief() const eicName = `${firstName} ${lastName}` const email = new Email({ diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js index 65af2dd10ea67925098d318bc9f5d7ff13223d28..ea5790b14676bae5f84abc8be5f230fb9677c4fa 100644 --- a/packages/component-faraday-selectors/src/index.js +++ b/packages/component-faraday-selectors/src/index.js @@ -7,10 +7,12 @@ export const isHEToManuscript = (state, collectionId) => { return get(collection, 'handlingEditor.id') === currentUserId } +const canMakeRecommendationStatuses = ['reviewCompleted', 'heAssigned'] export const canMakeRecommendation = (state, collection, fragment = {}) => { if (fragment.id !== last(collection.fragments)) return false const isHE = isHEToManuscript(state, collection.id) - return isHE && get(collection, 'status') === 'reviewCompleted' + const status = get(collection, 'status') + return isHE && canMakeRecommendationStatuses.includes(status) } export const currentUserIs = ({ currentUser: { user } }, role) => { @@ -60,15 +62,13 @@ export const getHERecommendation = (state, collectionId, fragmentId) => { ) } -const cantMakeDecisionStatuses = ['rejected', 'published', 'draft'] +const canMakeDecisionStatuses = ['submitted', 'pendingApproval'] export const canMakeDecision = (state, collection, fragment = {}) => { if (fragment.id !== last(collection.fragments)) return false const status = get(collection, 'status') - if (!status || cantMakeDecisionStatuses.includes(status)) return false - const isEIC = currentUserIs(state, 'adminEiC') - return isEIC && status + return isEIC && canMakeDecisionStatuses.includes(status) } export const canSeeReviewersReports = (state, collectionId) => { diff --git a/packages/component-helper-service/src/services/User.js b/packages/component-helper-service/src/services/User.js index 074414d59f43dcf979d912244249fce897b7d7b7..2eb092ceeb1220254e93270c9ef2f8dc2876f182 100644 --- a/packages/component-helper-service/src/services/User.js +++ b/packages/component-helper-service/src/services/User.js @@ -41,12 +41,11 @@ class User { return newUser } - async getEditorInChief() { + async getEditorsInChief() { const { UserModel } = this const users = await UserModel.all() - const eic = users.find(user => user.editorInChief || user.admin) - return eic + return users.filter(user => user.editorInChief) } async updateUserTeams({ userId, teamId }) { @@ -65,6 +64,12 @@ class User { return authors.filter(author => activeUsers.includes(author.id)) } + + async getEiCName() { + const editorsInChief = await this.getEditorsInChief() + const { firstName, lastName } = editorsInChief[0] + return `${firstName} ${lastName}` + } } module.exports = User diff --git a/packages/component-helper-service/src/services/email/Email.js b/packages/component-helper-service/src/services/email/Email.js index 8d5b688b6993b3ebb9df7ab25630b926aa7762c6..53436b212dd89df765028f90fc779d4f2e0045bf 100644 --- a/packages/component-helper-service/src/services/email/Email.js +++ b/packages/component-helper-service/src/services/email/Email.js @@ -1,6 +1,7 @@ const config = require('config') const helpers = require('./helpers') const SendEmail = require('@pubsweet/component-send-email') +const logger = require('@pubsweet/logger') class Email { constructor({ @@ -64,14 +65,20 @@ class Email { } sendEmail({ text, html }) { + const fromEmail = config.get('mailer.from') const mailData = { - from: config.get('mailer.from'), + from: fromEmail, to: this.toUser.email, subject: this.content.subject, text, html, } + logger.info( + `EMAIL: Sent email from ${fromEmail} to ${ + this.toUser.email + } with subject '${this.content.subject}'`, + ) SendEmail.send(mailData) } } diff --git a/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js b/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js index 44c00f6856cbb40b92f735a8744df41ce73532b7..90df1a7ce364a2445dd79238dd9f4837392be5c8 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js +++ b/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js @@ -36,7 +36,8 @@ module.exports = { } ${submittingAuthor.lastName}` const userHelper = new User({ UserModel }) - const eic = await userHelper.getEditorInChief() + const eics = await userHelper.getEditorsInChief() + const eic = eics[0] const eicName = `${eic.firstName} ${eic.lastName}` const subjectBaseText = `${collection.customId}: Manuscript ` diff --git a/packages/component-invite/src/routes/fragmentsInvitations/emails/invitations.js b/packages/component-invite/src/routes/fragmentsInvitations/emails/invitations.js index 9dc87ef106e786fc431f3be81acdd054d62313cf..b66445efe0a40c6470d9e04f3485710b5e8432ac 100644 --- a/packages/component-invite/src/routes/fragmentsInvitations/emails/invitations.js +++ b/packages/component-invite/src/routes/fragmentsInvitations/emails/invitations.js @@ -91,7 +91,7 @@ module.exports = { unsubscribeLink: services.createUrl(baseUrl, unsubscribeSlug, { id: invitedUser.id, }), - authorsList, + authorsList: authorsList.join(', '), }, }) diff --git a/packages/component-invite/src/routes/fragmentsInvitations/emails/notifications.js b/packages/component-invite/src/routes/fragmentsInvitations/emails/notifications.js index 12cad6a9d5283e486784a5a08c037b1b4c23d669..9eeb709b629ee52e0ab63624c4a25019b1dc1a95 100644 --- a/packages/component-invite/src/routes/fragmentsInvitations/emails/notifications.js +++ b/packages/component-invite/src/routes/fragmentsInvitations/emails/notifications.js @@ -37,8 +37,7 @@ module.exports = { const handlingEditor = get(collection, 'handlingEditor') const userHelper = new User({ UserModel }) - const { firstName, lastName } = await userHelper.getEditorInChief() - const eicName = `${firstName} ${lastName}` + const eicName = await userHelper.getEiCName() const subjectBaseText = isCanceled ? `${collection.customId}: Reviewer ` : `${collection.customId}: Manuscript ` 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 012113ffdbbd6df5542523b231860bdacaab7032..ee0f6f2918511fe268a35a1b9bca28c6e8d9e4c9 100644 --- a/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js @@ -49,9 +49,7 @@ module.exports = { }) const userHelper = new User({ UserModel }) - const eic = await userHelper.getEditorInChief() - const eicName = `${eic.firstName} ${eic.lastName}` - + const eicName = await userHelper.getEiCName() if (isNewVersion) { sendHandlingEditorEmail({ email, @@ -76,8 +74,8 @@ module.exports = { if (isTechnicalCheck) { sendEQSEmail({ - eic, email, + eicName, baseUrl, collection, subjectBaseText, @@ -157,7 +155,13 @@ const sendReviewersEmail = async ({ }) } -const sendEQSEmail = ({ eic, email, baseUrl, collection, subjectBaseText }) => { +const sendEQSEmail = ({ + email, + eicName, + baseUrl, + collection, + subjectBaseText, +}) => { const emailType = 'eqs-manuscript-submitted' email.toUser = { @@ -166,7 +170,7 @@ const sendEQSEmail = ({ eic, email, baseUrl, collection, subjectBaseText }) => { } email.content.unsubscribeLink = baseUrl - email.content.signatureName = `${eic.firstName} ${eic.lastName}` + email.content.signatureName = eicName email.content.subject = `${subjectBaseText} Submitted` email.content.ctaLink = services.createUrl( baseUrl, diff --git a/packages/component-manuscript-manager/src/routes/fragments/post.js b/packages/component-manuscript-manager/src/routes/fragments/post.js index 6150932b318d711b2eed23d7db81b6588e2a0799..2ec4ab94af0427c9014609b1927f0db01e40a498 100644 --- a/packages/component-manuscript-manager/src/routes/fragments/post.js +++ b/packages/component-manuscript-manager/src/routes/fragments/post.js @@ -52,7 +52,7 @@ module.exports = models => async (req, res) => { }, } - await MTS.sendPackage(packageFragment) + await MTS.sendPackage({ fragment: packageFragment }) notifications.sendNotifications({ fragment, diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js index f99bbd3b5c8ef78a1ed89ff6453df8945a1cc26f..b318595833c0efbf0f46f5b9ff37ad292b504677 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js @@ -47,12 +47,6 @@ module.exports = { }) const userHelper = new User({ UserModel }) - const { - email: eicEmail, - firstName, - lastName, - } = await userHelper.getEditorInChief() - const eicName = `${firstName} ${lastName}` let comments if (isEditorInChief) { @@ -64,12 +58,14 @@ module.exports = { comments = eicComments } - - if (isEditorInChief || newRecommendation.recommendationType === 'review') { + if ( + (isEditorInChief || newRecommendation.recommendationType === 'review') && + collection.status !== 'rejected' + ) { // the request came from either the Editor in Chief or a reviewer, so the HE needs to be notified sendHandlingEditorEmail({ email, - eicName, + eicName: await userHelper.getEiCName(), baseUrl, comments, titleText, @@ -95,28 +91,28 @@ module.exports = { subjectBaseText, newRecommendation, }) + if (collection.status !== 'rejected') { + sendReviewersEmail({ + email, + baseUrl, + UserModel, + titleText, + fragmentHelper, + isEditorInChief, + subjectBaseText, + recommendation: newRecommendation.recommendation, + handlingEditorName: get(collection, 'handlingEditor.name', 'N/A'), + }) - sendReviewersEmail({ - email, - baseUrl, - UserModel, - titleText, - fragmentHelper, - isEditorInChief, - subjectBaseText, - recommendation: newRecommendation.recommendation, - handlingEditorName: get(collection, 'handlingEditor.name', 'N/A'), - }) - - sendEiCEmail({ - email, - baseUrl, - eicName, - eicEmail, - titleText, - subjectBaseText, - recommendation: newRecommendation, - }) + sendEiCsEmail({ + email, + baseUrl, + userHelper, + titleText, + subjectBaseText, + recommendation: newRecommendation, + }) + } } }, } @@ -201,7 +197,7 @@ const sendAuthorsEmail = async ({ email.content.subject = `${subjectBaseText} Published` } else { emailType = 'author-manuscript-rejected' - email.content.subject = `${subjectBaseText} Rejected` + email.content.subject = `${subjectBaseText} Decision` } authors = fragmentAuthors.activeAuthors.map(author => ({ @@ -328,20 +324,18 @@ const sendReviewersEmail = async ({ }, ) const { html, text } = email.getBody({ - body: { paragraph: reviewer.paragraph }, - hasLink: reviewer.hasLink, + body: { paragraph: reviewer.paragraph, hasLink: reviewer.hasLink }, }) email.sendEmail({ html, text }) }) } -const sendEiCEmail = ({ +const sendEiCsEmail = async ({ email, - eicName, - eicEmail, titleText, - recommendation: { recommendation, comments: recComments = [] }, + userHelper, subjectBaseText, + recommendation: { recommendation, comments: recComments = [] }, }) => { let emailType @@ -361,22 +355,29 @@ const sendEiCEmail = ({ throw new Error(`undefined recommendation: ${recommendation} `) } - email.toUser = { - email: eicEmail, - name: eicName, - } - - const privateNote = recComments.find(comm => comm.private) + const privateNote = recComments.find(comm => !comm.public) const content = get(privateNote, 'content') const comments = content ? `Note to Editor: "${content}"` : '' - const { html, text } = email.getBody({ - body: getEmailCopy({ + + const editors = (await userHelper.getEditorsInChief()).map(eic => ({ + ...eic, + ...getEmailCopy({ emailType, titleText, comments, }), + })) + + editors.forEach(eic => { + email.toUser = { + email: eic.email, + name: `${eic.firstName} ${eic.lastName}`, + } + const { html, text } = email.getBody({ + body: { paragraph: eic.paragraph, hasLink: eic.hasLink }, + }) + email.sendEmail({ html, text }) }) - email.sendEmail({ html, text }) } const getSubjectByRecommendation = recommendation => diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js index 37677984272615861c98b4d2b2b7f341078933f6..69135f088fdff18442320398441a8db3f40562d5 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js @@ -1,5 +1,6 @@ const uuid = require('uuid') -const { pick } = require('lodash') +const { pick, get } = require('lodash') +const config = require('config') const { services, @@ -7,6 +8,10 @@ const { Collection, } = require('pubsweet-component-helper-service') +const s3Config = get(config, 'pubsweet-component-aws-s3', {}) +const mtsConfig = get(config, 'mts-service', {}) +const MTSService = require('pubsweet-component-mts-package') + const notifications = require('./notifications/notifications') module.exports = models => async (req, res) => { @@ -70,6 +75,20 @@ module.exports = models => async (req, res) => { fragment.revision = pick(fragment, ['authors', 'files', 'metadata']) } + if (isEditorInChief && recommendation === 'publish') { + const { journal, xmlParser, ftp } = mtsConfig + const MTS = new MTSService(journal, xmlParser, s3Config, ftp) + const packageFragment = { + ...fragment, + metadata: { + ...fragment.metadata, + customId: collection.customId, + }, + } + + await MTS.sendPackage({ fragment: packageFragment, isEQA: true }) + } + notifications.sendNotifications({ fragment, collection, diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js index 0da35cdfd11321ba4fbced245cd01a8e8a9ba22f..782cdbb0c0325048800a2f12096f013319fd8b8f 100644 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js @@ -27,18 +27,9 @@ module.exports = { } ${submittingAuthor.lastName}` const userHelper = new User({ UserModel }) - const { - lastName, - firstName, - email: eicEmail, - } = await userHelper.getEditorInChief() const email = new Email({ type: 'user', - toUser: { - email: eicEmail, - name: `${firstName} ${lastName}`, - }, content: { subject: `${collection.customId}: Manuscript Passed Technical Checks`, signatureName: 'EQS Team', @@ -51,12 +42,23 @@ module.exports = { }, }) - const { html, text } = email.getBody({ - body: getEmailCopy({ - titleText, + const editors = (await userHelper.getEditorsInChief()).map(eic => ({ + ...eic, + ...getEmailCopy({ emailType: 'eqs-manuscript-accepted', + titleText, }), + })) + + editors.forEach(eic => { + email.toUser = { + email: eic.email, + name: `${eic.firstName} ${eic.lastName}`, + } + const { html, text } = email.getBody({ + body: { paragraph: eic.paragraph, hasLink: eic.hasLink }, + }) + email.sendEmail({ html, text }) }) - email.sendEmail({ html, text }) }, } diff --git a/packages/component-manuscript/src/components/SubmitRevision.js b/packages/component-manuscript/src/components/SubmitRevision.js index a962668fb2bbb1537795e8057505a23526e109ad..afaf7697ebebc111d39a773e01ccf69e594c5e48 100644 --- a/packages/component-manuscript/src/components/SubmitRevision.js +++ b/packages/component-manuscript/src/components/SubmitRevision.js @@ -24,6 +24,7 @@ import { import { AuthorList, Files } from 'pubsweet-components-faraday/src/components' import { submitRevision } from 'pubsweet-component-wizard/src/redux/conversion' import AutosaveIndicator from 'pubsweet-component-wizard/src/components/AutosaveIndicator' +import { selectReviewRecommendations } from 'pubsweet-components-faraday/src/redux/recommendations' import { toClass, compose, @@ -60,6 +61,7 @@ const SubmitRevision = ({ removeFile, handleSubmit, responseFiles, + reviews = [], submitFailed, }) => ( <Root> @@ -108,39 +110,41 @@ const SubmitRevision = ({ /> </CustomValidatedField> </Expandable> - <Expandable label="RESPONSE TO REVIEWER COMMENTS" startExpanded> - <Title>Reply text*</Title> - <Row> - <FullWidth className="full-width"> - <ValidatedField - component={TextAreaField} - name="commentsToReviewers" - validate={ - isEmpty(get(formValues, 'files.responseToReviewers')) - ? [required] - : [] - } - /> - </FullWidth> - </Row> - <Row left> - {responseFiles.map(file => ( - <FileItem - compact - id={file.id} - key={file.id} - {...file} - removeFile={removeFile} - /> - ))} - </Row> - <FilePicker - allowedFileExtensions={['pdf', 'doc', 'docx']} - onUpload={addFile} - > - <ActionText left={12}>Upload file</ActionText> - </FilePicker> - </Expandable> + {!isEmpty(reviews) && ( + <Expandable label="RESPONSE TO REVIEWER COMMENTS" startExpanded> + <Title>Reply text*</Title> + <Row> + <FullWidth className="full-width"> + <ValidatedField + component={TextAreaField} + name="commentsToReviewers" + validate={ + isEmpty(get(formValues, 'files.responseToReviewers')) + ? [required] + : [] + } + /> + </FullWidth> + </Row> + <Row left> + {responseFiles.map(file => ( + <FileItem + compact + id={file.id} + key={file.id} + {...file} + removeFile={removeFile} + /> + ))} + </Row> + <FilePicker + allowedFileExtensions={['pdf', 'doc', 'docx']} + onUpload={addFile} + > + <ActionText left={12}>Upload file</ActionText> + </FilePicker> + </Expandable> + )} <SubmitContainer> {submitFailed && formError && <Error>There are some errors above.</Error>} @@ -169,8 +173,9 @@ export default compose( modalComponent: ConfirmationModal, })), connect( - state => ({ + (state, { version }) => ({ fileFetching: getRequestStatus(state), + reviews: selectReviewRecommendations(state, version.id), formValues: getFormValues('revision')(state), formError: getFormSyncErrors('revision')(state), }), diff --git a/packages/component-mts-package/src/MTS.js b/packages/component-mts-package/src/MTS.js index 0d52a235a9d63630cadd9b88cf5e036aced1e11c..a8a9421139c0beafbf844b974658b8e602822b17 100644 --- a/packages/component-mts-package/src/MTS.js +++ b/packages/component-mts-package/src/MTS.js @@ -216,15 +216,19 @@ class MTS { return this.convertToXML(this.composeJson(fragment)) } - sendPackage(fragment = {}) { + sendPackage({ fragment = {}, isEQA = false }) { const xmlFile = this.convertFragmentToXML(fragment) return PackageManager.createFilesPackage(this.s3Config)({ fragment, xmlFile, + isEQA, }).then(() => { - const manuscriptName = get(xmlFile, 'name', '').replace('.xml', '') - const filename = `${manuscriptName}.zip` + const packageName = get(xmlFile, 'name', '').replace('.xml', '') + const filename = isEQA + ? `ACCEPTED_${packageName}.zip` + : `${packageName}.zip` + return PackageManager.uploadFiles({ filename, s3Config: this.s3Config, diff --git a/packages/component-mts-package/src/PackageManager.js b/packages/component-mts-package/src/PackageManager.js index 43d9386c5037e78176ee3a41116fdaf071dfe366..967985f3a45c6170fbd6a4b5d2d627ebe8cac633 100644 --- a/packages/component-mts-package/src/PackageManager.js +++ b/packages/component-mts-package/src/PackageManager.js @@ -19,9 +19,12 @@ const createFilesPackage = (s3Config, archiver = nodeArchiver) => { const asyncGetObject = promisify(s3.getObject.bind(s3)) const asyncListObjects = promisify(s3.listObjects.bind(s3)) - return async ({ fragment, fileTypes, xmlFile }) => { + return async ({ fragment, fileTypes, xmlFile, isEQA = false }) => { const { id } = fragment - const manuscriptName = get(xmlFile, 'name', '').replace('.xml', '') + let packageName = get(xmlFile, 'name', '').replace('.xml', '') + if (isEQA) { + packageName = `ACCEPTED_${packageName}` + } try { const params = { Bucket: s3Config.bucket, @@ -39,7 +42,7 @@ const createFilesPackage = (s3Config, archiver = nodeArchiver) => { ) if (s3Files) { - const packageOutput = fs.createWriteStream(`${manuscriptName}.zip`) + const packageOutput = fs.createWriteStream(`${packageName}.zip`) const archive = archiver('zip') archive.pipe(packageOutput) @@ -53,6 +56,7 @@ const createFilesPackage = (s3Config, archiver = nodeArchiver) => { }) archive.on('error', err => { + logger.error(err) throw err }) archive.on('end', err => { diff --git a/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js b/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js index 8ee396d5206c25e20e52c5145938a8242cbde576..413ea4967f01a4244415681d2505edc1f7847618 100644 --- a/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js +++ b/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js @@ -33,8 +33,6 @@ module.exports = { } ${submittingAuthor.lastName}` const userHelper = new User({ UserModel }) - const { firstName, lastName } = await userHelper.getEditorInChief() - const eicName = `${firstName} ${lastName}` const subjectBaseText = `${collection.customId}: Manuscript` const email = new Email({ @@ -42,7 +40,7 @@ module.exports = { content: { ctaLink: baseUrl, ctaText: 'VIEW DASHBOARD', - signatureName: eicName, + signatureName: await userHelper.getEiCName(), }, }) diff --git a/packages/components-faraday/src/components/Dashboard/DashboardCard.js b/packages/components-faraday/src/components/Dashboard/DashboardCard.js index 2d6ec271f17846f5956c043627d6a5302b8235cf..044a3a21e91903f72a444097b665d116eac4aff2 100644 --- a/packages/components-faraday/src/components/Dashboard/DashboardCard.js +++ b/packages/components-faraday/src/components/Dashboard/DashboardCard.js @@ -66,6 +66,7 @@ const DashboardCard = ({ collectionId={project.id} fragmentId={version.id} modalKey={`decide-${version.id}`} + status={project.status} /> )} {canMakeRecommendation && ( @@ -73,6 +74,7 @@ const DashboardCard = ({ collectionId={project.id} fragmentId={version.id} modalKey={`recommend-${version.id}`} + status={project.status} /> )} <ZipFiles diff --git a/packages/components-faraday/src/components/MakeDecision/Decision.js b/packages/components-faraday/src/components/MakeDecision/Decision.js index cf4279e1615dc66ec08c8deb6cd8fab98ca16207..be2b86e66f15032614dea4d9d832b43823d13bc0 100644 --- a/packages/components-faraday/src/components/MakeDecision/Decision.js +++ b/packages/components-faraday/src/components/MakeDecision/Decision.js @@ -1,17 +1,21 @@ import React from 'react' import { th } from '@pubsweet/ui' +import { connect } from 'react-redux' import styled from 'styled-components' -import { compose, withHandlers, setDisplayName } from 'recompose' +import { actions } from 'pubsweet-client' +import { compose, withHandlers, setDisplayName, withProps } from 'recompose' import { ConfirmationModal, withModal, } from 'pubsweet-component-modal/src/components' +import { handleError } from '../utils' +import { createRecommendation } from '../../redux/recommendations' import { DecisionForm } from './' -const Decision = ({ showDecisionModal }) => ( - <Root onClick={showDecisionModal}>Make decision</Root> +const Decision = ({ showDecisionModal, buttonText }) => ( + <Root onClick={showDecisionModal}>{buttonText}</Root> ) const ModalComponent = ({ type, ...rest }) => { @@ -28,19 +32,55 @@ export default compose( withModal(() => ({ modalComponent: ModalComponent, })), + connect(null, { + createRecommendation, + getFragments: actions.getFragments, + getCollections: actions.getCollections, + }), + withProps(({ status }) => ({ + buttonText: status === 'submitted' ? 'Reject' : 'Make Decision', + })), withHandlers({ showDecisionModal: ({ + status, showModal, hideModal, fragmentId, collectionId, + getFragments, + setModalError, + getCollections, + createRecommendation, }) => () => { - showModal({ - type: 'decision', - hideModal, - fragmentId, - collectionId, - }) + status !== 'submitted' + ? showModal({ + type: 'decision', + hideModal, + fragmentId, + collectionId, + }) + : showModal({ + hideModal, + fragmentId, + collectionId, + title: 'Reject Manuscript?', + confirmText: 'Reject', + onConfirm: () => { + const recommendation = { + recommendation: 'reject', + recommendationType: 'editorRecommendation', + } + createRecommendation( + collectionId, + fragmentId, + recommendation, + ).then(() => { + getCollections() + getFragments() + hideModal() + }, handleError(setModalError)) + }, + }) }, }), )(Decision) diff --git a/packages/components-faraday/src/components/MakeDecision/DecisionForm.js b/packages/components-faraday/src/components/MakeDecision/DecisionForm.js index 0a53c9423317ac06571ebf6470b6ee16b957fb0f..3fab58f21c15bcdd312cc0fa0f8df64ef928350e 100644 --- a/packages/components-faraday/src/components/MakeDecision/DecisionForm.js +++ b/packages/components-faraday/src/components/MakeDecision/DecisionForm.js @@ -27,7 +27,6 @@ const { const Form = RootContainer.withComponent(FormContainer) const DecisionForm = ({ - aHERec, decision, hideModal, handleSubmit, diff --git a/packages/components-faraday/src/components/MakeRecommendation/Recommendation.js b/packages/components-faraday/src/components/MakeRecommendation/Recommendation.js index 10d7fc6d98a6a1f1ce932aa5b6622015eee59530..dff35cbd4f9388814ac47cb005a418462845e9a5 100644 --- a/packages/components-faraday/src/components/MakeRecommendation/Recommendation.js +++ b/packages/components-faraday/src/components/MakeRecommendation/Recommendation.js @@ -30,12 +30,14 @@ export default compose( })), withHandlers({ showFirstStep: ({ + status, showModal, hideModal, fragmentId, collectionId, }) => () => { showModal({ + status, hideModal, fragmentId, collectionId, diff --git a/packages/components-faraday/src/components/MakeRecommendation/StepOne.js b/packages/components-faraday/src/components/MakeRecommendation/StepOne.js index 6185a09a1677c060032875ce80ebf83c4e1139be..b6723f9ff0a70dd03fb30668d2e8db606247cd66 100644 --- a/packages/components-faraday/src/components/MakeRecommendation/StepOne.js +++ b/packages/components-faraday/src/components/MakeRecommendation/StepOne.js @@ -7,7 +7,7 @@ import { FormItems } from '../UIComponents' const { Row, Title, RowItem, RootContainer, CustomRadioGroup } = FormItems -const StepOne = ({ hideModal, disabled, onSubmit }) => ( +const StepOne = ({ hideModal, disabled, onSubmit, status }) => ( <RootContainer> <Title>Recommendation for Next Phase</Title> <Row> @@ -20,7 +20,11 @@ const StepOne = ({ hideModal, disabled, onSubmit }) => ( > <RadioGroup name="decision" - options={utils.recommendationOptions} + options={ + status === 'reviewCompleted' + ? utils.recommendationOptions + : utils.recommendationOptions.slice(1) + } {...input} /> </CustomRadioGroup> diff --git a/packages/components-faraday/src/components/MakeRecommendation/utils.js b/packages/components-faraday/src/components/MakeRecommendation/utils.js index 2884cdb904717cfdd4958cc99accf9f852adc489..69e5b63f12e4b979dba34332a98fa8bec20eed17 100644 --- a/packages/components-faraday/src/components/MakeRecommendation/utils.js +++ b/packages/components-faraday/src/components/MakeRecommendation/utils.js @@ -1,8 +1,8 @@ import { omit } from 'lodash' export const recommendationOptions = [ - { value: 'reject', label: 'Reject' }, { value: 'publish', label: 'Publish' }, + { value: 'reject', label: 'Reject' }, { value: 'revise', label: 'Request revision' }, ] diff --git a/packages/components-faraday/src/components/SignUp/utils.js b/packages/components-faraday/src/components/SignUp/utils.js index ae98c93c7df0b2d169affe222f81c2c79f412311..c5564bfe044faa2d7903253efb4ac688082567d5 100644 --- a/packages/components-faraday/src/components/SignUp/utils.js +++ b/packages/components-faraday/src/components/SignUp/utils.js @@ -15,6 +15,7 @@ const generatePasswordHash = () => export const parseSignupAuthor = ({ token, confirmPassword, ...values }) => ({ ...values, admin: false, + isActive: true, isConfirmed: false, editorInChief: false, handlingEditor: false, diff --git a/packages/xpub-faraday/config/default.js b/packages/xpub-faraday/config/default.js index 0e8568e0dc11ee83148a032d079c88617345c49a..d967fc6b6759301fb5cefe810713b65ab691aa83 100644 --- a/packages/xpub-faraday/config/default.js +++ b/packages/xpub-faraday/config/default.js @@ -110,9 +110,9 @@ module.exports = { }, }, mailer: { - from: 'faraday@hindawi.com', + from: 'hindawi@thinslices.com', path: `${__dirname}/mailer`, - editorialAssistant: 'hindawi@thinslices.com', + editorialAssistant: 'hindawi+editorial@thinslices.com', }, publicKeys: ['pubsweet-client', 'authsome', 'validations'], statuses: {