From 6e977372d2370794fcdf8ec16e82f2e5f162172f Mon Sep 17 00:00:00 2001
From: Mihail Hagiu <mihail.hagiu@thinslices.com>
Date: Mon, 3 Dec 2018 15:54:58 +0200
Subject: [PATCH] feat(EiCEmail): Created email template for eic when author
 submits revision

---
 .../src/notifications/emailCopy.js            |  6 +++
 .../src/notifications/notification.js         | 42 +++++++++++++++++++
 .../strategies/eicRequestRevision.js          | 10 ++++-
 3 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/packages/component-manuscript-manager/src/notifications/emailCopy.js b/packages/component-manuscript-manager/src/notifications/emailCopy.js
index f55b47978..3819d77a5 100644
--- a/packages/component-manuscript-manager/src/notifications/emailCopy.js
+++ b/packages/component-manuscript-manager/src/notifications/emailCopy.js
@@ -144,6 +144,12 @@ const getEmailCopy = ({
       paragraph = `The authors of ${titleText} have submitted a revised version. <br/><br/>
         To review this new submission and proceed with the review process, please visit the manuscript details page.`
       break
+    case 'eic-revision-published':
+      hasIntro = false
+      hasSignature = false
+      paragraph = `The authors of ${titleText} have submitted a revised version. <br/><br/>
+        To review this new submission and proceed with the review process, please visit the manuscript details page.`
+      break
     default:
       throw new Error(`The ${emailType} email type is not defined.`)
   }
diff --git a/packages/component-manuscript-manager/src/notifications/notification.js b/packages/component-manuscript-manager/src/notifications/notification.js
index ff6c733a1..d80fb11f2 100644
--- a/packages/component-manuscript-manager/src/notifications/notification.js
+++ b/packages/component-manuscript-manager/src/notifications/notification.js
@@ -629,6 +629,48 @@ class Notification {
     })
   }
 
+  async notifyEditorInChiefWhenAuthorSubmitsRevision(newFragment) {
+    const { titleText } = await this._getNotificationProperties()
+
+    const userHelper = new User({ UserModel: this.UserModel })
+    const editors = await userHelper.getEditorsInChief()
+
+    const { paragraph, ...bodyProps } = getEmailCopy({
+      titleText,
+      emailType: 'eic-revision-published',
+    })
+
+    editors.forEach(eic => {
+      const email = new Email({
+        type: 'user',
+        fromEmail: `${journalName} <${staffEmail}>`,
+        toUser: {
+          email: eic.email,
+        },
+        content: {
+          subject: `${this.collection.customId}: Revision submitted`,
+          paragraph,
+          signatureName: '',
+          signatureJournal: journalName,
+          ctaLink: services.createUrl(
+            this.baseUrl,
+            `/projects/${this.collection.id}/versions/${
+              newFragment.id
+            }/details`,
+          ),
+          ctaText: 'MANUSCRIPT DETAILS',
+          unsubscribeLink: services.createUrl(this.baseUrl, unsubscribeSlug, {
+            id: eic.id,
+            token: eic.accessTokens.unsubscribe,
+          }),
+        },
+        bodyProps,
+      })
+
+      return email.sendEmail()
+    })
+  }
+
   async notifyReviewersWhenAuthorSubmitsMajorRevision(newFragmentId) {
     const { fragmentHelper } = await this._getNotificationProperties()
     const { collection, UserModel } = this
diff --git a/packages/component-manuscript-manager/src/routes/fragments/strategies/eicRequestRevision.js b/packages/component-manuscript-manager/src/routes/fragments/strategies/eicRequestRevision.js
index 671c507d1..7c89f6b93 100644
--- a/packages/component-manuscript-manager/src/routes/fragments/strategies/eicRequestRevision.js
+++ b/packages/component-manuscript-manager/src/routes/fragments/strategies/eicRequestRevision.js
@@ -1,7 +1,13 @@
 const { union } = require('lodash')
 
 module.exports = {
-  execute: async ({ models, TeamHelper, fragmentHelper, collectionHelper }) => {
+  execute: async ({
+    models,
+    TeamHelper,
+    fragmentHelper,
+    collectionHelper,
+    notification,
+  }) => {
     const eicRequestToRevision = fragmentHelper.getLatestEiCRequestToRevision()
     if (!eicRequestToRevision) {
       throw new Error('No Editor in Chief request to revision has been found.')
@@ -46,6 +52,8 @@ module.exports = {
 
     await collectionHelper.addFragment(newFragment.id)
 
+    await notification.notifyEditorInChiefWhenAuthorSubmitsRevision(newFragment)
+
     return newFragment
   },
 }
-- 
GitLab