import React from 'react'; import {connect} from 'react-redux'; import Button from 'react-bootstrap/lib/Button.js'; import Dropzone from 'react-dropzone'; import i18n from 'nfvo-utils/i18n/i18n.js'; import ProgressBar from 'nfvo-components/progressBar/ProgressBar.jsx'; import Modal from 'nfvo-components/modal/Modal.jsx'; import UploadScreenActionHelper from './UploadScreenActionHelper.js'; import Attachments from './attachments/Attachments.js'; const mapStateToProps = ({uploadScreen}) => { let {upload} = uploadScreen; return {uploadScreen: upload}; }; const mapActionsToProps = dispatch => { return { onUpload: (formData) => UploadScreenActionHelper.uploadFile(dispatch, formData), openMainScreen: () => UploadScreenActionHelper.openMainScreen(dispatch) }; }; class UploadScreen extends React.Component { state = { complete: '10', showModal: false, fileName: '', dragging: false, files: [] }; interval = ''; render() { let {uploadScreen} = this.props; let {showAttachments} = uploadScreen; return(
{showAttachments ? this.renderTree() : this.renderUploadScreen()}
); } renderUploadModal() { let {complete, showModal, fileName} = this.state; return ( {i18n('Uploading attachments')}
{i18n('File:')} {fileName}
{i18n('Upload in progress')}
); } renderUploadScreen() { return(

HEAT VALIDATION APPLICATION

this.handleImportSubmit(files)} onDragEnter={() => this.setState({dragging:true})} onDragLeave={() => this.setState({dragging:false})} multiple={false} disableClick={true} ref='fileInput' name='fileInput' accept='.zip'>
{i18n('Drag & drop for upload')}
{i18n('or')}
this.refs.fileInput.open()}> {i18n('Select file')}
{this.renderUploadModal()}
); } renderTree() { let {openMainScreen} = this.props; return(
openMainScreen()}> {i18n('Back')}
); } handleImportSubmit(files) { this.setState({ showModal: true, fileName: files[0].name, dragging: false, complete: '0', files }); this.interval = setInterval(() => { if (this.state.complete >= 90) { clearInterval(this.interval); this.setState({ showModal: false, fileName: '' }); this.startUploading(files); } else { this.setState({ complete: (parseInt(this.state.complete) + 10).toString() }); } }, 20); } onRunBackground() { let {files} = this.state; clearInterval(this.interval); this.startUploading(files); this.setState({showModal: false, files: []}); } onCancel() { clearInterval(this.interval); this.setState({ showModal: false, fileName: '', files: [] }); } startUploading(files) { let {onUpload} = this.props; if (!(files && files.length)) { return; } let file = files[0]; let formData = new FormData(); formData.append('upload', file); this.refs.fileInput.value = ''; onUpload(formData); } } export default connect(mapStateToProps, mapActionsToProps)(UploadScreen);