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';
|
2020-08-21 11:59:58 +00:00
|
|
|
import { withTranslation } from 'react-i18next';
|
2020-03-03 21:33:52 +00:00
|
|
|
import prettyBytes from 'pretty-bytes';
|
2020-06-08 09:46:38 +00:00
|
|
|
import getConfig from '../../../utils/getConfig';
|
2019-08-12 15:21:42 +00:00
|
|
|
import FileUploader from './FileUploader';
|
|
|
|
import { getreachedTotalSizeLimit } from '../selectors/users';
|
2020-04-29 22:34:37 +00:00
|
|
|
import ExitIcon from '../../../images/exit.svg';
|
2019-09-10 22:42:23 +00:00
|
|
|
|
2020-06-08 09:46:38 +00:00
|
|
|
const limit = getConfig('UPLOAD_LIMIT') || 250000000;
|
2020-03-03 21:33:52 +00:00
|
|
|
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,
|
2020-08-21 11:59:58 +00:00
|
|
|
closeModal: PropTypes.func.isRequired,
|
|
|
|
t: PropTypes.func.isRequired
|
2019-09-10 22:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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">
|
2020-08-21 11:59:58 +00:00
|
|
|
<h2 className="modal__title">{this.props.t('UploadFileModal.Title')}</h2>
|
2020-05-05 23:03:58 +00:00
|
|
|
<button
|
|
|
|
className="modal__exit-button"
|
|
|
|
onClick={this.props.closeModal}
|
2020-08-21 11:59:58 +00:00
|
|
|
aria-label={this.props.t('UploadFileModal.CloseButtonARIA')}
|
2020-05-05 23:03:58 +00:00
|
|
|
>
|
|
|
|
<ExitIcon focusable="false" aria-hidden="true" />
|
2019-09-10 22:42:23 +00:00
|
|
|
</button>
|
2019-08-12 15:21:42 +00:00
|
|
|
</div>
|
2019-09-10 22:42:23 +00:00
|
|
|
{ this.props.reachedTotalSizeLimit &&
|
|
|
|
<p>
|
2020-08-21 11:59:58 +00:00
|
|
|
{this.props.t('UploadFileModal.SizeLimitError', { sizeLimit: limitText })}
|
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)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-21 11:59:58 +00:00
|
|
|
export default withTranslation()(connect(mapStateToProps)(UploadFileModal));
|