|
|
@ -1,15 +1,11 @@ |
|
|
import type React from "react"; |
|
|
|
|
|
import { useEffect } from "react"; |
|
|
import { useEffect } from "react"; |
|
|
|
|
|
|
|
|
import { Controller, useForm, useWatch } from "react-hook-form"; |
|
|
import { Controller, useForm, useWatch } from "react-hook-form"; |
|
|
import { toast } from "react-hot-toast"; |
|
|
import { FormSection } from "@components/form/FormSection.js"; |
|
|
|
|
|
import { Input } from "@components/form/Input.js"; |
|
|
import { FormSection } from "@app/components/form/FormSection.js"; |
|
|
import { IPInput } from "@components/form/IPInput.js"; |
|
|
import { Input } from "@app/components/form/Input.js"; |
|
|
import { Select } from "@components/form/Select.js"; |
|
|
import { IPInput } from "@app/components/form/IPInput.js"; |
|
|
import { Toggle } from "@components/form/Toggle.js"; |
|
|
import { Select } from "@app/components/form/Select.js"; |
|
|
import { renderOptions } from "@core/utils/selectEnumOptions.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 { NetworkValidation } from "@app/validation/config/network.js"; |
|
|
import { Form } from "@components/form/Form"; |
|
|
import { Form } from "@components/form/Form"; |
|
|
import { useDevice } from "@core/providers/useDevice.js"; |
|
|
import { useDevice } from "@core/providers/useDevice.js"; |
|
|
@ -19,17 +15,13 @@ import { Protobuf } from "@meshtastic/meshtasticjs"; |
|
|
|
|
|
|
|
|
export const Network = (): JSX.Element => { |
|
|
export const Network = (): JSX.Element => { |
|
|
const { config, setWorkingConfig } = useDevice(); |
|
|
const { config, setWorkingConfig } = useDevice(); |
|
|
const { |
|
|
const { register, handleSubmit, control, reset } = useForm<NetworkValidation>( |
|
|
register, |
|
|
{ |
|
|
handleSubmit, |
|
|
|
|
|
formState: { errors, isDirty }, |
|
|
|
|
|
control, |
|
|
|
|
|
reset |
|
|
|
|
|
} = useForm<NetworkValidation>({ |
|
|
|
|
|
mode: "onChange", |
|
|
mode: "onChange", |
|
|
defaultValues: config.network, |
|
|
defaultValues: config.network, |
|
|
resolver: classValidatorResolver(NetworkValidation) |
|
|
resolver: classValidatorResolver(NetworkValidation) |
|
|
}); |
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
const wifiEnabled = useWatch({ |
|
|
const wifiEnabled = useWatch({ |
|
|
control, |
|
|
control, |
|
|
@ -66,19 +58,6 @@ export const Network = (): JSX.Element => { |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<Form onSubmit={onSubmit}> |
|
|
<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"> |
|
|
<FormSection title="WiFi Config"> |
|
|
<Controller |
|
|
<Controller |
|
|
name="wifiEnabled" |
|
|
name="wifiEnabled" |
|
|
@ -95,7 +74,6 @@ export const Network = (): JSX.Element => { |
|
|
<Input |
|
|
<Input |
|
|
label="SSID" |
|
|
label="SSID" |
|
|
description="Network name" |
|
|
description="Network name" |
|
|
error={errors.wifiSsid?.message} |
|
|
|
|
|
disabled={!wifiEnabled} |
|
|
disabled={!wifiEnabled} |
|
|
{...register("wifiSsid", { disabled: !wifiEnabled })} |
|
|
{...register("wifiSsid", { disabled: !wifiEnabled })} |
|
|
/> |
|
|
/> |
|
|
@ -103,7 +81,6 @@ export const Network = (): JSX.Element => { |
|
|
label="PSK" |
|
|
label="PSK" |
|
|
type="password" |
|
|
type="password" |
|
|
description="Network password" |
|
|
description="Network password" |
|
|
error={errors.wifiPsk?.message} |
|
|
|
|
|
disabled={!wifiEnabled} |
|
|
disabled={!wifiEnabled} |
|
|
{...register("wifiPsk", { disabled: !wifiEnabled })} |
|
|
{...register("wifiPsk", { disabled: !wifiEnabled })} |
|
|
/> |
|
|
/> |
|
|
@ -138,26 +115,21 @@ export const Network = (): JSX.Element => { |
|
|
<IPInput |
|
|
<IPInput |
|
|
label="IP" |
|
|
label="IP" |
|
|
description="IP Address" |
|
|
description="IP Address" |
|
|
error={errors.ipv4Config?.ip?.message} |
|
|
|
|
|
{...register("ipv4Config.ip", { valueAsNumber: true })} |
|
|
{...register("ipv4Config.ip", { valueAsNumber: true })} |
|
|
/> |
|
|
/> |
|
|
<IPInput |
|
|
<IPInput |
|
|
label="Gateway" |
|
|
label="Gateway" |
|
|
description="Default Gateway" |
|
|
description="Default Gateway" |
|
|
error={errors.ipv4Config?.gateway?.message} |
|
|
|
|
|
{...register("ipv4Config.gateway", { valueAsNumber: true })} |
|
|
{...register("ipv4Config.gateway", { valueAsNumber: true })} |
|
|
/> |
|
|
/> |
|
|
<IPInput |
|
|
<IPInput |
|
|
label="Subnet" |
|
|
label="Subnet" |
|
|
description="Subnet Mask" |
|
|
description="Subnet Mask" |
|
|
error={errors.ipv4Config?.subnet?.message} |
|
|
|
|
|
{...register("ipv4Config.subnet", { valueAsNumber: true })} |
|
|
{...register("ipv4Config.subnet", { valueAsNumber: true })} |
|
|
/> |
|
|
/> |
|
|
<IPInput |
|
|
<IPInput |
|
|
label="DNS" |
|
|
label="DNS" |
|
|
// type="number" //prevent
|
|
|
|
|
|
description="DNS Server" |
|
|
description="DNS Server" |
|
|
error={errors.ipv4Config?.dns?.message} |
|
|
|
|
|
{...register("ipv4Config.dns", { valueAsNumber: true })} |
|
|
{...register("ipv4Config.dns", { valueAsNumber: true })} |
|
|
/> |
|
|
/> |
|
|
</> |
|
|
</> |
|
|
@ -166,13 +138,11 @@ export const Network = (): JSX.Element => { |
|
|
<Input |
|
|
<Input |
|
|
label="NTP Server" |
|
|
label="NTP Server" |
|
|
description="NTP server for time synchronization" |
|
|
description="NTP server for time synchronization" |
|
|
error={errors.ntpServer?.message} |
|
|
|
|
|
{...register("ntpServer")} |
|
|
{...register("ntpServer")} |
|
|
/> |
|
|
/> |
|
|
<Input |
|
|
<Input |
|
|
label="Rsyslog Server" |
|
|
label="Rsyslog Server" |
|
|
description="Rsyslog server for external logging" |
|
|
description="Rsyslog server for external logging" |
|
|
error={errors.rsyslogServer?.message} |
|
|
|
|
|
{...register("rsyslogServer")} |
|
|
{...register("rsyslogServer")} |
|
|
/> |
|
|
/> |
|
|
</Form> |
|
|
</Form> |
|
|
|