2019-08-12 15:21:42 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { Link } from 'react-router';
|
2019-09-10 22:42:23 +00:00
|
|
|
import InlineSVG from 'react-inlinesvg';
|
2020-03-03 21:33:52 +00:00
|
|
|
import prettyBytes from 'pretty-bytes';
|
2019-08-12 15:21:42 +00:00
|
|
|
import FileUploader from './FileUploader';
|
|
|
|
import { getreachedTotalSizeLimit } from '../selectors/users';
|
2019-09-10 22:42:23 +00:00
|
|
|
import exitUrl from '../../../images/exit.svg';
|
|
|
|
|
2020-03-03 21:33:52 +00:00
|
|
|
const __process = (typeof global !== 'undefined' ? global : window).process;
|
|
|
|
const limit = __process.env.UPLOAD_LIMIT || 250000000;
|
|
|
|
const limitText = prettyBytes(limit);
|
|
|
|
|
2019-08-12 15:21:42 +00:00
|
|
|
class UploadFileModal extends React.Component {
|
|
|
|
propTypes = {
|
2019-09-10 22:42:23 +00:00
|
|
|
reachedTotalSizeLimit: PropTypes.bool.isRequired,
|
|
|
|
closeModal: PropTypes.func.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.focusOnModal();
|
2019-08-12 15:21:42 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 22:42:23 +00:00
|
|
|
focusOnModal = () => {
|
|
|
|
this.modal.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-12 15:21:42 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<section className="modal" ref={(element) => { this.modal = element; }}>
|
2019-09-10 22:42:23 +00:00
|
|
|
<div className="modal-content">
|
|
|
|
<div className="modal__header">
|
|
|
|
<h2 className="modal__title">Upload File</h2>
|
|
|
|
<button className="modal__exit-button" onClick={this.props.closeModal}>
|
|
|
|
<InlineSVG src={exitUrl} alt="Close New File Modal" />
|
|
|
|
</button>
|
2019-08-12 15:21:42 +00:00
|
|
|
</div>
|
2019-09-10 22:42:23 +00:00
|
|
|
{ this.props.reachedTotalSizeLimit &&
|
|
|
|
<p>
|
|
|
|
{
|
2020-03-03 21:33:52 +00:00
|
|
|
`Error: You cannot upload any more files. You have reached the total size limit of ${limitText}.
|
2019-09-10 22:42:23 +00:00
|
|
|
If you would like to upload more, please remove the ones you aren't using anymore by
|
2019-09-26 19:06:43 +00:00
|
|
|
in your `
|
2019-09-10 22:42:23 +00:00
|
|
|
}
|
2020-03-03 21:33:52 +00:00
|
|
|
<Link to="/assets" onClick={this.props.closeModal}>assets</Link>
|
|
|
|
.
|
2019-09-10 22:42:23 +00:00
|
|
|
</p>
|
|
|
|
}
|
|
|
|
{ !this.props.reachedTotalSizeLimit &&
|
|
|
|
<div>
|
|
|
|
<FileUploader />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
2019-08-12 15:21:42 +00:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
reachedTotalSizeLimit: getreachedTotalSizeLimit(state)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(UploadFileModal);
|