Cancel dragged invalid file with proper messaging

This commit is contained in:
Tim Daubenschütz 2016-01-21 13:53:14 +01:00
parent 4dd701a414
commit 80b4e22435
2 changed files with 18 additions and 4 deletions

View File

@ -518,16 +518,26 @@ const ReactS3FineUploader = React.createClass({
},
isFileValid(file) {
if (file.size > this.props.validation.sizeLimit) {
const fileSizeInMegaBytes = this.props.validation.sizeLimit / 1000000;
let { validation, onValidationFailed } = this.props;
if (file.size > validation.sizeLimit) {
const fileSizeInMegaBytes = validation.sizeLimit / 1000000;
const notification = new GlobalNotificationModel(getLangText('A file you submitted is bigger than ' + fileSizeInMegaBytes + 'MB.'), 'danger', 5000);
GlobalNotificationActions.appendGlobalNotification(notification);
if (typeof this.props.onValidationFailed === 'function') {
this.props.onValidationFailed(file);
if (typeof onValidationFailed === 'function') {
onValidationFailed(file);
}
return false;
} else if (validation.allowedExtensions.indexOf(file.type) === -1) {
const prettyAllowedExtensions = validation.allowedExtensions.join(', ');
const notification = new GlobalNotificationModel(getLangText(`The file you've submitted is of an invalid file format: Valid format(s): ${prettyAllowedExtensions}`), 'danger', 5000);
GlobalNotificationActions.appendGlobalNotification(notification);
return false;
} else {
return true;

View File

@ -7,6 +7,8 @@
position: fixed;
transition: .2s bottom cubic-bezier(.77, 0, .175, 1);
width: 100%;
z-index: 9999;
}
.ascribe-global-notification-off {
@ -37,6 +39,8 @@
right: -50em;
transition: 1s right ease;
z-index: 9999;
> div {
padding: .75em 1.5em;
}