Commit 8f8aea02 authored by Peter Hooper's avatar Peter Hooper
Browse files

Merge branch 'fix-upload-validation' into 'master'

fix: file upload form validation

See merge request !67
parents 2a8efb11 d976724b
......@@ -38,26 +38,32 @@ const FileUploadsPage = ({ history }) => (
}}
validationSchema={schema}
>
{({ setFieldValue, errors, touched, ...props }) => (
<FileUploads
conversion={{
converting: loading,
completed: !!uploadData,
error: uploadError,
}}
formError={errors.manuscriptUrl && touched.manuscriptUrl}
onDrop={([file]) =>
uploadFile({
variables: { file, id: initialValues.id },
}).then(({ data }) => {
setFieldValue('title', data.uploadManuscript.title)
setFieldValue('files', data.uploadManuscript.files)
})
}
setFieldValue={setFieldValue}
{...props}
/>
)}
{({ setFieldValue, errors, touched, values, ...props }) => {
const fieldName = 'files'
return (
<FileUploads
conversion={{
converting: loading,
// TODO import this constant from somewhere (data model package?)
completed: values[fieldName].includes(
file => file.type === 'MANUSCRIPT_SOURCE',
),
error: uploadError,
}}
formError={errors[fieldName] && touched[fieldName]}
onDrop={([file]) =>
uploadFile({
variables: { file, id: initialValues.id },
}).then(({ data }) => {
setFieldValue('title', data.uploadManuscript.title)
setFieldValue(fieldName, data.uploadManuscript.files)
})
}
setFieldValue={setFieldValue}
{...props}
/>
)
}}
</Formik>
)}
</Mutation>
......
......@@ -29,6 +29,10 @@ const manuscriptFragment = gql`
reason
}
noConflictOfInterest
files {
name
type
}
submissionMeta {
coverLetter
author {
......
......@@ -29,7 +29,17 @@ const CentredFlex = styled(Flex)`
align-items: center;
`
const DropzoneContent = ({ conversion, formError, dropzoneOpen, ...props }) => {
const DropzoneContent = ({ conversion, formError, dropzoneOpen }) => {
if (conversion.converting) {
return (
<div>
<Icon size={6}>Upload</Icon>
<Instruction data-test-id="dropzoneMessage">
Manuscript is uploading
</Instruction>
</div>
)
}
if (conversion.error) {
const errorMessage = get(
conversion,
......@@ -56,16 +66,6 @@ const DropzoneContent = ({ conversion, formError, dropzoneOpen, ...props }) => {
</div>
)
}
if (conversion.converting) {
return (
<div>
<Icon size={6}>Upload</Icon>
<Instruction data-test-id="dropzoneMessage">
Manuscript is uploading
</Instruction>
</div>
)
}
if (conversion.completed) {
return (
<div>
......
......@@ -57,3 +57,11 @@ it('displays uploading if conversion.converting is set', () => {
})
expect(dropzoneContentWrapper.text()).toBe(manuscriptUploading)
})
it('displays uploading even if there are errors', () => {
const dropzoneContentWrapper = makeCheerioWrapper({
conversion: { converting: true, error: new Error('Boo') },
formError: true,
})
expect(dropzoneContentWrapper.text()).toBe(manuscriptUploading)
})
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