From c416920a801081c4e4b18b66dffd808227d35280 Mon Sep 17 00:00:00 2001 From: Alexandru Munteanu <alexandru.munt@gmail.com> Date: Thu, 2 Aug 2018 10:58:18 +0300 Subject: [PATCH] feat(eqs-decision): send mail to eic --- .../fragments/notifications/notifications.js | 10 ++- .../src/routes/fragments/post.js | 4 +- .../notifications/emailCopy.js | 16 +++++ .../notifications/notifications.js | 62 +++++++++++++++++++ .../src/routes/technicalChecks/patch.js | 11 +++- .../UIComponents/EQSDecisionPage.js | 1 - packages/xpub-faraday/config/default.js | 3 + 7 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 packages/component-manuscript-manager/src/routes/technicalChecks/notifications/emailCopy.js create mode 100644 packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js 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 2d362b840..b2d0f8e26 100644 --- a/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js @@ -167,7 +167,15 @@ const sendEQSEmail = ({ eic, email, baseUrl, collection, subjectBaseText }) => { email.content.unsubscribeLink = baseUrl email.content.signatureName = `${eic.firstName} ${eic.lastName}` email.content.subject = `${subjectBaseText} Submitted` - email.content.ctaLink = '' + email.content.ctaLink = services.createUrl( + baseUrl, + config.get('eqs-decision.url'), + { + collectionId: collection.id, + customId: collection.customId, + token: collection.technicalChecks.token, + }, + ) email.content.ctaText = 'MAKE DECISION' const { html, text } = email.getBody({ diff --git a/packages/component-manuscript-manager/src/routes/fragments/post.js b/packages/component-manuscript-manager/src/routes/fragments/post.js index 7efc61b10..6150932b3 100644 --- a/packages/component-manuscript-manager/src/routes/fragments/post.js +++ b/packages/component-manuscript-manager/src/routes/fragments/post.js @@ -1,5 +1,6 @@ +const { v4 } = require('uuid') const config = require('config') -const { get } = require('lodash') +const { get, set } = require('lodash') const { services, authsome: authsomeHelper, @@ -38,6 +39,7 @@ module.exports = models => async (req, res) => { fragment = await fragment.save() collection.status = 'technicalChecks' + set(collection, 'technicalChecks.token', v4()) await collection.save() const { journal, xmlParser, ftp } = mtsConfig diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/emailCopy.js b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/emailCopy.js new file mode 100644 index 000000000..c562e8be4 --- /dev/null +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/emailCopy.js @@ -0,0 +1,16 @@ +const getEmailCopy = ({ emailType, titleText }) => { + let paragraph + switch (emailType) { + case 'eqs-manuscript-accepted': + paragraph = `We are please to inform you that ${titleText} has passed the Hindawi technical check process and is now submitted. Please click the link below to access the manuscript.` + break + default: + throw new Error(`The ${emailType} email type is not defined.`) + } + + return { paragraph, hasLink: true } +} + +module.exports = { + getEmailCopy, +} diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js new file mode 100644 index 000000000..0da35cdfd --- /dev/null +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js @@ -0,0 +1,62 @@ +const { + User, + Email, + services, + Fragment, +} = require('pubsweet-component-helper-service') +const { getEmailCopy } = require('./emailCopy') + +module.exports = { + async sendNotifications({ + baseUrl, + collection, + User: UserModel, + Fragment: FragmentModel, + }) { + const fragment = await FragmentModel.find(collection.fragments[0]) + const fragmentHelper = new Fragment({ fragment }) + const parsedFragment = await fragmentHelper.getFragmentData({ + handlingEditor: collection.handlingEditor, + }) + const { submittingAuthor } = await fragmentHelper.getAuthorData({ + UserModel, + }) + + const titleText = `the manuscript titled "${parsedFragment.title}" by ${ + submittingAuthor.firstName + } ${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', + ctaLink: services.createUrl( + baseUrl, + `/projects/${collection.id}/versions/${fragment.id}/details`, + ), + ctaText: 'MANUSCRIPT DETAILS', + unsubscribeLink: baseUrl, + }, + }) + + const { html, text } = email.getBody({ + body: getEmailCopy({ + titleText, + emailType: 'eqs-manuscript-accepted', + }), + }) + email.sendEmail({ html, text }) + }, +} diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js index f415d8e1e..f0f354748 100644 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js @@ -1,6 +1,8 @@ const { get, isEmpty } = require('lodash') const { services } = require('pubsweet-component-helper-service') +const { sendNotifications } = require('./notifications/notifications') + const TECHNICAL_STEPS = { EQS: 'eqs', EQA: 'eqa', @@ -14,7 +16,7 @@ const setNewStatus = (step, agree) => { } } -module.exports = ({ Collection }) => async (req, res) => { +module.exports = ({ Collection, Fragment, User }) => async (req, res) => { const { collectionId } = req.params const { token, agree, step } = req.body @@ -38,7 +40,12 @@ module.exports = ({ Collection }) => async (req, res) => { collection.status = setNewStatus(step, agree) await collection.save() - // TODO: send email to EiC here + sendNotifications({ + User, + Fragment, + collection, + baseUrl: services.getBaseUrl(req), + }) return res.status(200).json(collection) } catch (e) { diff --git a/packages/components-faraday/src/components/UIComponents/EQSDecisionPage.js b/packages/components-faraday/src/components/UIComponents/EQSDecisionPage.js index 4e3f753ed..3217266f7 100644 --- a/packages/components-faraday/src/components/UIComponents/EQSDecisionPage.js +++ b/packages/components-faraday/src/components/UIComponents/EQSDecisionPage.js @@ -33,7 +33,6 @@ const EQSDecisionPage = ({ <Root> <Title> Take a decision for manuscript <b>{params.customId}</b>. - {params.collectionId} </Title> {errorMessage && <Err>{errorMessage}</Err>} {successMessage && <Subtitle>{successMessage}</Subtitle>} diff --git a/packages/xpub-faraday/config/default.js b/packages/xpub-faraday/config/default.js index 945cc96a6..3d84183a8 100644 --- a/packages/xpub-faraday/config/default.js +++ b/packages/xpub-faraday/config/default.js @@ -94,6 +94,9 @@ module.exports = { 'confirm-signup': { url: process.env.PUBSWEET_CONFIRM_SIGNUP_URL || '/confirm-signup', }, + 'eqs-decision': { + url: process.env.PUBSWEET_EQS_DECISION || '/eqs-decision', + }, unsubscribe: { url: process.env.PUBSWEET_UNSUBSCRIBE_URL || '/unsubscribe', }, -- GitLab