From de2d370d97e72bc123424e92ad72722739992ce1 Mon Sep 17 00:00:00 2001
From: Sebastian Mihalache <sebastian.mihalache@gmail.con>
Date: Wed, 1 Aug 2018 21:43:47 +0300
Subject: [PATCH] feat(component-manuscript-manager): build eqs email

---
 .../fragments/notifications/emailCopy.js      |  6 ++--
 .../fragments/notifications/notifications.js  | 28 +++++++++----------
 .../src/routes/fragments/post.js              | 16 +++++------
 packages/xpub-faraday/config/default.js       |  1 +
 4 files changed, 27 insertions(+), 24 deletions(-)

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 2c7c5302b..6b7c64bcf 100644
--- a/packages/component-manuscript-manager/src/routes/fragments/notifications/emailCopy.js
+++ b/packages/component-manuscript-manager/src/routes/fragments/notifications/emailCopy.js
@@ -1,4 +1,4 @@
-const getEmailCopy = ({ emailType, titleText, expectedDate }) => {
+const getEmailCopy = ({ emailType, titleText, expectedDate, customId }) => {
   let paragraph
   switch (emailType) {
     case 'he-new-version-submitted':
@@ -11,7 +11,9 @@ const getEmailCopy = ({ emailType, titleText, expectedDate }) => {
     case 'eic-manuscript-submitted':
       paragraph = `A new manuscript has been submitted. You can view ${titleText} and take further actions by clicking on the following link:`
       break
-
+    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
     default:
       throw new Error(`The ${emailType} email type is not defined.`)
   }
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 b6fa7b690..2d362b840 100644
--- a/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js
+++ b/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js
@@ -11,6 +11,7 @@ const {
 const { getEmailCopy } = require('./emailCopy')
 
 const unsubscribeSlug = config.get('unsubscribe.url')
+const editorialAssistantEmail = config.get('mailer.editorialAssistant')
 
 module.exports = {
   async sendNotifications({
@@ -19,7 +20,7 @@ module.exports = {
     UserModel,
     collection,
     isNewVersion = false,
-    isForEditorInChief,
+    isTechnicalCheck,
     isMajorRecommendation,
   }) {
     const fragmentHelper = new Fragment({ fragment })
@@ -72,13 +73,12 @@ module.exports = {
       })
     }
 
-    if (isForEditorInChief) {
-      sendEiCEmail({
+    if (isTechnicalCheck) {
+      sendEQSEmail({
         eic,
         email,
         baseUrl,
-        titleText,
-        fragmentHelper,
+        collection,
         subjectBaseText,
       })
     }
@@ -156,24 +156,24 @@ const sendReviewersEmail = async ({
   })
 }
 
-const sendEiCEmail = ({ eic, email, baseUrl, titleText, subjectBaseText }) => {
-  const emailType = 'eic-manuscript-submitted'
+const sendEQSEmail = ({ eic, email, baseUrl, collection, subjectBaseText }) => {
+  const emailType = 'eqs-manuscript-submitted'
 
   email.toUser = {
-    email: eic.email,
-    name: `${eic.firstName} ${eic.lastName}`,
+    email: editorialAssistantEmail,
+    name: 'Editorial Assistant',
   }
 
-  email.content.unsubscribeLink = services.createUrl(baseUrl, unsubscribeSlug, {
-    id: eic.id,
-  })
-  email.content.signatureName = 'Hindawi Submission System'
+  email.content.unsubscribeLink = baseUrl
+  email.content.signatureName = `${eic.firstName} ${eic.lastName}`
   email.content.subject = `${subjectBaseText} Submitted`
+  email.content.ctaLink = ''
+  email.content.ctaText = 'MAKE DECISION'
 
   const { html, text } = email.getBody({
     body: getEmailCopy({
       emailType,
-      titleText,
+      customId: collection.customId,
     }),
   })
   email.sendEmail({ html, text })
diff --git a/packages/component-manuscript-manager/src/routes/fragments/post.js b/packages/component-manuscript-manager/src/routes/fragments/post.js
index 08370831a..82a681eef 100644
--- a/packages/component-manuscript-manager/src/routes/fragments/post.js
+++ b/packages/component-manuscript-manager/src/routes/fragments/post.js
@@ -37,14 +37,6 @@ module.exports = models => async (req, res) => {
     fragment.submitted = Date.now()
     fragment = await fragment.save()
 
-    notifications.sendNotifications({
-      fragment,
-      collection,
-      UserModel: models.User,
-      isForEditorInChief: true,
-      baseUrl: services.getBaseUrl(req),
-    })
-
     collection.status = 'technicalChecks'
     collection.save()
 
@@ -60,6 +52,14 @@ module.exports = models => async (req, res) => {
 
     await MTS.sendPackage(packageFragment)
 
+    notifications.sendNotifications({
+      fragment,
+      collection,
+      UserModel: models.User,
+      isTechnicalCheck: true,
+      baseUrl: services.getBaseUrl(req),
+    })
+
     return res.status(200).json(fragment)
   } catch (e) {
     const notFoundError = await services.handleNotFoundError(e, 'Item')
diff --git a/packages/xpub-faraday/config/default.js b/packages/xpub-faraday/config/default.js
index d7958d81f..945cc96a6 100644
--- a/packages/xpub-faraday/config/default.js
+++ b/packages/xpub-faraday/config/default.js
@@ -109,6 +109,7 @@ module.exports = {
   mailer: {
     from: 'faraday@hindawi.com',
     path: `${__dirname}/mailer`,
+    editorialAssistant: 'hindawi@thinslices.com',
   },
   publicKeys: [
     'pubsweet-client',
-- 
GitLab