Commit b3710015 authored by Yannis Barlas's avatar Yannis Barlas

feat(submission form): add no datatype option

parent 14d62cbb
......@@ -26,6 +26,10 @@ const options = {
label: 'Gene expression results',
value: 'geneExpression',
},
{
label: 'No Datatype',
value: 'noDatatype',
},
],
}
......
......@@ -17,14 +17,20 @@ const SubmissionForm = props => {
const handleSubmit = (formValues, formikBag) => {
const submit = () => {
const data = cloneDeep(formValues)
data.status = updateSubmissionStatus(data.status)
data.status = updateSubmissionStatus(data.status, data.dataType)
const manuscriptInput = formValuesToData(data)
update({ variables: { data: manuscriptInput } })
formikBag.resetForm(formValues)
const { datatypeSelected, full } = data.status.submission
if (!(datatypeSelected && !full)) showModal()
if (
!(datatypeSelected && !full) &&
!(full && data.dataType === 'noDatatype')
) {
showModal()
}
}
if (get(formValues, 'image.url') === get(article, 'image.url')) {
......
......@@ -196,6 +196,12 @@ const setDatatypeSelected = status => {
return status
}
const setDatatypeSelectedAndFullSubmissionReady = status => {
set(status, 'submission.datatypeSelected', true)
set(status, 'submission.full', true)
return status
}
const setFullSubmissionReady = status => {
set(status, 'submission.full', true)
return status
......@@ -203,7 +209,7 @@ const setFullSubmissionReady = status => {
// Sets submission status to its next logical state
// initial -> datatype selected -> full
const updateSubmissionStatus = status => {
const updateSubmissionStatus = (status, newDatatype) => {
if (!status)
throw new Error('Cannot update submission status without a status object')
......@@ -215,7 +221,12 @@ const updateSubmissionStatus = status => {
const full = isFullSubmissionReady(newStatus)
if (!initial) return setInitialSubmissionReady(newStatus)
if (initial && !datatype) return setDatatypeSelected(newStatus)
if (initial && !datatype) {
if (newDatatype === 'noDatatype') {
return setDatatypeSelectedAndFullSubmissionReady(status)
}
return setDatatypeSelected(newStatus)
}
if (datatype && !full) return setFullSubmissionReady(newStatus)
throw new Error(
......
const config = require('config')
const cheerio = require('cheerio')
const without = require('lodash/without')
const mailer = require('@pubsweet/component-send-email')
const User = require('pubsweet-server/src/models/User')
......@@ -101,12 +102,12 @@ const getEditorIds = async () => {
const getEditorEmails = async () => {
const editorIds = await getEditorIds()
return getEmailsByUserIds(editorIds)
}
const editors = await Promise.all(
editorIds.map(async memberId => User.find(memberId)),
)
const emails = editors.map(ed => ed.email).join(',')
const getEmailsByUserIds = async userIds => {
const users = await Promise.all(userIds.map(async id => User.find(id)))
const emails = users.map(user => user.email).join(',')
return emails
}
......@@ -325,6 +326,20 @@ const currentlyWith = async context => {
const dataTypeSelected = async context => {
const authorEmails = await getAuthorEmails(context)
const manuscript = await getManuscript(context)
const noDatatype = manuscript.dataType === 'noDatatype'
const nextStepText = noDatatype
? `
<p>
Your article is now with the editorial team for review.
</p>
`
: `
<p>
You can now complete your full submission! Scroll down to the bottom
of the submission and fill out the relevant fields.
</p>
`
const content = `
<p>
......@@ -332,10 +347,7 @@ const dataTypeSelected = async context => {
"${formatManuscriptTitle(manuscript.title)}"
the "${toRegularText(manuscript.dataType)}" data type.
</p>
<p>
You can now complete your full submission! Scroll down to the bottom of
the submission and fill out the relevant fields.
</p>
${nextStepText}
${getArticleLink(manuscript.id)}
`
......@@ -353,15 +365,35 @@ const dataTypeSelected = async context => {
*/
const fullSubmission = async context => {
const editorEmails = await getEditorEmails()
const manuscript = await getManuscript(context)
const currentUser = await getCurrentUser(context)
/*
There is one case (when 'no datatype' datatype is chosen) where the editor
triggers the full submission, not the author. In this scenario, send the
email to all other editors.
*/
let editorIds = await getEditorIds()
const isCurrentUserEditor = editorIds.includes(currentUser.id)
if (isCurrentUserEditor) editorIds = without(editorIds, currentUser.id)
const editorEmails = await getEmailsByUserIds(editorIds)
const message = isCurrentUserEditor
? `
<p>
Article "${formatManuscriptTitle(manuscript.title)}" has been fully
submitted and is now ready for review.
</p>
`
: `
<p>
User ${currentUser.username} just finished the full submission for
article "${formatManuscriptTitle(manuscript.title)}".
</p>
`
const content = `
<p>
User ${currentUser.username} just finished the full submission for
article "${formatManuscriptTitle(manuscript.title)}".
</p>
${message}
${getArticleLink(manuscript.id)}
`
......
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