From fb89e76866b397fabf5a9f84f18c8e801fa69d7a Mon Sep 17 00:00:00 2001
From: Alexandru Munteanu <alexandru.munt@gmail.com>
Date: Mon, 23 Apr 2018 16:48:57 +0300
Subject: [PATCH] fix(manuscript-submission): add current user as submitting
 autohr

---
 .../component-wizard/src/redux/conversion.js  | 35 +++++++++----------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/packages/component-wizard/src/redux/conversion.js b/packages/component-wizard/src/redux/conversion.js
index a290931bb..becacf414 100644
--- a/packages/component-wizard/src/redux/conversion.js
+++ b/packages/component-wizard/src/redux/conversion.js
@@ -1,6 +1,7 @@
 import { pick } from 'lodash'
 import moment from 'moment'
 import { actions } from 'pubsweet-client'
+import { create } from 'pubsweet-client/src/helpers/api'
 
 /* constants */
 export const CREATE_DRAFT_REQUEST = 'CREATE_DRAFT_REQUEST'
@@ -23,27 +24,21 @@ const generateCustomId = () =>
     .toString()
     .slice(-7)
 
+const addSubmittingAuthor = (user, collectionId) => {
+  const author = {
+    ...pick(user, ['affiliation', 'email', 'firstName', 'lastName']),
+    isSubmitting: true,
+    isCorresponding: true,
+  }
+  create(`/collections/${collectionId}/users`, {
+    role: 'author',
+    ...author,
+  })
+}
+
 /* actions */
 export const createDraftSubmission = history => (dispatch, getState) => {
   const currentUser = getState().currentUser.user
-  let authors = []
-  if (!currentUser.admin) {
-    authors = [
-      {
-        ...pick(currentUser, [
-          'affiliation',
-          'email',
-          'firstName',
-          'lastName',
-          'middleName',
-          'country',
-        ]),
-        isSubmitting: true,
-        isCorresponding: true,
-      },
-    ]
-  }
-
   return dispatch(
     actions.createCollection({ customId: generateCustomId() }),
   ).then(({ collection }) => {
@@ -58,13 +53,15 @@ export const createDraftSubmission = history => (dispatch, getState) => {
         files: {
           supplementary: [],
         },
-        authors,
         fragmentType: 'version',
         metadata: {},
         version: 1,
       }),
     ).then(({ fragment }) => {
       const route = `/projects/${collection.id}/versions/${fragment.id}/submit`
+      if (!currentUser.admin) {
+        addSubmittingAuthor(currentUser, collection.id)
+      }
 
       // redirect after a short delay
       window.setTimeout(() => {
-- 
GitLab