From 2b473a67b09affb61e4a27b08315b994b9473933 Mon Sep 17 00:00:00 2001 From: Alexandru Munteanu <alexandru.munteanu@thinslices.com> Date: Wed, 21 Feb 2018 17:08:56 +0200 Subject: [PATCH] add author as submitting when creating new manuscript submission --- .../component-wizard/src/redux/conversion.js | 27 ++++++++++++++++--- .../src/components/AuthorList/AuthorList.js | 25 ++++++++++------- .../src/components/Dashboard/DashboardCard.js | 11 ++++---- packages/xpub-faraday/config/default.js | 2 +- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/packages/component-wizard/src/redux/conversion.js b/packages/component-wizard/src/redux/conversion.js index e922af529..6331ac689 100644 --- a/packages/component-wizard/src/redux/conversion.js +++ b/packages/component-wizard/src/redux/conversion.js @@ -1,3 +1,4 @@ +import { pick } from 'lodash' import { actions } from 'pubsweet-client' /* constants */ @@ -15,8 +16,27 @@ export const createDraftSuccess = draft => ({ }) /* actions */ -export const createDraftSubmission = history => dispatch => - dispatch(actions.createCollection()).then(({ collection }) => { +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()).then(({ collection }) => { if (!collection.id) { throw new Error('Failed to create a project') } @@ -28,6 +48,7 @@ export const createDraftSubmission = history => dispatch => files: { supplementary: [], }, + authors, fragmentType: 'version', metadata: {}, version: 1, @@ -41,7 +62,7 @@ export const createDraftSubmission = history => dispatch => }, 1000) }) }) - +} /* reducer */ const initialState = { diff --git a/packages/components-faraday/src/components/AuthorList/AuthorList.js b/packages/components-faraday/src/components/AuthorList/AuthorList.js index 9b00dd834..60c8b41a5 100644 --- a/packages/components-faraday/src/components/AuthorList/AuthorList.js +++ b/packages/components-faraday/src/components/AuthorList/AuthorList.js @@ -72,17 +72,16 @@ const Authors = ({ export default compose( withRouter, getContext({ version: PropTypes.object, project: PropTypes.object }), - connect(null, { - addAuthor, - changeForm, - }), - withState('authors', 'setAuthors', []), - lifecycle({ - componentDidMount() { - const { version, setAuthors } = this.props - setAuthors(version.authors) + connect( + state => ({ + currentUser: state.currentUser.user, + }), + { + addAuthor, + changeForm, }, - }), + ), + withState('authors', 'setAuthors', []), withState('editMode', 'setEditMode', false), withState('editedAuthor', 'setEditedAuthor', -1), withHandlers({ @@ -131,4 +130,10 @@ export default compose( setFormAuthors(newAuthors) }, }), + lifecycle({ + componentDidMount() { + const { version, setAuthors } = this.props + setAuthors(version.authors) + }, + }), )(Authors) diff --git a/packages/components-faraday/src/components/Dashboard/DashboardCard.js b/packages/components-faraday/src/components/Dashboard/DashboardCard.js index e0e31e49e..a3fcd76c5 100644 --- a/packages/components-faraday/src/components/Dashboard/DashboardCard.js +++ b/packages/components-faraday/src/components/Dashboard/DashboardCard.js @@ -22,7 +22,10 @@ const DashboardCard = ({ const hasFiles = !isEmpty(files) const abstract = get(version, 'metadata.abstract') const metadata = get(version, 'metadata') - return ( + const journalIssueType = journal.issueTypes.find( + t => t.value === get(metadata, 'issue'), + ) + return version ? ( <Card> <ListView> <Left> @@ -69,9 +72,7 @@ const DashboardCard = ({ <DetailsView> <LeftDetails> <JournalTitle>{journal.metadata.nameText}</JournalTitle> - <Issue> - {journal.issueTypes.find(t => t.value === metadata.issue).label} - </Issue> + {journalIssueType && <Issue>{journalIssueType.label}</Issue>} {get(version, 'authors') && ( <Authors> <span>Authors:</span> @@ -111,7 +112,7 @@ const DashboardCard = ({ </RightDetails> </DetailsView> </Card> - ) + ) : null } export default compose(getContext({ journal: PropTypes.object }))(DashboardCard) diff --git a/packages/xpub-faraday/config/default.js b/packages/xpub-faraday/config/default.js index c78cdecc4..fd1592d87 100644 --- a/packages/xpub-faraday/config/default.js +++ b/packages/xpub-faraday/config/default.js @@ -26,7 +26,7 @@ module.exports = { 'pubsweet-client': { API_ENDPOINT: '/api', 'login-redirect': '/', - 'redux-log': false, + 'redux-log': true, theme: process.env.PUBSWEET_THEME, }, 'mail-transport': { -- GitLab