import type React from "react"; import { useEffect } from "react"; import { Controller, useForm, useWatch } from "react-hook-form"; import { toast } from "react-hot-toast"; import { Input } from "@app/components/form/Input.js"; import { Select } from "@app/components/form/Select.js"; import { Toggle } from "@app/components/form/Toggle.js"; import { BluetoothValidation } from "@app/validation/config/bluetooth.js"; import { Form } from "@components/form/Form"; import { useDevice } from "@core/providers/useDevice.js"; import { renderOptions } from "@core/utils/selectEnumOptions.js"; import { classValidatorResolver } from "@hookform/resolvers/class-validator"; import { Protobuf } from "@meshtastic/meshtasticjs"; export const Bluetooth = (): JSX.Element => { const { config, connection, setConfig } = useDevice(); const { register, handleSubmit, formState: { errors, isDirty }, control, reset } = useForm({ defaultValues: config.bluetooth, resolver: classValidatorResolver(BluetoothValidation) }); useEffect(() => { reset(config.bluetooth); }, [reset, config.bluetooth]); const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( connection .setConfig({ config: { payloadVariant: { oneofKind: "bluetooth", bluetooth: data } } }) .then(() => setConfig({ payloadVariant: { oneofKind: "bluetooth", bluetooth: data } }) ), { loading: "Saving...", success: "Saved Bluetooth Config, Restarting Node", error: "No response received" } ); } }); const pairingMode = useWatch({ control, name: "mode", defaultValue: Protobuf.Config_BluetoothConfig_PairingMode.RANDOM_PIN }); return (
reset(config.bluetooth)} dirty={isDirty} onSubmit={onSubmit} > ( )} /> ); };