import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { CCard, CCardHeader, CCardBody, CCol, CLabel, CCollapse, CCardFooter, CButton, CRow, CPopover, } from '@coreui/react'; import CIcon from '@coreui/icons-react'; import { cilWindowMaximize } from '@coreui/icons'; import { prettyDate } from 'utils/helper'; import axiosInstance from 'utils/axiosInstance'; import { CopyToClipboardButton, HideTextButton, NotesTable, useAuth, useDevice, } from 'ucentral-libs'; import DeviceConfigurationModal from './DeviceConfigurationModal'; const DeviceConfiguration = () => { const { t } = useTranslation(); const { currentToken, endpoints } = useAuth(); const { deviceSerialNumber } = useDevice(); const [loading, setLoading] = useState(false); const [showPassword, setShowPassword] = useState(false); const [collapse, setCollapse] = useState(false); const [showModal, setShowModal] = useState(false); const [device, setDevice] = useState(null); const toggleShowPassword = () => { setShowPassword(!showPassword); }; const toggle = (e) => { setCollapse(!collapse); e.preventDefault(); }; const toggleModal = () => { setShowModal(!showModal); }; const getDevice = () => { const options = { headers: { Accept: 'application/json', Authorization: `Bearer ${currentToken}`, }, }; axiosInstance .get( `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}`, options, ) .then((response) => { setDevice(response.data); }) .catch(() => {}); }; const saveNote = (currentNote) => { setLoading(true); const parameters = { serialNumber: deviceSerialNumber, notes: [{ note: currentNote }], }; const headers = { Accept: 'application/json', Authorization: `Bearer ${currentToken}`, }; axiosInstance .put( `${endpoints.ucentralgw}/api/v1/device/${encodeURIComponent(deviceSerialNumber)}`, parameters, { headers }, ) .then(() => { getDevice(); }) .catch(() => {}) .finally(() => { setLoading(false); }); }; const getPassword = () => { const password = device.devicePassword === '' ? 'openwifi' : device.devicePassword; return showPassword ? password : '******'; }; useEffect(() => { if (deviceSerialNumber) getDevice(); }, [deviceSerialNumber]); if (device) { return (