From 3096d66d9617f4c679cf950db4f6ec630e3efd32 Mon Sep 17 00:00:00 2001
From: ahamelers <audrey@ahamelers.com>
Date: Tue, 5 Feb 2019 09:27:11 +0000
Subject: [PATCH] qa reject submission

---
 ...ReviewErrors.jsx => ReviewErrorReport.jsx} |  4 +-
 ...bmitMessages.jsx => SubmitErrorReport.jsx} | 95 ++++++++++++-------
 .../submission-wizard/SubmitErrors.jsx        | 85 -----------------
 .../submission-wizard/SubmitForm.jsx          | 67 ++++++++++---
 .../submission-wizard/SubmitPage.jsx          | 12 +--
 server/email/index.js                         | 11 +++
 .../xpub-model/entities/manuscript/index.js   | 32 ++++---
 7 files changed, 155 insertions(+), 151 deletions(-)
 rename app/components/submission-wizard/{ReviewErrors.jsx => ReviewErrorReport.jsx} (96%)
 rename app/components/submission-wizard/{SubmitMessages.jsx => SubmitErrorReport.jsx} (67%)
 delete mode 100644 app/components/submission-wizard/SubmitErrors.jsx

diff --git a/app/components/submission-wizard/ReviewErrors.jsx b/app/components/submission-wizard/ReviewErrorReport.jsx
similarity index 96%
rename from app/components/submission-wizard/ReviewErrors.jsx
rename to app/components/submission-wizard/ReviewErrorReport.jsx
index 2769044f2..684cca58b 100644
--- a/app/components/submission-wizard/ReviewErrors.jsx
+++ b/app/components/submission-wizard/ReviewErrorReport.jsx
@@ -5,7 +5,7 @@ import { TextArea, Button, H2, H3 } from '@pubsweet/ui'
 import { B, Buttons } from '../ui'
 import { REJECT_MANUSCRIPT } from './operations'
 
