import { Dialog, DialogActions, DialogContent, DialogTitle, Grid2, TextField } from "@mui/material"; import CancelSubmit from "common/CancelSubmit"; import { useComponentAPI, useSnackbar } from "hooks"; import { pond } from "protobuf-ts/pond"; import { useGlobalState } from "providers"; import { useState } from "react"; import { or } from "utils"; interface Props { open: boolean; onClose: () => void; device: number; } export default function AddComponentManualDialog (props: Props) { const { open, onClose, device } = props; const [{as}] = useGlobalState(); const componentAPI = useComponentAPI(); const snackbar = useSnackbar(); const [component, setComponent] = useState(pond.ComponentSettings.create()) const onSubmit = () => { componentAPI.add(device, component, as).then(() => { snackbar.success("Component added") }) } const close = () => { setComponent(pond.ComponentSettings.create()) onClose() } return ( Manual Component Entry { let newSettings = pond.ComponentSettings.create(component) newSettings.name = event.currentTarget.value setComponent(newSettings) }} /> { let newSettings = pond.ComponentSettings.create(component) newSettings.type = or(parseInt(event.currentTarget.value), 0) setComponent(newSettings) }} /> { let newSettings = pond.ComponentSettings.create(component) newSettings.addressType = or(parseInt(event.currentTarget.value), 0) setComponent(newSettings) }} /> { let newSettings = pond.ComponentSettings.create(component) newSettings.address = or(parseInt(event.currentTarget.value), 0) setComponent(newSettings) }} /> { let newSettings = pond.ComponentSettings.create(component) newSettings.measurementPeriodMs = or(parseInt(event.currentTarget.value), 0) setComponent(newSettings) }} /> { let newSettings = pond.ComponentSettings.create(component) newSettings.reportPeriodMs = or(parseInt(event.currentTarget.value), 0) setComponent(newSettings) }} /> ) }