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

fix(authors): add default corresponding author delete

parent 2965b242
No related branches found
No related tags found
1 merge request!58Sprint #20 - Goal - Reviewers submit report
......@@ -21,6 +21,21 @@ const castToBool = author => ({
isCorresponding: isBoolean(author.isCorresponding) && author.isCorresponding,
})
const setCorrespondingAuthor = authors => {
const corresponding = authors.find(a => a.isCorresponding)
return corresponding
? authors
: authors.map(
a =>
a.isSubmitting
? {
...a,
isCorresponding: true,
}
: a,
)
}
const parseEditedAuthors = (editedAuthor, authors) => {
const newAuthor = castToBool(editedAuthor)
const newAuthors = authors.map(
......@@ -35,18 +50,7 @@ const parseEditedAuthors = (editedAuthor, authors) => {
},
)
const corresponding = newAuthors.find(a => a.isCorresponding)
return corresponding
? newAuthors
: newAuthors.map(
a =>
a.isSubmitting
? {
...a,
isCorresponding: true,
}
: a,
)
return setCorrespondingAuthor(newAuthors)
}
const WizardAuthors = ({
......@@ -168,7 +172,10 @@ export default compose(
}) => author => ({ hideModal, setModalError }) =>
deleteAuthor(project.id, version.id, author.id)
.then(() => {
setFormAuthors(authors.filter(a => a.id !== author.id))
const newAuthors = setCorrespondingAuthor(
authors.filter(a => a.id !== author.id),
)
setFormAuthors(newAuthors)
hideModal()
})
.catch(() => {
......
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