diff --git a/packages/component-email/src/routes/emails/notifications.js b/packages/component-email/src/routes/emails/notifications.js index e5783fd5e02ea2586a854a7836fb2096495c2fb0..1a89afff1ae771239a7fd6b6dba64a493b96f414 100644 --- a/packages/component-email/src/routes/emails/notifications.js +++ b/packages/component-email/src/routes/emails/notifications.js @@ -11,8 +11,7 @@ const { getEmailCopy } = require('./emailCopy') module.exports = { async sendNotifications({ user, baseUrl, role, UserModel }) { const userHelper = new User({ UserModel }) - const { firstName, lastName } = await userHelper.getEditorsInChief() - const eicName = `${firstName} ${lastName}` + const eicName = await userHelper.getEiCName() const email = new Email({ type: 'user', diff --git a/packages/component-helper-service/src/services/email/templates/partials/button.hbs b/packages/component-helper-service/src/services/email/templates/partials/button.hbs index 3b78683c484d20b9bdfcf72d7b68e9490ba04230..5b8b0493173d905c8a8a98322e4da5b0173a7302 100644 --- a/packages/component-helper-service/src/services/email/templates/partials/button.hbs +++ b/packages/component-helper-service/src/services/email/templates/partials/button.hbs @@ -6,8 +6,8 @@ <table border="0" cellPadding="0" cellSpacing="0" class="button-css__deep-table___2OZyb wrapper-mobile" style="text-align:center"> <tbody> <tr> - <td align="center" bgcolor="#0d78f2" class="inner-td" style="border-radius:6px;font-size:16px;text-align:center;background-color:inherit"> - <a href="{{ ctaLink }}" style="background-color:#0d78f2;border:1px solid #333333;border-color:#0d78f2;border-radius:0px;border-width:1px;color:#ffffff;display:inline-block;font-family:arial,helvetica,sans-serif;font-size:16px;font-weight:normal;letter-spacing:0px;line-height:16px;padding:12px 18px 12px 18px;text-align:center;text-decoration:none" + <td align="center" bgcolor="#63a945" class="inner-td" style="border-radius:6px;font-size:16px;text-align:center;background-color:inherit"> + <a href="{{ ctaLink }}" style="background-color:#63a945;border:1px solid #333333;border-color:#63a945;border-radius:0px;border-width:1px;color:#ffffff;display:inline-block;font-family:arial,helvetica,sans-serif;font-size:16px;font-weight:normal;letter-spacing:0px;line-height:16px;padding:12px 18px 12px 18px;text-align:center;text-decoration:none" target="_blank">{{ ctaText }}</a> </td> </tr> diff --git a/packages/component-manuscript-manager/src/routes/fragments/notifications/emailCopy.js b/packages/component-manuscript-manager/src/routes/fragments/notifications/emailCopy.js index 6b7c64bcf95b2803bea159ba981f35817f150ea0..2f438381c22a6fbb03c602df9b76ec946790d916 100644 --- a/packages/component-manuscript-manager/src/routes/fragments/notifications/emailCopy.js +++ b/packages/component-manuscript-manager/src/routes/fragments/notifications/emailCopy.js @@ -1,5 +1,6 @@ const getEmailCopy = ({ emailType, titleText, expectedDate, customId }) => { let paragraph + const hasLink = true switch (emailType) { case 'he-new-version-submitted': paragraph = `A new version of ${titleText} has been submitted. @@ -14,11 +15,25 @@ const getEmailCopy = ({ emailType, titleText, expectedDate, customId }) => { case 'eqs-manuscript-submitted': paragraph = `Manuscript ID ${customId} has been submitted and a package has been sent. Please click on the link below to either approve or reject the manuscript:` break + case 'coauthors-manuscript-submitted': + paragraph = `${titleText} has been received.<br/> + Please verify your details by clicking the link below.<br/> + Once confirmed, you will also be able to view the status and progress of the manuscript.<br/> + Thank you for submitting your work to Hindawi. <br/> + ` + break + case 'submitting-author-manuscript-submitted': + paragraph = `Congratulations, ${titleText} has been successfully submitted.<br/> + All authors will receive correspondence regarding this manuscript, though only you will be able to make updates.<br/> + In order to view the status of the manuscript, please click the link below.<br/> + Thank you for submitting your work to Hindawi. <br/> + ` + break default: throw new Error(`The ${emailType} email type is not defined.`) } - return { paragraph, hasLink: true } + return { paragraph, hasLink } } module.exports = { 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 ee0f6f2918511fe268a35a1b9bca28c6e8d9e4c9..00e10fb91d49f7bf89b8374c019bced5139ed6ce 100644 --- a/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js @@ -8,6 +8,7 @@ const { Fragment, } = require('pubsweet-component-helper-service') +const resetPath = config.get('invite-reset-password.url') const { getEmailCopy } = require('./emailCopy') const unsubscribeSlug = config.get('unsubscribe.url') @@ -27,7 +28,10 @@ module.exports = { const parsedFragment = await fragmentHelper.getFragmentData({ handlingEditor: collection.handlingEditor, }) - const { submittingAuthor } = await fragmentHelper.getAuthorData({ + const { + submittingAuthor, + activeAuthors: authors, + } = await fragmentHelper.getAuthorData({ UserModel, }) @@ -80,6 +84,16 @@ module.exports = { collection, subjectBaseText, }) + sendAuthorsEmail({ + email, + baseUrl, + titleText, + UserModel, + subjectBaseText, + fragmentId: fragment.id, + fragmentAuthors: authors, + collectionId: collection.id, + }) } }, } @@ -191,3 +205,78 @@ const sendEQSEmail = ({ }) email.sendEmail({ html, text }) } + +const sendAuthorsEmail = async ({ + email, + baseUrl, + customId, + UserModel, + titleText, + fragmentId, + collectionId, + fragmentAuthors, +}) => { + email.content.subject = 'Manuscript Sumbmitted' + + const userEmailData = await Promise.all( + fragmentAuthors.map(async author => { + const user = await UserModel.find(author.id) + return { + ...author, + isConfirmed: user.isConfirmed, + ...getEmailCopy({ + customId, + emailType: author.isSubmitting + ? 'submitting-author-manuscript-submitted' + : 'coauthors-manuscript-submitted', + titleText: author.isSubmitting + ? titleText + : titleText.replace(/^\w/, firstChar => firstChar.toUpperCase()), + }), + } + }), + ) + + userEmailData.forEach(author => { + email.toUser = { + email: author.email, + name: `${author.firstName} ${author.lastName}`, + } + email.content.unsubscribeLink = services.createUrl( + baseUrl, + unsubscribeSlug, + { + id: author.id, + }, + ) + + if (author.isSubmitting) { + email.content.ctaLink = services.createUrl( + baseUrl, + `/projects/${collectionId}/versions/${fragmentId}/details`, + ) + email.content.ctaText = 'MANUSCRIPT DETAILS' + } else if (author.isConfirmed) { + email.content.ctaLink = services.createUrl(baseUrl, '') + email.content.ctaText = 'LOGIN' + } else { + email.content.ctaLink = services.createUrl(baseUrl, resetPath, { + email: author.email, + token: author.passwordResetToken, + firstName: author.firstName, + lastName: author.lastName, + affiliation: author.affiliation, + title: author.title, + }) + email.content.ctaText = 'CONFIRM ACCOUNT' + } + + const { html, text } = email.getBody({ + body: { + paragraph: author.paragraph, + hasLink: author.hasLink, + }, + }) + email.sendEmail({ html, text }) + }) +} 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 89cc1d71180c06f2fed6c78f2650a974ec8501ea..d130afb1506b1cabc01f24df626b066fdd726815 100644 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js @@ -58,17 +58,9 @@ module.exports = { }, }) - if (isEQA && agree) { - const eicName = await userHelper.getEiCName() - email.content.signatureName = eicName + if (agree && isEQA) { + email.content.signatureName = await userHelper.getEiCName() - sendAuthorsEmail({ - email, - baseUrl, - titleText, - subjectBaseText, - fragmentAuthors: authors, - }) sendHandlingEditorEmail({ email, baseUrl, @@ -84,6 +76,14 @@ module.exports = { fragmentHelper, subjectBaseText, }) + + sendAuthorsEmail({ + email, + baseUrl, + titleText, + subjectBaseText, + fragmentAuthors: authors, + }) } else { sendEditorsEmail({ email, agree, comments, userHelper, titleText }) } diff --git a/packages/component-user-manager/src/routes/fragmentsUsers/post.js b/packages/component-user-manager/src/routes/fragmentsUsers/post.js index f4f0608f01eeaf8b849b636963197cd2a80a4495..7337aace0f394ee7c83561c91afef9f92472afc2 100644 --- a/packages/component-user-manager/src/routes/fragmentsUsers/post.js +++ b/packages/component-user-manager/src/routes/fragmentsUsers/post.js @@ -1,5 +1,4 @@ const { pick } = require('lodash') -const notifications = require('./emails/notifications') const { User, @@ -47,7 +46,7 @@ module.exports = models => async (req, res) => { error: notFoundError.message, }) } - const baseUrl = services.getBaseUrl(req) + const UserModel = models.User const teamHelper = new Team({ TeamModel: models.Team, fragmentId }) const fragmentHelper = new Fragment({ fragment }) @@ -92,14 +91,9 @@ module.exports = models => async (req, res) => { collection.save() } - notifications.sendNotifications({ - user, - baseUrl, - fragment, - collection, - reqUserId: req.user, - UserModel: models.User, - }) + /* + TO DO: send email to SA when an Admin submits a manuscript on his behalf + */ return res.status(200).json({ ...pick(user, authorKeys), @@ -131,14 +125,9 @@ module.exports = models => async (req, res) => { isCorresponding, }) - notifications.sendNotifications({ - baseUrl, - fragment, - collection, - user: newUser, - reqUserId: req.user, - UserModel: models.User, - }) + /* + TO DO: send email to SA when an Admin submits a manuscript on his behalf + */ if (!collection.owners.includes(newUser.id)) { collection.owners.push(newUser.id)