Skip to content
Snippets Groups Projects
Commit 135301ae authored by Bsandor453's avatar Bsandor453
Browse files

Add front-end validation for file type and size

parent 06edec63
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,15 @@ import './Forms.css';
import ConfirmModal from '../forms/ConfirmModal';
import { emptyMessage } from '../pages/Homework';
const allowedFileTypes = [
'image/jpeg',
'image/png',
'application/x-zip-compressed',
];
//in megabytes
const maxFileSize = 50;
class AddSolutionForm extends Component {
constructor(props) {
super(props);
......@@ -23,7 +32,7 @@ class AddSolutionForm extends Component {
const accepted = false;
const sentences = this.props.taskdesc.split('\n');
const note = '';
const disabledText = 'A határidő lejárt, további beadás nem lehetséges.'
const disabledText = 'A határidő lejárt, további beadás nem lehetséges.';
return (
<Modal
open={this.state.showModal}
......@@ -65,7 +74,7 @@ class AddSolutionForm extends Component {
placeholder='Add meg a megoldás leírását...'
/>
<Form.Field>
<label>Fájl:</label>
<label>Fájl (Megengedett fájltípusok: png, jpeg, jpg, zip. Maximum 50 MB.):</label>
<Input type='file' onChange={e => this.props.writeSolutionFile(e)} />
</Form.Field>
</Form>
......@@ -86,7 +95,16 @@ class AddSolutionForm extends Component {
?
<ConfirmModal
button={
<Button disabled={(name === '' || description === '')} inverted color='green'>
<Button
disabled={
name === '' ||
description === '' ||
!allowedFileTypes.includes(file.type) ||
file.size > (maxFileSize) * (1024 ** 2)
}
inverted
color='green'
>
<Icon name='checkmark' /> Beadás
</Button>
}
......@@ -95,6 +113,7 @@ class AddSolutionForm extends Component {
this.props.addSolution({
task, accepted, corrected, note, name, description, file,
});
console.log(file);
this.setState({ showModal: false });
this.props.clearWrite();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment