import { Button } from "@components/Button"; import { InputFieldWithLabel } from "./InputField"; import { UsbConfigState } from "@/hooks/stores"; import { useEffect, useCallback, useState } from "react"; import { useJsonRpc } from "../hooks/useJsonRpc"; import { USBConfig } from "../routes/devices.$id.settings.hardware"; export default function UpdateUsbConfigModal({ onSetUsbConfig, onRestoreToDefault, }: { onSetUsbConfig: (usbConfig: USBConfig) => void; onRestoreToDefault: () => void; }) { const [usbConfigState, setUsbConfigState] = useState({ vendor_id: "", product_id: "", serial_number: "", manufacturer: "", product: "", }); const [send] = useJsonRpc(); const syncUsbConfig = useCallback(() => { send("getUsbConfig", {}, resp => { if ("error" in resp) { console.error("Failed to load USB Config:", resp.error); } else { setUsbConfigState(resp.result as UsbConfigState); } }); }, [send, setUsbConfigState]); // Load stored usb config from the backend useEffect(() => { syncUsbConfig(); }, [syncUsbConfig]); const handleUsbVendorIdChange = (value: string) => { setUsbConfigState({ ...usbConfigState, vendor_id: value }); }; const handleUsbProductIdChange = (value: string) => { setUsbConfigState({ ...usbConfigState, product_id: value }); }; const handleUsbSerialChange = (value: string) => { setUsbConfigState({ ...usbConfigState, serial_number: value }); }; const handleUsbManufacturer = (value: string) => { setUsbConfigState({ ...usbConfigState, manufacturer: value }); }; const handleUsbProduct = (value: string) => { setUsbConfigState({ ...usbConfigState, product: value }); }; return (
handleUsbVendorIdChange(e.target.value)} /> handleUsbProductIdChange(e.target.value)} /> handleUsbSerialChange(e.target.value)} /> handleUsbManufacturer(e.target.value)} /> handleUsbProduct(e.target.value)} />
); }