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 2d362b84035b7ff979560c3c9fd1ecd885fd4d49..b2d0f8e2614db48c467cfe5440c1c156332361ab 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 7efc61b1055778bf8e04b30447eabf8dbabbed91..6150932b318d711b2eed23d7db81b6588e2a0799 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 0000000000000000000000000000000000000000..c562e8be47b57e98d965e88681150adead6057b0 --- /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 0000000000000000000000000000000000000000..0da35cdfd11321ba4fbced245cd01a8e8a9ba22f --- /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 f415d8e1edacc5d521294974d3755d38807ccd7d..f0f354748dda452dbe809150f151f59d85e27e2f 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 4e3f753ed0e2a52df80411ea6cee56c71a5f5352..3217266f7a46152387438f73d58b9852ee7e44b5 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 945cc96a6ae9655316723d09687998939bbacee9..3d84183a8d9058de2dbe526e60130994f552e548 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', },