2019-08-12 17:21:42 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { Link } from 'react-router';
|
2020-08-21 13:59:58 +02:00
|
|
|
import { withTranslation } from 'react-i18next';
|
2020-03-03 22:33:52 +01:00
|
|
|
import prettyBytes from 'pretty-bytes';
|
2020-06-08 11:46:38 +02:00
|
|
|
import getConfig from '../../../utils/getConfig';
|
2019-08-12 17:21:42 +02:00
|
|
|
import FileUploader from './FileUploader';
|
|
|
|
import { getreachedTotalSizeLimit } from '../selectors/users';
|
2020-04-30 00:34:37 +02:00
|
|
|
import ExitIcon from '../../../images/exit.svg';
|
2019-09-11 00:42:23 +02:00
|
|
|
|
2020-06-08 11:46:38 +02:00
|
|
|
const limit = getConfig('UPLOAD_LIMIT') || 250000000;
|
2020-03-03 22:33:52 +01:00
|
|
|
const limitText = prettyBytes(limit);
|
|
|
|
|
2019-08-12 17:21:42 +02:00
|
|
|
class UploadFileModal extends React.Component {
|
|
|
|
propTypes = {
|
2019-09-11 00:42:23 +02:00
|
|
|
reachedTotalSizeLimit: PropTypes.bool.isRequired,
|
2020-08-21 13:59:58 +02:00
|
|
|
closeModal: PropTypes.func.isRequired,
|
|
|
|
t: PropTypes.func.isRequired
|
2019-09-11 00:42:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.focusOnModal();
|
2019-08-12 17:21:42 +02:00
|
|
|
}
|
|
|
|
|
2019-09-11 00:42:23 +02:00
|
|
|
focusOnModal = () => {
|
|
|
|
this.modal.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-12 17:21:42 +02:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<section className="modal" ref={(element) => { this.modal = element; }}>
|
2019-09-11 00:42:23 +02:00
|
|
|
<div className="modal-content">
|
|
|
|
<div className="modal__header">
|
2020-08-21 13:59:58 +02:00
|
|
|
<h2 className="modal__title">{this.props.t('UploadFileModal.Title')}</h2>
|
2020-05-06 01:03:58 +02:00
|
|
|
<button
|
|
|
|
className="modal__exit-button"
|
|
|
|
onClick={this.props.closeModal}
|
2020-08-21 13:59:58 +02:00
|
|
|
aria-label={this.props.t('UploadFileModal.CloseButtonARIA')}
|
2020-05-06 01:03:58 +02:00
|
|
|
>
|
|
|
|
<ExitIcon focusable="false" aria-hidden="true" />
|
2019-09-11 00:42:23 +02:00
|
|
|
</button>
|
2019-08-12 17:21:42 +02:00
|
|
|
</div>
|
2019-09-11 00:42:23 +02:00
|
|
|
{ this.props.reachedTotalSizeLimit &&
|
|
|
|
<p>
|
2020-08-21 13:59:58 +02:00
|
|
|
{this.props.t('UploadFileModal.SizeLimitError', { sizeLimit: limitText })}
|
2020-03-03 22:33:52 +01:00
|
|
|
<Link to="/assets" onClick={this.props.closeModal}>assets</Link>
|
|
|
|
.
|
2019-09-11 00:42:23 +02:00
|
|
|
</p>
|
|
|
|
}
|
|
|
|
{ !this.props.reachedTotalSizeLimit &&
|
|
|
|
<div>
|
|
|
|
<FileUploader />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
2019-08-12 17:21:42 +02:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
reachedTotalSizeLimit: getreachedTotalSizeLimit(state)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-21 13:59:58 +02:00
|
|
|
export default withTranslation()(connect(mapStateToProps)(UploadFileModal));
|