-const ReviewErrors = ({
+const ReviewErrorReport = ({
   close,
   history,
   onChange,
@@ -64,4 +64,4 @@ const ReviewErrors = ({
   </Mutation>
 )
 
-export default withRouter(ReviewErrors)
+export default withRouter(ReviewErrorReport)
diff --git a/app/components/submission-wizard/SubmitMessages.jsx b/app/components/submission-wizard/SubmitErrorReport.jsx
similarity index 67%
rename from app/components/submission-wizard/SubmitMessages.jsx
rename to app/components/submission-wizard/SubmitErrorReport.jsx
index 77a245081..b1f2b65de 100755
--- a/app/components/submission-wizard/SubmitMessages.jsx
+++ b/app/components/submission-wizard/SubmitErrorReport.jsx
@@ -1,9 +1,11 @@
 import React from 'react'
+import { withRouter } from 'react-router'
+import { Mutation } from 'react-apollo'
 import styled from 'styled-components'
 import { th, override } from '@pubsweet/ui-toolkit'
 import { Button, CheckboxGroup, TextField } from '@pubsweet/ui'
 import { Buttons, TextArea } from '../ui'
-// import { citeOptions, fileOptions, grantOptions } from './SubmitErrors'
+import { REJECT_MANUSCRIPT } from './operations'
 
 const Recipient = styled.fieldset`
   border: 0;
@@ -51,7 +53,8 @@ Please contact us at helpdesk@europepmc.org to confirm the manuscript title and
   },
   grants: {
     subject: 'linked grants mismatch',
-    message: '',
+    message:
+      'There is a problem with the grants linked to the manuscript. [DESCRIBE PROBLEM HERE]',
   },
   english: {
     subject: 'English is not the primary language',
@@ -65,7 +68,7 @@ const endErrs = ['title', 'english']
 const formatName = name =>
   `${name.title ? `${name.title} ` : ''}${name.givenNames} ${name.surname}`
 
-class SubmitMessages extends React.Component {
+class SubmitErrorReport extends React.Component {
   state = {
     subject: '',
     people: [],
@@ -110,10 +113,12 @@ class SubmitMessages extends React.Component {
 Thank you for your submission to Europe PMC plus.
 
 ${checkedBoxes
-  .map(
-    err => `${errors[err].message}
+  .map(err =>
+    errors[err]
+      ? `${errors[err].message}
 
-`,
+`
+      : '',
   )
   .join('')}${
       !checkedBoxes.some(err => endErrs.includes(err))
@@ -131,35 +136,59 @@ Europe PMC Helpdesk`
   }
   render() {
     const { subject, message, people, selected } = this.state
-    const { close } = this.props
+    const { close, history, manuscript } = this.props
     return (
-      <div>
-        <Recipient>
-          <label>Recipient(s)</label>
-          <CheckboxGroup
-            onChange={checked => this.setState({ selected: checked })}
-            options={people}
-            value={selected}
-          />
-        </Recipient>
-        <TextField
-          label="Subject"
-          onChange={e => this.setState({ subject: e.target.value })}
-          value={subject}
-        />
-        <TextArea
-          label="Message"
-          onChange={e => this.setState({ message: e.target.value })}
-          rows={15}
-          value={message}
-        />
-        <Buttons right>
-          <Button primary>Send & Reject</Button>
-          <Button onClick={close}>Cancel</Button>
-        </Buttons>
-      </div>
+      <Mutation mutation={REJECT_MANUSCRIPT}>
+        {(rejectManuscript, { data }) => {
+          const reject = async () => {
+            await rejectManuscript({
+              variables: {
+                data: {
+                  manuscriptId: manuscript.id,
+                  notesType: 'userMessage',
+                  content: JSON.stringify({
+                    to: selected.map(s => JSON.parse(s).id),
+                    subject,
+                    message,
+                  }),
+                },
+              },
+            })
+            history.push('/')
+          }
+          return (
+            <div>
+              <Recipient>
+                <label>Recipient(s)</label>
+                <CheckboxGroup
+                  onChange={checked => this.setState({ selected: checked })}
+                  options={people}
+                  value={selected}
+                />
+              </Recipient>
+              <TextField
+                label="Subject"
+                onChange={e => this.setState({ subject: e.target.value })}
+                value={subject}
+              />
+              <TextArea
+                label="Message"
+                onChange={e => this.setState({ message: e.target.value })}
+                rows={15}
+                value={message}
+              />
+              <Buttons right>
+                <Button onClick={reject} primary>
+                  Send & Reject
+                </Button>
+                <Button onClick={close}>Cancel</Button>
+              </Buttons>
+            </div>
+          )
+        }}
+      </Mutation>
     )
   }
 }
 
-export default SubmitMessages
+export default withRouter(SubmitErrorReport)
diff --git a/app/components/submission-wizard/SubmitErrors.jsx b/app/components/submission-wizard/SubmitErrors.jsx
deleted file mode 100644
index 99f780ef2..000000000
--- a/app/components/submission-wizard/SubmitErrors.jsx
+++ /dev/null
@@ -1,85 +0,0 @@
-import React from 'react'
-import { CheckboxGroup, H4 } from '@pubsweet/ui'
-
-export const citeOptions = [
-  {
-    value: 'title',
-    label: 'Manuscript title that matches submission',
-  },
-  {
-    value: 'citeOther',
-    label: 'Something else',
-  },
-]
-export const fileOptions = [
-  {
-    value: 'affiliations',
-    label: 'Complete title page with authors and affiliations',
-  },
-  {
-    value: 'figures',
-    label: 'All referenced figures, with captions',
-  },
-  {
-    value: 'tables',
-    label: 'All referenced tables, with captions',
-  },
-  {
-    value: 'supp',
-    label: 'All referenced supplementary material',
-  },
-  {
-    value: 'refs',
-    label: 'Complete reference list',
-  },
-  {
-    value: 'display',
-    label: 'Text and graphics displaying correctly',
-  },
-  {
-    value: 'english',
-    label: 'Content in English',
-  },
-  {
-    value: 'fileOther',
-    label: 'Something else',
-  },
-]
-export const grantOptions = [
-  {
-    value: 'grants',
-    label: 'Appropriate grant linking',
-  },
-  {
-    value: 'grantOther',
-    label: 'Something else',
-  },
-]
-
-const SubmitErrors = ({ onChange, value }) => (
-  <React.Fragment>
-    <H4>Citation</H4>
-    <CheckboxGroup
-      name="citation-checklist"
-      onChange={onChange}
-      options={citeOptions}
-      value={value}
-    />
-    <H4>Files</H4>
-    <CheckboxGroup
-      name="files-checklist"
-      onChange={onChange}
-      options={fileOptions}
-      value={value}
-    />
-    <H4>Funding</H4>
-    <CheckboxGroup
-      name="funding-checklist"
-      onChange={onChange}
-      options={grantOptions}
-      value={value}
-    />
-  </React.Fragment>
-)
-
-export default SubmitErrors
diff --git a/app/components/submission-wizard/SubmitForm.jsx b/app/components/submission-wizard/SubmitForm.jsx
index 828d48ed7..b73814cee 100755
--- a/app/components/submission-wizard/SubmitForm.jsx
+++ b/app/components/submission-wizard/SubmitForm.jsx
@@ -1,4 +1,5 @@
 import React from 'react'
+import { withRouter } from 'react-router'
 import { Mutation } from 'react-apollo'
 import styled from 'styled-components'
 import { Button, CheckboxGroup, H2, H3, Icon } from '@pubsweet/ui'
@@ -13,15 +14,57 @@ import {
   SectionHeader as Header,
 } from '../ui/'
 import { SUBMIT_MANUSCRIPT } from './operations'
-import ReviewErrors from './ReviewErrors'
-import SubmitMessages from './SubmitMessages'
-import SubmitErrors from './SubmitErrors'
+import ReviewErrorReport from './ReviewErrorReport'
+import SubmitErrorReport from './SubmitErrorReport'
 
 const Help = styled.p`
   font-style: italic;
   display: flex;
   align-items: center;
 `
+const adminOptions = [
+  {
+    value: 'title',
+    label: 'Manuscript title that matches submission',
+  },
+  {
+    value: 'affiliations',
+    label: 'Complete title page with authors and affiliations',
+  },
+  {
+    value: 'figures',
+    label: 'All referenced figures, with captions',
+  },
+  {
+    value: 'tables',
+    label: 'All referenced tables, with captions',
+  },
+  {
+    value: 'supp',
+    label: 'All referenced supplementary material',
+  },
+  {
+    value: 'refs',
+    label: 'Complete reference list',
+  },
+  {
+    value: 'display',
+    label: 'Text and graphics displaying correctly',
+  },
+  {
+    value: 'english',
+    label: 'Content in English',
+  },
+  {
+    value: 'grants',
+    label: 'Appropriate grant linking',
+  },
+  {
+    value: 'other',
+    label: 'Something else',
+  },
+]
+
 class SubmitForm extends React.Component {
   constructor(props) {
     super(props)
@@ -123,8 +166,10 @@ class SubmitForm extends React.Component {
                     <p>
                       Check the following and select anything that is missing:
                     </p>
-                    <SubmitErrors
+                    <CheckboxGroup
+                      name="admin-checklist"
                       onChange={onSubmissionCheck}
+                      options={adminOptions}
                       value={checkedBoxes}
                     />
                     <Buttons>
@@ -147,13 +192,13 @@ class SubmitForm extends React.Component {
                   </div>
                 </Content>
                 {reject && (
-                  <Portal>
+                  <Portal transparent>
                     <Close style={{ margin: 0 }}>
                       <CloseButton
                         onClick={() => this.setState({ reject: false })}
                       />
                     </Close>
-                    <SubmitMessages
+                    <SubmitErrorReport
                       checkedBoxes={checkedBoxes}
                       close={() => this.setState({ reject: false })}
                       manuscript={manuscript}
@@ -170,7 +215,7 @@ class SubmitForm extends React.Component {
               !['INITIAL', 'READY', 'submission-error'].includes(status)
             ) {
               return (
-                <Portal>
+                <Portal transparent>
                   <H2>Thank you for your submission</H2>
                   <p>{`Your submission is now ${
                     status === 'submitted' || status === 'in-review'
@@ -211,7 +256,7 @@ class SubmitForm extends React.Component {
           } else if (reviewer && reviewer.user.id === currentUser.id) {
             if (status && !['in-review', 'submission-error'].includes(status)) {
               return (
-                <Portal>
+                <Portal transparent>
                   <H2>Thank you for your submission</H2>
                   <p>
                     {`Your submission is being processed. You will receive email updates as your manuscript is processed. You can also log in to Europe PMC plus at any time to check the status of your submission.`}
@@ -269,13 +314,13 @@ class SubmitForm extends React.Component {
                   </div>
                 </Content>
                 {reject && (
-                  <Portal>
+                  <Portal transparent>
                     <Close style={{ margin: 0 }}>
                       <CloseButton
                         onClick={() => this.setState({ reject: false })}
                       />
                     </Close>
-                    <ReviewErrors
+                    <ReviewErrorReport
                       close={() => this.setState({ reject: false })}
                       manuscriptId={id}
                       message={message}
@@ -308,4 +353,4 @@ class SubmitForm extends React.Component {
   }
 }
 
-export default SubmitForm
+export default withRouter(SubmitForm)
diff --git a/app/components/submission-wizard/SubmitPage.jsx b/app/components/submission-wizard/SubmitPage.jsx
index 471a6a8a8..0b94287bb 100755
--- a/app/components/submission-wizard/SubmitPage.jsx
+++ b/app/components/submission-wizard/SubmitPage.jsx
@@ -1,4 +1,5 @@
 import React from 'react'
+import { withRouter } from 'react-router'
 import { Query } from 'react-apollo'
 import { omit } from 'lodash'
 import styled, { withTheme } from 'styled-components'
@@ -473,7 +474,6 @@ class Submit extends React.Component {
                 ))}
                 <SubmitForm
                   currentUser={currentUser}
-                  history={this.props.history}
                   manuscript={this.props.manuscript}
                   sections={sections}
                 />
@@ -504,15 +504,9 @@ const SubmitPage = ({ match, ...props }) => (
           </Loading>
         )
       }
-      return (
-        <SubmitWithHeader
-          manuscript={data.manuscript}
-          match={match}
-          {...props}
-        />
-      )
+      return <SubmitWithHeader manuscript={data.manuscript} {...props} />
     }}
   </Query>
 )
 
-export default SubmitPage
+export default withRouter(SubmitPage)
diff --git a/server/email/index.js b/server/email/index.js
index 93b2401bf..0dd73724b 100755
--- a/server/email/index.js
+++ b/server/email/index.js
@@ -20,6 +20,16 @@ const sendMail = (email, subject, messageInHtml) => {
   Email.send(mailData)
 }
 
+const userMessage = (email, subject, message) => {
+  const regex = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()[\]{};:'".,<>?«»“”‘’]))/i
+  const linkAdded = message.replace(
+    regex,
+    '<a href="$&" style="color:#20699C">$&</a>',
+  )
+  const messageDiv = `<div style="white-space:pre-wrap">${linkAdded}</div>`
+  sendMail(email, subject, messageDiv)
+}
+
 const reviewerEmail = ({ reviewer, manInfo, submitter, token }) => {
   const { title, givenNames, surname } = submitter
   const submitterName = `${title ? `${title} ` : ''}${givenNames} ${surname}`
@@ -59,6 +69,7 @@ const submitterRejectEmail = ({ reviewer, manInfo, submitter, message }) => {
 
 module.exports = {
   sendMail,
+  userMessage,
   reviewerEmail,
   submitterRejectEmail,
 }
diff --git a/server/xpub-model/entities/manuscript/index.js b/server/xpub-model/entities/manuscript/index.js
index d40272c67..6c9b6ceb8 100755
--- a/server/xpub-model/entities/manuscript/index.js
+++ b/server/xpub-model/entities/manuscript/index.js
@@ -13,7 +13,7 @@ const UserAccess = require('../user/data-access')
 const Team = require('../team/data-access')
 const { dManuscriptUpdate, gManuscript } = require('./helpers/transform')
 
-const { reviewerEmail, submitterRejectEmail } = rfr('server/email')
+const { userMessage, reviewerEmail, submitterRejectEmail } = rfr('server/email')
 
 const Manuscript = {
   selectActivityById: async id => {
@@ -324,12 +324,13 @@ const Manuscript = {
     const revTeam = teams.find(t => t.roleName === 'reviewer')
     const submitter = await UserAccess.findById(subTeam.userId)
     const reviewer = await UserAccess.findById(revTeam.userId)
+    const email = JSON.parse(input.content)
     const errors = []
     try {
       await NoteAccess.insert(input, userId)
       const manUpdate = {
         claimedBy: null,
-        formState: input.content,
+        formState: email.to ? email.html : input.content,
         status: 'submission-error',
         updatedBy: userId,
       }
@@ -343,15 +344,24 @@ const Manuscript = {
         errors,
       }
     }
-    await submitterRejectEmail({
-      reviewer,
-      manInfo: {
-        id: originalMan.id,
-        title: originalMan['meta,title'],
-      },
-      submitter,
-      message: input.content,
-    })
+    if (email.to) {
+      email.to.forEach(async e => {
+        const sendTo =
+          (submitter.id === e && submitter.identities[0].email) ||
+          (reviewer.id === e && reviewer.identities[0].email)
+        await userMessage(sendTo, email.subject, email.html)
+      })
+    } else {
+      await submitterRejectEmail({
+        reviewer,
+        manInfo: {
+          id: originalMan.id,
+          title: originalMan['meta,title'],
+        },
+        submitter,
+        message: input.content,
+      })
+    }
     const updatedMan = await ManuscriptAccess.selectById(originalMan.id, true)
     return {
       manuscript: gManuscript(updatedMan),
-- 
GitLab