import DeleteIcon from "@mui/icons-material/Delete"; import { IconButton, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Tooltip, } from "@mui/material"; import React from "react"; import { Device, DeviceApi } from "../api/DeviceApi"; import { useAlert } from "../hooks/context_providers/AlertDialogProvider"; import { useConfirm } from "../hooks/context_providers/ConfirmDialogProvider"; import { useLoadingMessage } from "../hooks/context_providers/LoadingMessageProvider"; import { useSnackbar } from "../hooks/context_providers/SnackbarProvider"; import { AsyncWidget } from "../widgets/AsyncWidget"; import { SolarEnergyRouteContainer } from "../widgets/SolarEnergyRouteContainer"; import { TimeWidget } from "../widgets/TimeWidget"; import CheckIcon from "@mui/icons-material/Check"; export function PendingDevicesRoute(): React.ReactElement { const loadKey = React.useRef(1); const [pending, setPending] = React.useState(); const load = async () => { setPending(await DeviceApi.PendingList()); }; const reload = () => { loadKey.current += 1; setPending(undefined); }; return ( ( )} /> ); } function PendingDevicesList(p: { pending: Device[]; onReload: () => void; }): React.ReactElement { const alert = useAlert(); const confirm = useConfirm(); const snackbar = useSnackbar(); const loadingMessage = useLoadingMessage(); const validateDevice = async (d: Device) => { try { loadingMessage.show("Validating device..."); await DeviceApi.Validate(d); snackbar("The device has been successfully validated!"); p.onReload(); } catch (e) { console.error(`Failed to validate device! ${e})`); alert("Failed to validate device!"); } finally { loadingMessage.hide(); } }; const deleteDevice = async (d: Device) => { try { if ( !(await confirm( `Do you really want to delete the device ${d.id}? The operation cannot be reverted!` )) ) return; loadingMessage.show("Deleting device..."); await DeviceApi.Delete(d); snackbar("The device has been successfully deleted!"); p.onReload(); } catch (e) { console.error(`Failed to delete device! ${e})`); alert("Failed to delete device!"); } finally { loadingMessage.hide(); } }; if (p.pending.length === 0) { return

There is no device awaiting confirmation right now.

; } return ( # Model Version Max number of relays Created {p.pending.map((dev) => ( {dev.id} {dev.info.reference} {dev.info.version} {dev.info.max_relays} validateDevice(dev)}> deleteDevice(dev)}> ))}
); }