Skip to content
Snippets Groups Projects
Commit daf22370 authored by Mihail Gorceag's avatar Mihail Gorceag
Browse files

fix: dont submit/evaluate article if required fields are not fulfilled

parent 08e6dcd5
No related branches found
No related tags found
No related merge requests found
...@@ -118,6 +118,7 @@ const composeValidate = ( ...@@ -118,6 +118,7 @@ const composeValidate = (
fieldName, fieldName,
doiValidation = false, doiValidation = false,
client, client,
componentType,
) => value => { ) => value => {
const validator = vld || [] const validator = vld || []
...@@ -126,10 +127,14 @@ const composeValidate = ( ...@@ -126,10 +127,14 @@ const composeValidate = (
validator validator
.map(v => v.value) .map(v => v.value)
.map(validatorFn => { .map(validatorFn => {
// if there is YSWYG component and it's empty - the value is a paragraph
const valueFormatted =
componentType === 'AbstractEditor' && value === '<p></p>' ? '' : value
const error = const error =
validatorFn === 'required' validatorFn === 'required'
? validators[validatorFn](value) ? validators[validatorFn](valueFormatted)
: validators[validatorFn](valueField[validatorFn])(value) : validators[validatorFn](valueField[validatorFn])(valueFormatted)
if (error) { if (error) {
errors.push(error) errors.push(error)
...@@ -138,7 +143,11 @@ const composeValidate = ( ...@@ -138,7 +143,11 @@ const composeValidate = (
return validatorFn return validatorFn
}) })
if (errors.length === 0 && fieldName === 'submission.articleURL' && doiValidation) { if (
errors.length === 0 &&
fieldName === 'submission.articleURL' &&
doiValidation
) {
return client return client
.query({ .query({
query: VALIDATE_DOI, query: VALIDATE_DOI,
...@@ -178,7 +187,7 @@ const FormTemplate = ({ ...@@ -178,7 +187,7 @@ const FormTemplate = ({
}) => { }) => {
const client = useApolloClient() const client = useApolloClient()
const submitButton = text => ( const submitButton = (text, haspopup = false) => (
<div> <div>
<Button <Button
onClick={async () => { onClick={async () => {
...@@ -189,7 +198,7 @@ const FormTemplate = ({ ...@@ -189,7 +198,7 @@ const FormTemplate = ({
if ( if (
hasErrors || hasErrors ||
values.status === articleStatuses.evaluated || values.status === articleStatuses.evaluated ||
values.status === articleStatuses.submitted (values.status === articleStatuses.submitted && !haspopup)
) { ) {
handleSubmit() handleSubmit()
} else { } else {
...@@ -204,6 +213,11 @@ const FormTemplate = ({ ...@@ -204,6 +213,11 @@ const FormTemplate = ({
</div> </div>
) )
const submitButtonText = match.url.includes('/evaluation')
? 'Submit Evaluation'
: 'Submit your research object'
const hasPopup = form.haspopup ? JSON.parse(form.haspopup) : false
return ( return (
<Container> <Container>
<Heading1>{form.name}</Heading1> <Heading1>{form.name}</Heading1>
...@@ -215,87 +229,92 @@ const FormTemplate = ({ ...@@ -215,87 +229,92 @@ const FormTemplate = ({
), ),
)} )}
/> />
<form onSubmit={handleSubmit}> <form>
{(form.children || []).map((element, i) => ( {(form.children || []).map((element, i) => {
<Section return (
cssOverrides={JSON.parse(element.sectioncss || '{}')} <Section
key={`${element.id}`} cssOverrides={JSON.parse(element.sectioncss || '{}')}
> key={`${element.id}`}
<Legend dangerouslySetInnerHTML={createMarkup(element.title)} /> >
{element.component === 'SupplementaryFiles' && ( <Legend dangerouslySetInnerHTML={createMarkup(element.title)} />
<FilesUpload {element.component === 'SupplementaryFiles' && (
containerId={manuscript.id} <FilesUpload
containerName="manuscript" containerId={manuscript.id}
fileType="supplementary" containerName="manuscript"
onChange={onChange} fileType="supplementary"
/> onChange={onChange}
)}
{element.component === 'VisualAbstract' && (
<FilesUpload
accept="image/*"
containerId={manuscript.id}
containerName="manuscript"
fileType="visualAbstract"
multiple={false}
onChange={onChange}
/>
)}
{element.component === 'AuthorsInput' && (
<AuthorsInput data-testid={element.name} onChange={onChange} />
)}
{element.component !== 'AuthorsInput' &&
element.component !== 'SupplementaryFiles' &&
element.component !== 'VisualAbstract' && (
<ValidatedFieldFormik
aria-label={element.placeholder || element.title}
component={elements[element.component]}
data-testid={element.name} // TODO: Improve this
key={`validate-${element.id}`}
name={element.name}
onChange={value => {
// TODO: Perhaps split components remove conditions here
let val
if (value.target) {
val = value.target.value
} else if (value.value) {
val = value.value
} else {
val = value
}
setFieldValue(element.name, val, true)
onChange(val, element.name)
}}
readonly={false}
setTouched={setTouched}
{...rejectProps(element, [
'component',
'title',
'sectioncss',
'parse',
'format',
'validate',
'validateValue',
'description',
'shortDescription',
'order',
])}
validate={composeValidate(
element.validate,
element.validateValue,
element.name,
JSON.parse(element.DoiValidation ? element.DoiValidation : false),
client,
)}
values={values}
/> />
)} )}
<SubNote {element.component === 'VisualAbstract' && (
dangerouslySetInnerHTML={createMarkup(element.description)} <FilesUpload
/> accept="image/*"
</Section> containerId={manuscript.id}
))} containerName="manuscript"
fileType="visualAbstract"
multiple={false}
onChange={onChange}
/>
)}
{element.component === 'AuthorsInput' && (
<AuthorsInput data-testid={element.name} onChange={onChange} />
)}
{element.component !== 'AuthorsInput' &&
element.component !== 'SupplementaryFiles' &&
element.component !== 'VisualAbstract' && (
<ValidatedFieldFormik
aria-label={element.placeholder || element.title}
component={elements[element.component]}
data-testid={element.name} // TODO: Improve this
key={`validate-${element.id}`}
name={element.name}
onChange={value => {
// TODO: Perhaps split components remove conditions here
let val
if (value.target) {
val = value.target.value
} else if (value.value) {
val = value.value
} else {
val = value
}
setFieldValue(element.name, val, true)
onChange(val, element.name)
}}
readonly={false}
setTouched={setTouched}
{...rejectProps(element, [
'component',
'title',
'sectioncss',
'parse',
'format',
'validate',
'validateValue',
'description',
'shortDescription',
'order',
])}
validate={composeValidate(
element.validate,
element.validateValue,
element.name,
JSON.parse(
element.DoiValidation ? element.DoiValidation : false,
),
client,
element.component,
)}
values={values}
/>
)}
<SubNote
dangerouslySetInnerHTML={createMarkup(element.description)}
/>
</Section>
)
})}
{filterFileManuscript(values.files || []).length > 0 ? ( {filterFileManuscript(values.files || []).length > 0 ? (
<Section id="files.manuscript"> <Section id="files.manuscript">
...@@ -308,42 +327,15 @@ const FormTemplate = ({ ...@@ -308,42 +327,15 @@ const FormTemplate = ({
</Section> </Section>
) : null} ) : null}
{process.env.INSTANCE_NAME === 'aperture' && ( {process.env.INSTANCE_NAME === 'aperture' &&
<> !['submitted', 'revise'].includes(values.status) &&
{!['submitted', 'revise'].includes(values.status) && submitButton(submitButtonText, hasPopup)}
form.haspopup === 'false' && (
<Button onClick={() => handleSubmit()} primary type="submit">
Submit your research object
</Button>
)}
{!['submitted', 'revise'].includes(values.status) && {['elife', 'ncrc'].includes(process.env.INSTANCE_NAME) &&
form.haspopup === 'true' && !['revise'].includes(values.status) &&
submitButton('Submit your research object')} submitButton(submitButtonText, hasPopup)}
</>
)}
{['elife', 'ncrc'].includes(process.env.INSTANCE_NAME) && (
<>
{!['revise'].includes(values.status) && form.haspopup === 'false' && (
<Button onClick={() => handleSubmit()} primary type="submit">
{match.url.includes('/evaluation')
? 'Submit Evaluation'
: 'Submit your research object'}
</Button>
)}
{!['revise'].includes(values.status) &&
form.haspopup === 'true' &&
submitButton(
match.url.includes('/evaluation')
? 'Submit Evaluation'
: 'Submit your research object',
)}
</>
)}
{values.status === 'revise' && submitButton('Submit your revision')} {values.status === 'revise' && submitButton(submitButtonText)}
{confirming && ( {confirming && (
<ModalWrapper> <ModalWrapper>
......
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