-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_devicesCard.tsx
More file actions
40 lines (36 loc) · 1.41 KB
/
_devicesCard.tsx
File metadata and controls
40 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React, { useState } from 'react'
import DeviceRegistrationButton from './_deviceRegistrationButton'
import {DevicesList} from './_devicesList'
export function DevicesCard() {
const [deviceId, setDeviceId] = useState('')
const [error, setError] = useState<string | null>(null)
const [isLoading, setIsLoading] = useState(false)
function handleChange(event: any) {
setError('')
setDeviceId(event.target.value)
}
function handleError(error: string) {
console.log(error)
setError(error)
}
return(
<div className='card'>
<h5 className='card-title' >Devices</h5>
<form className='card-body row'>
<label htmlFor='findOrRegisterDevice_IdInput' className="form-label">
Find or register a device ID
</label>
<input type="text" id='findOrRegisterDevice_IdInput' name="register_deviceId" className="form-control col-md-10" onChange={ handleChange } />
<DeviceRegistrationButton deviceId={ deviceId } onError={ handleError } isLoading={ setIsLoading } />
<h5 className='mt-4'>Registered devices</h5>
{ isLoading &&
<div className="alert"><span>Loading...</span></div>
}
{ error &&
<div className="alert-danger">{ error }</div>
}
<DevicesList listFilter={ deviceId } isLoading={ setIsLoading } onError={ handleError } />
</form>
</div>
)
}