Skip to content
Snippets Groups Projects
Commit 2dd68e22 authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

Fix multiple requests on Author details form

parent 39a27902
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,12 @@ import {
} from 'recompose'
import { TextField, Menu, Icon, ValidatedField, Button } from '@pubsweet/ui'
import { addAuthor, getFragmentAuthors, setAuthors } from '../redux/authors'
import {
addAuthor,
getFragmentAuthors,
setAuthors,
moveAuthors,
} from '../redux/authors'
import classes from './AuthorList.local.scss'
import SortableList from './SortableList'
......@@ -246,6 +251,7 @@ export default compose(
{
addAuthor,
setAuthors,
moveAuthors,
updateFragment: actions.updateFragment,
},
),
......@@ -256,13 +262,15 @@ export default compose(
},
}),
withHandlers({
dropItem: ({ updateFragment, authors, project, version }) =>
debounce(() => {
updateFragment(project, {
...version,
authors,
})
}, 500),
dropItem: ({
updateFragment,
authors,
project,
version,
setAuthors,
}) => () => {
setAuthors(authors, version.id)
},
countryParser: () => countryCode =>
countries.find(c => c.value === countryCode).label,
parseAuthorType: () => (isSubmitting, isCorresponding) => {
......@@ -272,14 +280,14 @@ export default compose(
},
moveAuthor: ({
authors,
setAuthors,
moveAuthors,
project,
version,
updateFragment,
match: { params },
}) => (dragIndex, hoverIndex) => {
const newAuthors = SortableList.moveItem(authors, dragIndex, hoverIndex)
setAuthors(newAuthors, params.version)
moveAuthors(newAuthors, params.version)
},
removeAuthor: ({
authors,
......@@ -289,10 +297,7 @@ export default compose(
setAuthors,
}) => authorEmail => () => {
const newAuthors = authors.filter(a => a.email !== authorEmail)
updateFragment(project, {
...version,
authors: newAuthors,
}).then(() => setAuthors(newAuthors, version.id))
setAuthors(newAuthors, version.id)
},
setAsCorresponding: ({
authors,
......@@ -305,10 +310,7 @@ export default compose(
...a,
isCorresponding: a.isSubmitting || a.email === authorEmail,
}))
updateFragment(project, {
...version,
authors: newAuthors,
}).then(() => setAuthors(newAuthors, version.id))
setAuthors(newAuthors, version.id)
},
}),
)(Authors)
......@@ -18,6 +18,10 @@ export const setAuthors = (authors, fragmentId) => dispatch => {
dispatch(change('wizard', 'authors', authors))
}
export const moveAuthors = (authors, fragmentId) => dispatch => {
dispatch(_setAuthors(authors, fragmentId))
}
export const addAuthor = (author, collectionId, fragmentId) => dispatch =>
api
.create(`/fragments/${fragmentId}/authors`, author)
......
......@@ -15,7 +15,7 @@ import { declarations } from './'
import issueTypes from './issues-types'
import manuscriptTypes from './manuscript-types'
import { requiredBasedOnType, parseAbstract } from './wizard-validators'
import { requiredBasedOnType } from './wizard-validators'
const min3Chars = minChars(3)
const declarationsMinSize = minSize(declarations.options.length)
......@@ -51,7 +51,7 @@ export default {
steps: [
{
label: 'Journal details',
title: 'Journal & Field Selection',
title: '1. Journal & Field Selection',
children: [
{
fieldId: 'label-Journal',
......@@ -80,7 +80,7 @@ export default {
},
{
label: 'Pre-submission checklist',
title: 'Pre-submission Checklist',
title: '2. Pre-submission Checklist',
subtitle:
'Before moving forward make sure you have all the needed details prepared by reviewing and checking off the items on this list.',
children: [
......@@ -94,7 +94,7 @@ export default {
},
{
label: 'Manuscript & Authors Details',
title: 'Manuscript & Authors Details',
title: '3. Manuscript & Authors Details',
subtitle:
'Please provide the details of all the authors of this manuscript....',
children: [
......@@ -128,7 +128,7 @@ export default {
renderComponent: AbstractEditor,
title: 'Abstract',
placeholder: 'Write an abstract',
validate: [requiredBasedOnType, parseAbstract],
validate: [requiredBasedOnType],
},
{
fieldId: 'spacing-abstract',
......@@ -163,7 +163,7 @@ export default {
},
{
label: 'Files upload',
title: 'Manuscript Files Upload',
title: '4. Manuscript Files Upload',
children: [
{
fieldId: 'label-manuscript',
......
......@@ -6,19 +6,19 @@ const requiredTypes = manuscriptTypes
.filter(t => t.abstractRequired)
.map(t => t.value)
const parseAbstract = value => {
if (value && value.replace('<p></p>', '').replace('<h1></h1>', '')) {
return undefined
}
return 'Required'
}
export const requiredBasedOnType = (value, formValues) => {
if (
requiredTypes.includes(get(formValues, 'metadata.type')) &&
isEmpty(get(formValues, 'metadata.abstract'))
(isEmpty(get(formValues, 'metadata.abstract')) || parseAbstract(value))
) {
return 'Required'
}
return undefined
}
export const parseAbstract = value => {
if (value && value.replace('<p></p>', '').replace('<h1></h1>', '')) {
return undefined
}
return 'Required'
}
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