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-03-03 22:33:52 +01:00
|
|
|
import prettyBytes from 'pretty-bytes';
|
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-03-03 22:33:52 +01:00
|
|
|
const __process = (typeof global !== 'undefined' ? global : window).process;
|
|
|
|
const limit = __process.env.UPLOAD_LIMIT || 250000000;
|
|
|
|
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,
|
|
|
|
closeModal: PropTypes.func.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
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">
|
|
|
|
<h2 className="modal__title">Upload File</h2>
|
2020-05-06 01:03:58 +02:00
|
|
|
<button
|
|
|
|
className="modal__exit-button"
|
|
|
|
onClick={this.props.closeModal}
|
|
|
|
aria-label="Close upload file modal"
|
|
|
|
>
|
|
|
|
<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-03-03 22:33:52 +01:00
|
|
|
`Error: You cannot upload any more files. You have reached the total size limit of ${limitText}.
|
2019-09-11 00:42:23 +02:00
|
|
|
If you would like to upload more, please remove the ones you aren't using anymore by
|
2019-09-26 21:06:43 +02:00
|
|
|
in your `
|
2019-09-11 00:42:23 +02:00
|
|
|
}
|
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)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(UploadFileModal);
|