fix: show success message
This commit is contained in:
parent
ae7eaca10c
commit
b80b729388
2 changed files with 35 additions and 8 deletions
|
|
@ -6,7 +6,7 @@ import { Form, Formik, FastField } from 'formik'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import QRCode from 'qrcode.react'
|
import QRCode from 'qrcode.react'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import React, { memo, useState } from 'react'
|
import React, { memo, useState, useEffect, useRef } from 'react'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
|
|
||||||
import Title from 'src/components/Title'
|
import Title from 'src/components/Title'
|
||||||
|
|
@ -42,10 +42,26 @@ const useStyles = makeStyles(styles)
|
||||||
const getSize = R.compose(R.length, R.pathOr([], ['machines']))
|
const getSize = R.compose(R.length, R.pathOr([], ['machines']))
|
||||||
|
|
||||||
const QrCodeComponent = ({ classes, qrCode, name, count, onPaired }) => {
|
const QrCodeComponent = ({ classes, qrCode, name, count, onPaired }) => {
|
||||||
|
const timeout = useRef(null)
|
||||||
|
const CLOSE_SCREEN_TIMEOUT = 2000
|
||||||
const { data } = useQuery(GET_MACHINES, { pollInterval: 10000 })
|
const { data } = useQuery(GET_MACHINES, { pollInterval: 10000 })
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (timeout.current) {
|
||||||
|
clearTimeout(timeout.current)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
const addedMachine = data?.machines?.find(m => m.name === name)
|
const addedMachine = data?.machines?.find(m => m.name === name)
|
||||||
if (getSize(data) > count && addedMachine) onPaired(addedMachine)
|
const hasNewMachine = getSize(data) > count && addedMachine
|
||||||
|
if (hasNewMachine) {
|
||||||
|
timeout.current = setTimeout(
|
||||||
|
() => onPaired(addedMachine),
|
||||||
|
CLOSE_SCREEN_TIMEOUT
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -61,12 +77,19 @@ const QrCodeComponent = ({ classes, qrCode, name, count, onPaired }) => {
|
||||||
<div className={classes.qrTextIcon}>
|
<div className={classes.qrTextIcon}>
|
||||||
<WarningIcon />
|
<WarningIcon />
|
||||||
</div>
|
</div>
|
||||||
<P className={classes.qrText}>
|
<div className={classes.textWrapper}>
|
||||||
To pair the machine you need scan the QR code with your machine.
|
<P className={classes.qrText}>
|
||||||
To do this either snap a picture of this QR code or download it
|
To pair the machine you need scan the QR code with your machine.
|
||||||
through the button above and scan it with the scanning bay on your
|
To do this either snap a picture of this QR code or download it
|
||||||
machine.
|
through the button above and scan it with the scanning bay on
|
||||||
</P>
|
your machine.
|
||||||
|
</P>
|
||||||
|
{hasNewMachine && (
|
||||||
|
<P className={classes.qrText}>
|
||||||
|
✔ Machine has been successfully paired!
|
||||||
|
</P>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,10 @@ const styles = {
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
alignItems: 'center'
|
alignItems: 'center'
|
||||||
},
|
},
|
||||||
|
textWrapper: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column'
|
||||||
|
},
|
||||||
qrTextIcon: {
|
qrTextIcon: {
|
||||||
marginRight: 16
|
marginRight: 16
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue