import type React from "react"; import { useEffect } from "react"; import { Controller, useForm, useWatch } from "react-hook-form"; import { toast } from "react-hot-toast"; import { FormSection } from "@app/components/form/FormSection.js"; 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 { renderOptions } from "@app/core/utils/selectEnumOptions.js"; import { NetworkValidation } from "@app/validation/config/network.js"; import { Form } from "@components/form/Form"; import { useDevice } from "@core/providers/useDevice.js"; import { classValidatorResolver } from "@hookform/resolvers/class-validator"; import { Protobuf } from "@meshtastic/meshtasticjs"; export const Network = (): JSX.Element => { const { config, connection } = useDevice(); const { register, handleSubmit, formState: { errors, isDirty }, control, reset, } = useForm({ defaultValues: config.network, resolver: classValidatorResolver(NetworkValidation), }); const wifiEnabled = useWatch({ control, name: "wifiEnabled", defaultValue: false, }); const ethEnabled = useWatch({ control, name: "ethEnabled", defaultValue: false, }); useEffect(() => { reset(config.network); }, [reset, config.network]); const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( connection.setConfig( { payloadVariant: { oneofKind: "network", network: data, }, }, async () => { reset({ ...data }); await Promise.resolve(); } ), { loading: "Saving...", success: "Saved Network Config, Restarting Node", error: "No response received", } ); } }); return (
reset(config.network)} dirty={isDirty} onSubmit={onSubmit} > ( )} /> ( )} />
); };