1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

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) { isFileValid(file) {
if (file.size > this.props.validation.sizeLimit) { let { validation, onValidationFailed } = this.props;
const fileSizeInMegaBytes = this.props.validation.sizeLimit / 1000000;
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); const notification = new GlobalNotificationModel(getLangText('A file you submitted is bigger than ' + fileSizeInMegaBytes + 'MB.'), 'danger', 5000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
if (typeof this.props.onValidationFailed === 'function') { if (typeof onValidationFailed === 'function') {
this.props.onValidationFailed(file); 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; return false;
} else { } else {
return true; return true;

View File

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