Skip to content
Snippets Groups Projects
Commit fb89e768 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

fix(manuscript-submission): add current user as submitting autohr

parent 3e04c99b
No related branches found
No related tags found
1 merge request!6Agree/Decline to work on a manuscript
import { pick } from 'lodash' import { pick } from 'lodash'
import moment from 'moment' import moment from 'moment'
import { actions } from 'pubsweet-client' import { actions } from 'pubsweet-client'
import { create } from 'pubsweet-client/src/helpers/api'
/* constants */ /* constants */
export const CREATE_DRAFT_REQUEST = 'CREATE_DRAFT_REQUEST' export const CREATE_DRAFT_REQUEST = 'CREATE_DRAFT_REQUEST'
...@@ -23,27 +24,21 @@ const generateCustomId = () => ...@@ -23,27 +24,21 @@ const generateCustomId = () =>
.toString() .toString()
.slice(-7) .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 */ /* actions */
export const createDraftSubmission = history => (dispatch, getState) => { export const createDraftSubmission = history => (dispatch, getState) => {
const currentUser = getState().currentUser.user 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( return dispatch(
actions.createCollection({ customId: generateCustomId() }), actions.createCollection({ customId: generateCustomId() }),
).then(({ collection }) => { ).then(({ collection }) => {
...@@ -58,13 +53,15 @@ export const createDraftSubmission = history => (dispatch, getState) => { ...@@ -58,13 +53,15 @@ export const createDraftSubmission = history => (dispatch, getState) => {
files: { files: {
supplementary: [], supplementary: [],
}, },
authors,
fragmentType: 'version', fragmentType: 'version',
metadata: {}, metadata: {},
version: 1, version: 1,
}), }),
).then(({ fragment }) => { ).then(({ fragment }) => {
const route = `/projects/${collection.id}/versions/${fragment.id}/submit` const route = `/projects/${collection.id}/versions/${fragment.id}/submit`
if (!currentUser.admin) {
addSubmittingAuthor(currentUser, collection.id)
}
// redirect after a short delay // redirect after a short delay
window.setTimeout(() => { window.setTimeout(() => {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment