|
@ -1,6 +1,5 @@ |
|
|
import React from 'react'; |
|
|
import React from 'react'; |
|
|
import ReactDOM from 'react-dom'; |
|
|
import ReactDOM from 'react-dom'; |
|
|
|
|
|
|
|
|
import Store from '../../../store'; |
|
|
import Store from '../../../store'; |
|
|
import { translate } from '../../../translate/translate'; |
|
|
import { translate } from '../../../translate/translate'; |
|
|
import QrReader from 'react-qr-reader' |
|
|
import QrReader from 'react-qr-reader' |
|
@ -12,59 +11,55 @@ import { |
|
|
class QRModal extends React.Component { |
|
|
class QRModal extends React.Component { |
|
|
constructor(props) { |
|
|
constructor(props) { |
|
|
super(props); |
|
|
super(props); |
|
|
|
|
|
|
|
|
this.state = { |
|
|
this.state = { |
|
|
modalIsOpen: false, |
|
|
modalIsOpen: false, |
|
|
error: "" |
|
|
error: '' |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
this.openModal = this.openModal.bind(this); |
|
|
this.openModal = this.openModal.bind(this); |
|
|
this.closeModal = this.closeModal.bind(this); |
|
|
this.closeModal = this.closeModal.bind(this); |
|
|
|
|
|
|
|
|
this.handleScan = this.handleScan.bind(this); |
|
|
this.handleScan = this.handleScan.bind(this); |
|
|
this.handleError = this.handleError.bind(this); |
|
|
this.handleError = this.handleError.bind(this); |
|
|
|
|
|
|
|
|
document.body.addEventListener('click', this.closeModal); |
|
|
document.body.addEventListener('click', this.closeModal); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
handleScan(data) { |
|
|
handleScan(data) { |
|
|
if(data !== null) { |
|
|
if(data !== null) { |
|
|
if(this.props.mode==="scan") { |
|
|
if(this.props.mode === 'scan') { |
|
|
this.props.setRecieverFromScan(data) |
|
|
this.props.setRecieverFromScan(data) |
|
|
} |
|
|
} |
|
|
this.closeModal(); |
|
|
this.closeModal(); |
|
|
} |
|
|
} |
|
|
return data; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
handleError(err) { |
|
|
handleError(err) { |
|
|
this.setState({error: err}); |
|
|
this.setState({error: err}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
openModal() { |
|
|
openModal() { |
|
|
this.setState({modalIsOpen: true}); |
|
|
this.setState({modalIsOpen: true}); |
|
|
if(this.props.mode==="scan") { |
|
|
if(this.props.mode === 'scan') { |
|
|
ReactDOM.render(<QrReader |
|
|
ReactDOM.render( |
|
|
delay={500} |
|
|
<QrReader |
|
|
style={{ height: 281, width: 500, }} |
|
|
delay={50} |
|
|
|
|
|
style={{ height: 281, width: 500, transform: 'scaleX(-1)' }} |
|
|
onError={this.handleError} |
|
|
onError={this.handleError} |
|
|
onScan={this.handleScan} |
|
|
onScan={this.handleScan} />, document.getElementById('webcam')); |
|
|
/>, document.getElementById('webcam')); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
closeModal() { |
|
|
closeModal() { |
|
|
this.setState({modalIsOpen: false}); |
|
|
this.setState({modalIsOpen: false}); |
|
|
if(this.props.mode==="scan") { |
|
|
if(this.props.mode === 'scan') { |
|
|
ReactDOM.unmountComponentAtNode(document.getElementById('webcam')); |
|
|
ReactDOM.unmountComponentAtNode(document.getElementById('webcam')); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
if(this.props.mode==="scan") { |
|
|
if(this.props.mode === 'scan') { |
|
|
return QRModalReaderRender.call(this); |
|
|
return QRModalReaderRender.call(this); |
|
|
} else { |
|
|
} else { |
|
|
return QRModalRender.call(this); |
|
|
return QRModalRender.call(this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|