import { useCallback, useEffect, useState } from 'react';
import {
Button,
Card,
CardActions,
CardContent,
CardHeader,
Divider,
Stack,
TextField,
InputLabel,
MenuItem,
Select,
FormControl,
SvgIcon,
Dialog,
DialogTitle,
DialogContent,
DialogContentText,
DialogActions,
Box,
IconButton,
Icon,
SnackbarContent,
Snackbar,
Checkbox,
FormControlLabel,
useTheme,
} from '@mui/material';
import XMarkIcon from '@heroicons/react/24/outline/XMarkIcon';
import Check from '@heroicons/react/24/outline/CheckIcon';
//import ExclamationTriangleIcon from '@heroicons/react/24/solid/ExclamationTriangleIcon';
import CircularProgress from '@mui/material/CircularProgress';
import Backdrop from '@mui/material/Backdrop';
import { useRouter } from 'next/router';
import GlobeAltIcon from '@heroicons/react/24/outline/GlobeAltIcon';
export const DevicesWiFi = () => {
const theme = useTheme();
const router = useRouter()
const [content, setContent] = useState([])
const [applyContent, setApplyContent] = useState([])
const [apply, setApply] = useState(false)
const [errorModal, setErrorModal] = useState(false)
const [errorModalText, setErrorModalText] = useState("")
const fetchWifiData = async () => {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", localStorage.getItem("token"));
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT || ""}/api/device/${router.query.id[0]}/wifi`, requestOptions)
.then(response => {
if (response.status === 401) {
router.push("/auth/login")
}
return response.json()
})
.then(result => {
console.log("wifi content", result)
result.map((item) => {
let contentToApply = {
hasChanges: false,
path: item.path,
}
setApplyContent(oldValue => [...oldValue, contentToApply])
})
setContent(result)
})
.catch(error => console.log('error', error));
};
useEffect(() => {
fetchWifiData()
}, [])
return (
{content.length > 1 ?
(content.map((item, index) => {
return (
}
/>
{item.enable.value != null &&
{
let enable = item.enable.value == 1 ? "0" : "1"
console.log(enable)
applyContent[index].hasChanges = true
applyContent[index].enable = {
value: enable
}
setApplyContent([...applyContent])
item.enable.value = enable
}} />}
label="Enabled" />}
{item.ssid.value != null && {
applyContent[index].hasChanges = true
applyContent[index].ssid = {
value: e.target.value
}
setApplyContent([...applyContent])
item.ssid.value = e.target.value
}}
/>}
{item.securityCapabilities &&
}
{item.password.value != null &&
{
if (e.target.value.length >= 8) {
applyContent[index].hasChanges = true
} else {
applyContent[index].hasChanges = false
}
applyContent[index].password = {
value: e.target.value
}
setApplyContent([...applyContent])
item.password.value = e.target.value
console.log("applyContent: ", applyContent)
}}
/>}
{item.channel?.value != null && item.possibleChannels?.value != null &&
Channel
}
{item.standard.value != null &&
{
applyContent[index].hasChanges = true
applyContent[index].standard = {
value: e.target.value
}
setApplyContent([...applyContent])
item.standard.value = e.target.value
}}
/>}
)
})) :
}
theme.zIndex.drawer + 1 }}
open={apply}
>
);
};