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'; ...@@ -6,6 +6,15 @@ import './Forms.css';
import ConfirmModal from '../forms/ConfirmModal'; import ConfirmModal from '../forms/ConfirmModal';
import { emptyMessage } from '../pages/Homework'; import { emptyMessage } from '../pages/Homework';
const allowedFileTypes = [
'image/jpeg',
'image/png',
'application/x-zip-compressed',
];
//in megabytes
const maxFileSize = 50;
class AddSolutionForm extends Component { class AddSolutionForm extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
...@@ -23,7 +32,7 @@ class AddSolutionForm extends Component { ...@@ -23,7 +32,7 @@ class AddSolutionForm extends Component {
const accepted = false; const accepted = false;
const sentences = this.props.taskdesc.split('\n'); const sentences = this.props.taskdesc.split('\n');
const note = ''; 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 ( return (
<Modal <Modal
open={this.state.showModal} open={this.state.showModal}
...@@ -65,7 +74,7 @@ class AddSolutionForm extends Component { ...@@ -65,7 +74,7 @@ class AddSolutionForm extends Component {
placeholder='Add meg a megoldás leírását...' placeholder='Add meg a megoldás leírását...'
/> />
<Form.Field> <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)} /> <Input type='file' onChange={e => this.props.writeSolutionFile(e)} />
</Form.Field> </Form.Field>
</Form> </Form>
...@@ -86,7 +95,16 @@ class AddSolutionForm extends Component { ...@@ -86,7 +95,16 @@ class AddSolutionForm extends Component {
? ?
<ConfirmModal <ConfirmModal
button={ 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 <Icon name='checkmark' /> Beadás
</Button> </Button>
} }
...@@ -95,6 +113,7 @@ class AddSolutionForm extends Component { ...@@ -95,6 +113,7 @@ class AddSolutionForm extends Component {
this.props.addSolution({ this.props.addSolution({
task, accepted, corrected, note, name, description, file, task, accepted, corrected, note, name, description, file,
}); });
console.log(file);
this.setState({ showModal: false }); this.setState({ showModal: false });
this.props.clearWrite(); this.props.clearWrite();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment