chore(frontend): show loading at set parameter value request

This commit is contained in:
leandrofars 2023-10-23 10:05:11 -03:00
parent 8d1c2c3647
commit a6b6cc4779

View File

@ -14,7 +14,8 @@ import {
DialogContentText, DialogContentText,
DialogTitle, DialogTitle,
TextField, TextField,
Button Button,
Backdrop,
} from '@mui/material'; } from '@mui/material';
import CircularProgress from '@mui/material/CircularProgress'; import CircularProgress from '@mui/material/CircularProgress';
import PlusCircleIcon from '@heroicons/react/24/outline/PlusCircleIcon'; import PlusCircleIcon from '@heroicons/react/24/outline/PlusCircleIcon';
@ -176,6 +177,7 @@ const [deviceParametersValue, setDeviceParametersValue] = useState({})
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const [errorModal, setErrorModal] = useState(false) const [errorModal, setErrorModal] = useState(false)
const [errorModalText, setErrorModalText] = useState("") const [errorModalText, setErrorModalText] = useState("")
const [showLoading, setShowLoading] = useState(false)
const initialize = async (raw) => { const initialize = async (raw) => {
let content = await getDeviceParameters(raw) let content = await getDeviceParameters(raw)
@ -686,16 +688,19 @@ const getDeviceParameterInstances = async (raw) =>{
console.log(requestOptions.body) console.log(requestOptions.body)
setOpen(false)
setShowLoading(true)
let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/set`, requestOptions)) let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/set`, requestOptions))
if (result.status != 200) { if (result.status != 200) {
setShowLoading(false)
throw new Error('Please check your email and password'); throw new Error('Please check your email and password');
}else{ }else{
setShowLoading(false)
let response = await result.json() let response = await result.json()
let feedback = JSON.stringify(response, null, 2) let feedback = JSON.stringify(response, null, 2)
if (response.updated_obj_results[0].oper_status.OperStatus["OperSuccess"] === undefined) { if (response.updated_obj_results[0].oper_status.OperStatus["OperSuccess"] === undefined) {
console.log("Error to set parameter change") console.log("Error to set parameter change")
setOpen(false)
setErrorModalText(feedback) setErrorModalText(feedback)
setErrorModal(true) setErrorModal(true)
return return
@ -768,6 +773,16 @@ const getDeviceParameterInstances = async (raw) =>{
}}>OK</Button> }}>OK</Button>
</DialogActions> </DialogActions>
</Dialog> </Dialog>
<Backdrop
sx={{
color: '#fff',
zIndex: (theme) => theme.zIndex.drawer + 1,
overflow: 'hidden'
}}
open={showLoading}
>
<CircularProgress color="inherit" />
</Backdrop>
</Card> </Card>
: :
<Box sx={{display:'flex',justifyContent:'center'}}> <Box sx={{display:'flex',justifyContent:'center'}}>