diff --git a/packages/component-wizard/src/redux/conversion.js b/packages/component-wizard/src/redux/conversion.js index a290931bb5c244bf166523909cf1c2a1fa3cb228..becacf4146503472797087aa17aafebd4efdf257 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(() => {