Skip to content
Snippets Groups Projects
Commit 523ee04a authored by Sebastian's avatar Sebastian
Browse files

feat(component-invite): send decline

parent 97450bac
No related branches found
No related tags found
1 merge request!6Agree/Decline to work on a manuscript
......@@ -46,12 +46,21 @@ module.exports = models => async (req, res) => {
await collection.save()
await teamHelper.removeTeamMember(team.id, user.id, models.Team)
user.teams = user.teams.filter(userTeamId => team.id !== userTeamId)
const fragment = await models.Fragment.find(collection.fragments[0])
let { title } = fragment.metadata
title = title.replace(/<(.|\n)*?>/g, '')
const submittingAuthorData = collection.authors.find(
author => author.isSubmitting === true,
)
const author = await models.User.find(submittingAuthorData.userId)
try {
await mailService.setupDeclineEmail(
await mailService.setupReviewerDeclineEmail(
toEmail,
user,
'decline',
collection.customId,
collection,
title,
`${author.firstName} ${author.lastName}`,
)
} catch (e) {
logger.error(e)
......
......@@ -76,13 +76,31 @@ module.exports = models => async (req, res) => {
invitation.reason = reason
}
try {
await mailService.setupDeclineEmail(
toEmail,
user,
'decline',
collection.customId,
reason,
)
if (invitation.role === 'handlingEditor') {
await mailService.setupDeclineEmail(
toEmail,
user,
'handling-editor-declined',
collection.customId,
reason,
)
} else if (invitation.role === 'reviewer') {
const fragment = await models.Fragment.find(collection.fragments[0])
let { title } = fragment.metadata
title = title.replace(/<(.|\n)*?>/g, '')
const submittingAuthorData = collection.authors.find(
author => author.isSubmitting === true,
)
const author = await models.User.find(submittingAuthorData.userId)
await mailService.setupReviewerDeclineEmail(
toEmail,
user,
collection,
title,
`${author.firstName} ${author.lastName}`,
)
}
} catch (e) {
logger.error(e)
return res.status(500).json({ error: 'Email could not be sent.' })
......
......@@ -198,6 +198,36 @@ module.exports = {
}
return Email.send(mailData)
},
setupReviewerDeclineEmail: async (
toEmail,
invitedUser,
collection,
title,
authorName,
) => {
const subject = `${collection.customId}: Review Unassigned`
const replacements = {
reviewerName: `${invitedUser.firstName} ${invitedUser.lastName}`,
title,
editorName: collection.handlingEditor.name,
authorName,
staffEmail: config.get('mailer.from'),
}
const { htmlBody, textBody } = getEmailBody(
'unassign-reviewer',
replacements,
)
const mailData = {
from: config.get('mailer.from'),
to: invitedUser.email,
subject,
text: textBody,
html: htmlBody,
}
return Email.send(mailData)
},
}
const getEmailBody = (emailType, replacements) => {
......
......@@ -164,7 +164,7 @@
<tr>
<td style="padding:30px 23px 0px 23px;background-color:#ffffff;" height="100%" valign="top" bgcolor="#ffffff">
<div>
<p data-pm-slice="1 1 []">Dear {{ reivewerName }},</p>
<p data-pm-slice="1 1 []">Dear {{ reviewerName }},</p>
<p>&nbsp;</p>
......@@ -176,6 +176,7 @@
<p>Best regards,
<br /> {{editorName}}
</p>
<p>&nbsp;</p>
</div>
</td>
......
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