diff --git a/packages/component-wizard/src/components/FileSection.js b/packages/component-wizard/src/components/FileSection.js index 45da7de03dcd4559dda18dc8cbd86a2125efcd79..245dcc5ffc7d7a7b7c9bae8a6dc20577e68fe129 100644 --- a/packages/component-wizard/src/components/FileSection.js +++ b/packages/component-wizard/src/components/FileSection.js @@ -114,12 +114,30 @@ export default compose( 'item', { drop( - { changeList, listId: toListId, maxFiles, files, setError }, + { + changeList, + listId: toListId, + maxFiles, + files, + setError, + allowedFileExtensions, + ...pm + }, monitor, ) { - const { listId: fromListId, id } = monitor.getItem() + const { listId: fromListId, id, name } = monitor.getItem() + const fileExtention = name.split('.')[1] + + if ( + allowedFileExtensions && + !allowedFileExtensions.includes(fileExtention) + ) { + setError('Invalid file type.') + return + } + if (files.length >= maxFiles) { - setError('No more files of this type can be added.') + setError('No more files can be added to this section.') return } @@ -148,7 +166,7 @@ export default compose( const fileExtention = file.name.split('.')[1] if (files.length >= maxFiles) { - setError('No more files of this type can be added.') + setError('No more files can be added to this section.') return } @@ -158,7 +176,7 @@ export default compose( ) { addFile(file) } else { - setError('File type not allowed for these kind of files.') + setError('Invalid file type.') } }, }, diff --git a/packages/component-wizard/src/components/WizardStep.js b/packages/component-wizard/src/components/WizardStep.js index 9f0a4b8c51bffcc518b3f4c9154ccfc86d0e7865..52b7609e4776cb2d1453fbeb0ad8d281f8bc39b6 100644 --- a/packages/component-wizard/src/components/WizardStep.js +++ b/packages/component-wizard/src/components/WizardStep.js @@ -66,7 +66,6 @@ export default ({ ) }, )} - <Files /> <div className={classnames(classes.buttons)}> <Button onClick={isFirst ? () => history.push('/') : prevStep}> {isFirst diff --git a/packages/xpub-faraday/app/config/journal/submit-wizard.js b/packages/xpub-faraday/app/config/journal/submit-wizard.js index 2fb9f0428a60e624f8159259cac738924a037557..261390aa2c296cd39170e2d5dadb2171331dc079 100644 --- a/packages/xpub-faraday/app/config/journal/submit-wizard.js +++ b/packages/xpub-faraday/app/config/journal/submit-wizard.js @@ -13,6 +13,7 @@ import { requiredBasedOnType, editModeEnabled, parseEmptyHtml, + requiredFiles, } from './wizard-validators' const min3Chars = minChars(3) @@ -174,37 +175,8 @@ export default { { fieldId: 'file-upload', renderComponent: Files, + validate: [requiredFiles], }, - // { - // fieldId: 'label-manuscript', - // renderComponent: Label, - // label: 'Main Manuscript', - // }, - // { - // fieldId: 'files.manuscripts', - // label: 'Main Manuscript', - // renderComponent: Supplementary, - // }, - // { - // fieldId: 'label-supplementary', - // renderComponent: Label, - // label: 'Supplemental Files', - // }, - // { - // fieldId: 'files.supplementary', - // label: 'Supplemental Files', - // renderComponent: Supplementary, - // }, - // { - // fieldId: 'label-cover', - // renderComponent: Label, - // label: 'Cover Letter', - // }, - // { - // fieldId: 'files.coverLetter', - // label: 'Cover Letter', - // renderComponent: Supplementary, - // }, ], }, ], diff --git a/packages/xpub-faraday/app/config/journal/wizard-validators.js b/packages/xpub-faraday/app/config/journal/wizard-validators.js index af5026c88f44bd1f8a2b21a91553fbd51742d7ce..7816aee812bfed54a505ccb95dfb240c3a7a0c14 100644 --- a/packages/xpub-faraday/app/config/journal/wizard-validators.js +++ b/packages/xpub-faraday/app/config/journal/wizard-validators.js @@ -29,3 +29,10 @@ export const editModeEnabled = value => { } return undefined } + +export const requiredFiles = (valus, formValues) => { + if (get(formValues, 'files.manuscripts').length === 0) { + return 'At least one main manuscript file is needed.' + } + return undefined +}