Start moduleConfig & general import cleanup
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
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 { IPInput } from "@app/components/form/IPInput.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 { FormSection } from "@components/form/FormSection.js";
|
||||
import { Input } from "@components/form/Input.js";
|
||||
import { IPInput } from "@components/form/IPInput.js";
|
||||
import { Select } from "@components/form/Select.js";
|
||||
import { Toggle } from "@components/form/Toggle.js";
|
||||
import { renderOptions } from "@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";
|
||||
@@ -19,17 +15,13 @@ import { Protobuf } from "@meshtastic/meshtasticjs";
|
||||
|
||||
export const Network = (): JSX.Element => {
|
||||
const { config, setWorkingConfig } = useDevice();
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors, isDirty },
|
||||
control,
|
||||
reset
|
||||
} = useForm<NetworkValidation>({
|
||||
mode: "onChange",
|
||||
defaultValues: config.network,
|
||||
resolver: classValidatorResolver(NetworkValidation)
|
||||
});
|
||||
const { register, handleSubmit, control, reset } = useForm<NetworkValidation>(
|
||||
{
|
||||
mode: "onChange",
|
||||
defaultValues: config.network,
|
||||
resolver: classValidatorResolver(NetworkValidation)
|
||||
}
|
||||
);
|
||||
|
||||
const wifiEnabled = useWatch({
|
||||
control,
|
||||
@@ -66,19 +58,6 @@ export const Network = (): JSX.Element => {
|
||||
|
||||
return (
|
||||
<Form onSubmit={onSubmit}>
|
||||
<ErrorMessage errors={errors} name="wifiEnabled" />
|
||||
<ErrorMessage errors={errors} name="wifiMode" />
|
||||
<ErrorMessage errors={errors} name="wifiSsid" />
|
||||
<ErrorMessage errors={errors} name="wifiPsk" />
|
||||
<ErrorMessage errors={errors} name="ntpServer" />
|
||||
<ErrorMessage errors={errors} name="ethEnabled" />
|
||||
<ErrorMessage errors={errors} name="addressMode" />
|
||||
<ErrorMessage errors={errors} name="ethConfig" />
|
||||
<ErrorMessage errors={errors} name="ip" />
|
||||
<ErrorMessage errors={errors} name="gateway" />
|
||||
<ErrorMessage errors={errors} name="subnet" />
|
||||
<ErrorMessage errors={errors} name="dns" />
|
||||
|
||||
<FormSection title="WiFi Config">
|
||||
<Controller
|
||||
name="wifiEnabled"
|
||||
@@ -95,7 +74,6 @@ export const Network = (): JSX.Element => {
|
||||
<Input
|
||||
label="SSID"
|
||||
description="Network name"
|
||||
error={errors.wifiSsid?.message}
|
||||
disabled={!wifiEnabled}
|
||||
{...register("wifiSsid", { disabled: !wifiEnabled })}
|
||||
/>
|
||||
@@ -103,7 +81,6 @@ export const Network = (): JSX.Element => {
|
||||
label="PSK"
|
||||
type="password"
|
||||
description="Network password"
|
||||
error={errors.wifiPsk?.message}
|
||||
disabled={!wifiEnabled}
|
||||
{...register("wifiPsk", { disabled: !wifiEnabled })}
|
||||
/>
|
||||
@@ -138,26 +115,21 @@ export const Network = (): JSX.Element => {
|
||||
<IPInput
|
||||
label="IP"
|
||||
description="IP Address"
|
||||
error={errors.ipv4Config?.ip?.message}
|
||||
{...register("ipv4Config.ip", { valueAsNumber: true })}
|
||||
/>
|
||||
<IPInput
|
||||
label="Gateway"
|
||||
description="Default Gateway"
|
||||
error={errors.ipv4Config?.gateway?.message}
|
||||
{...register("ipv4Config.gateway", { valueAsNumber: true })}
|
||||
/>
|
||||
<IPInput
|
||||
label="Subnet"
|
||||
description="Subnet Mask"
|
||||
error={errors.ipv4Config?.subnet?.message}
|
||||
{...register("ipv4Config.subnet", { valueAsNumber: true })}
|
||||
/>
|
||||
<IPInput
|
||||
label="DNS"
|
||||
// type="number" //prevent
|
||||
description="DNS Server"
|
||||
error={errors.ipv4Config?.dns?.message}
|
||||
{...register("ipv4Config.dns", { valueAsNumber: true })}
|
||||
/>
|
||||
</>
|
||||
@@ -166,13 +138,11 @@ export const Network = (): JSX.Element => {
|
||||
<Input
|
||||
label="NTP Server"
|
||||
description="NTP server for time synchronization"
|
||||
error={errors.ntpServer?.message}
|
||||
{...register("ntpServer")}
|
||||
/>
|
||||
<Input
|
||||
label="Rsyslog Server"
|
||||
description="Rsyslog server for external logging"
|
||||
error={errors.rsyslogServer?.message}
|
||||
{...register("rsyslogServer")}
|
||||
/>
|
||||
</Form>
|
||||
|
||||
Reference in New Issue
Block a user