|
|
@ -9,6 +9,7 @@ export default class QrScanner extends Component { |
|
|
|
static propTypes = { |
|
|
|
static propTypes = { |
|
|
|
hideModal: PropTypes.func.isRequired, |
|
|
|
hideModal: PropTypes.func.isRequired, |
|
|
|
qrCodeDetected: PropTypes.func, |
|
|
|
qrCodeDetected: PropTypes.func, |
|
|
|
|
|
|
|
scanQrCode: PropTypes.func, |
|
|
|
error: PropTypes.bool, |
|
|
|
error: PropTypes.bool, |
|
|
|
errorType: PropTypes.string, |
|
|
|
errorType: PropTypes.string, |
|
|
|
} |
|
|
|
} |
|
|
@ -20,18 +21,9 @@ export default class QrScanner extends Component { |
|
|
|
constructor (props, context) { |
|
|
|
constructor (props, context) { |
|
|
|
super(props) |
|
|
|
super(props) |
|
|
|
|
|
|
|
|
|
|
|
let initialMsg = context.t('accessingYourCamera') |
|
|
|
|
|
|
|
if (props.error) { |
|
|
|
|
|
|
|
if (props.errorType === 'NO_WEBCAM_FOUND') { |
|
|
|
|
|
|
|
initialMsg = context.t('noWebcamFound') |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
initialMsg = context.t('unknownCameraError') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.state = { |
|
|
|
this.state = { |
|
|
|
ready: false, |
|
|
|
ready: false, |
|
|
|
msg: initialMsg, |
|
|
|
msg: context.t('accessingYourCamera'), |
|
|
|
} |
|
|
|
} |
|
|
|
this.codeReader = null |
|
|
|
this.codeReader = null |
|
|
|
this.permissionChecker = null |
|
|
|
this.permissionChecker = null |
|
|
@ -118,11 +110,22 @@ export default class QrScanner extends Component { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stopAndClose = () => { |
|
|
|
stopAndClose = () => { |
|
|
|
|
|
|
|
if (this.codeReader) { |
|
|
|
this.codeReader.reset() |
|
|
|
this.codeReader.reset() |
|
|
|
|
|
|
|
} |
|
|
|
this.setState({ ready: false }) |
|
|
|
this.setState({ ready: false }) |
|
|
|
this.props.hideModal() |
|
|
|
this.props.hideModal() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tryAgain = () => { |
|
|
|
|
|
|
|
// close the modal
|
|
|
|
|
|
|
|
this.stopAndClose() |
|
|
|
|
|
|
|
// wait for the animation and try again
|
|
|
|
|
|
|
|
setTimeout(_ => { |
|
|
|
|
|
|
|
this.props.scanQrCode() |
|
|
|
|
|
|
|
}, 1000) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
renderVideo () { |
|
|
|
renderVideo () { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className={'qr-scanner__content__video-wrapper'}> |
|
|
|
<div className={'qr-scanner__content__video-wrapper'}> |
|
|
@ -137,18 +140,61 @@ export default class QrScanner extends Component { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderErrorModal () { |
|
|
|
|
|
|
|
let title, msg |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.props.error) { |
|
|
|
|
|
|
|
if (this.props.errorType === 'NO_WEBCAM_FOUND') { |
|
|
|
|
|
|
|
title = this.context.t('noWebcamFoundTitle') |
|
|
|
|
|
|
|
msg = this.context.t('noWebcamFound') |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
title = this.context.t('unknownCameraErrorTitle') |
|
|
|
|
|
|
|
msg = this.context.t('unknownCameraError') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<div className="qr-scanner"> |
|
|
|
|
|
|
|
<div className="qr-scanner__close" onClick={this.stopAndClose}></div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div className="qr-scanner__image"> |
|
|
|
|
|
|
|
<img src={'images/webcam.svg'} width={70} height={70} /> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<div className="qr-scanner__title"> |
|
|
|
|
|
|
|
{ title } |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<div className={'qr-scanner__error'}> |
|
|
|
|
|
|
|
{msg} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<div className={'qr-scanner__footer'}> |
|
|
|
|
|
|
|
<button className="btn-default btn--large" onClick={this.stopAndClose}> |
|
|
|
|
|
|
|
CANCEL |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
<button className="btn-primary btn--large" onClick={this.tryAgain}> |
|
|
|
|
|
|
|
TRY AGAIN |
|
|
|
|
|
|
|
</button> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render () { |
|
|
|
render () { |
|
|
|
const { t } = this.context |
|
|
|
const { t } = this.context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.props.error) { |
|
|
|
|
|
|
|
return this.renderErrorModal() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="qr-scanner"> |
|
|
|
<div className="qr-scanner"> |
|
|
|
|
|
|
|
<div className="qr-scanner__close" onClick={this.stopAndClose}></div> |
|
|
|
<div className="qr-scanner__title"> |
|
|
|
<div className="qr-scanner__title"> |
|
|
|
{ `${t('scanQrCode')}` } |
|
|
|
{ `${t('scanQrCode')}` } |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className="qr-scanner__content"> |
|
|
|
<div className="qr-scanner__content"> |
|
|
|
{ !this.props.error ? this.renderVideo() : null} |
|
|
|
{ this.renderVideo() } |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className={`qr-scanner__status ${this.props.error ? 'error' : ''}`}> |
|
|
|
<div className={'qr-scanner__status'}> |
|
|
|
{this.state.msg} |
|
|
|
{this.state.msg} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|