Skip to content
Snippets Groups Projects
Commit 89cabd31 authored by Sebastian Mihalache's avatar Sebastian Mihalache
Browse files

refactor(email-helper): send email to existing authors

parent f76ebc0f
No related branches found
No related tags found
2 merge requests!34Sprint 17 features,!27Hin 832 send email to existing coauthor
const getEmailCopy = ({ emailType, titleText }) => {
let paragraph
switch (emailType) {
case 'co-author-added-to-manuscript':
paragraph = `You have been added as co-author to ${titleText}. The manuscript will become visible on your dashboard once it's submitted. Please click on the link below to access your dashboard.`
case 'author-added-to-manuscript':
paragraph = `You have been added as an author to ${titleText}. The manuscript will become visible on your dashboard once it's submitted. Please click on the link below to access your dashboard.`
break
case 'new-author-added-to-manuscript':
paragraph = `You have been added as an author to ${titleText}. In order to gain access to the manuscript, please confirm your account and set your account details by clicking on the link below.`
......
......@@ -9,17 +9,11 @@ const {
services,
Fragment,
} = require('pubsweet-component-helper-service')
const { getEmailCopy } = require('./emailCopy')
module.exports = {
async sendNotifications({
user,
baseUrl,
isSubmitting,
fragment,
UserModel,
collection,
}) {
async sendNotifications({ user, baseUrl, fragment, UserModel, collection }) {
const fragmentHelper = new Fragment({ fragment })
const { title } = await fragmentHelper.getFragmentData({
handlingEditor: collection.handlingEditor,
......@@ -44,21 +38,27 @@ module.exports = {
},
})
if (!isSubmitting) {
sendCoAuthorEmail({ email, baseUrl, user, titleText, subjectBaseText })
if (!user.isConfirmed) {
sendNewAuthorEmail({
email,
user,
baseUrl,
titleText,
subjectBaseText,
})
}
sendNewAuthorEmail({
sendAddedToManuscriptEmail({
email,
user,
baseUrl,
user,
titleText,
subjectBaseText,
})
},
}
const sendCoAuthorEmail = ({
const sendAddedToManuscriptEmail = ({
email,
baseUrl,
user,
......@@ -77,7 +77,7 @@ const sendCoAuthorEmail = ({
const { html, text } = email.getBody({
body: getEmailCopy({
emailType: 'co-author-added-to-manuscript',
emailType: 'author-added-to-manuscript',
titleText,
}),
})
......@@ -85,13 +85,7 @@ const sendCoAuthorEmail = ({
email.sendEmail({ html, text })
}
const sendNewAuthorEmail = ({
email,
baseUrl,
user,
titleText,
subjectBaseText,
}) => {
const sendNewAuthorEmail = ({ email, baseUrl, user, titleText }) => {
email.toUser = {
email: user.email,
name: `${user.firstName} ${user.lastName}`,
......
......@@ -98,7 +98,6 @@ module.exports = models => async (req, res) => {
fragment,
collection,
UserModel: models.User,
isSubmitting,
})
return res.status(200).json({
......@@ -137,7 +136,6 @@ module.exports = models => async (req, res) => {
collection,
user: newUser,
UserModel: models.User,
isSubmitting,
})
if (!collection.owners.includes(newUser.id)) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment