Commit 91e53dd1 authored by Yannis Barlas's avatar Yannis Barlas

fix(submission form): prevent empty coauthor from being written to db

parent 02072f71
......@@ -4,6 +4,7 @@ import _, {
cloneDeep,
// cloneDeepWith,
find,
isEmpty,
// merge,
mergeWith,
keys,
......@@ -458,14 +459,26 @@ const formValuesToData = values => {
author.submittingAuthor = true
data.authors.push(author)
data.authors = data.authors.map(item => {
const modAuthor = cloneDeep(item)
delete modAuthor.id
delete modAuthor.__typename
if (!modAuthor.submittingAuthor) modAuthor.submittingAuthor = null
if (!modAuthor.email) modAuthor.email = null
return modAuthor
})
data.authors = data.authors
.map(item => {
const modAuthor = cloneDeep(item)
delete modAuthor.id
delete modAuthor.__typename
if (!modAuthor.submittingAuthor) modAuthor.submittingAuthor = null
if (!modAuthor.email) modAuthor.email = null
return modAuthor
})
.filter(item => {
if (
isEmpty(item.name) &&
isEmpty(item.credit) &&
isEmpty(item.affiliations)
) {
return false
}
return true
})
}
if (status) {
......
......@@ -93,17 +93,7 @@ const initial = {
'Name is required for all authors',
// eslint-disable-next-line func-names, prefer-arrow-callback
function(val) {
if (val) return true
const { affiliations, credit } = this.parent
if (
(!affiliations || affiliations.length === 0) &&
isCreditEmpty(credit)
) {
return true
}
if (val && val.length > 0) return true
return false
},
),
......
......@@ -247,7 +247,7 @@ const validate = (manuscript, imageSrc) => {
const ajv = new Ajv()
const valid = ajv.validate(schema, manuscript)
// if (!valid) logger.error(`${errorText} ${ajv.errorsText()}`)
if (!valid) logger.error(`${errorText} ${ajv.errorsText()}`)
return valid
}
......
Markdown is supported
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