Fix channel name validation
This commit is contained in:
@@ -6,18 +6,19 @@ import { Controller, useForm } from "react-hook-form";
|
|||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
|
|
||||||
import { Input } from "@app/components/form/Input.js";
|
import { Input } from "@app/components/form/Input.js";
|
||||||
|
import { ChannelSettingsValidation } from "@app/validation/channelSettings.js";
|
||||||
import { Form } from "@components/form/Form";
|
import { Form } from "@components/form/Form";
|
||||||
|
import { Select } from "@components/form/Select.js";
|
||||||
|
import { Toggle } from "@components/form/Toggle.js";
|
||||||
import { useDevice } from "@core/providers/useDevice.js";
|
import { useDevice } from "@core/providers/useDevice.js";
|
||||||
import {
|
import {
|
||||||
ArrowPathIcon,
|
ArrowPathIcon,
|
||||||
EyeIcon,
|
EyeIcon,
|
||||||
EyeSlashIcon,
|
EyeSlashIcon,
|
||||||
} from "@heroicons/react/24/outline";
|
} from "@heroicons/react/24/outline";
|
||||||
|
import { classValidatorResolver } from "@hookform/resolvers/class-validator";
|
||||||
import { Protobuf } from "@meshtastic/meshtasticjs";
|
import { Protobuf } from "@meshtastic/meshtasticjs";
|
||||||
|
|
||||||
import { Select } from "../form/Select.js";
|
|
||||||
import { Toggle } from "../form/Toggle.js";
|
|
||||||
|
|
||||||
export interface SettingsPanelProps {
|
export interface SettingsPanelProps {
|
||||||
channel: Protobuf.Channel;
|
channel: Protobuf.Channel;
|
||||||
}
|
}
|
||||||
@@ -34,9 +35,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
|
|||||||
reset,
|
reset,
|
||||||
control,
|
control,
|
||||||
setValue,
|
setValue,
|
||||||
} = useForm<
|
} = useForm<ChannelSettingsValidation>({
|
||||||
Omit<Protobuf.ChannelSettings, "psk"> & { psk: string; enabled: boolean }
|
|
||||||
>({
|
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
enabled: [
|
enabled: [
|
||||||
Protobuf.Channel_Role.SECONDARY,
|
Protobuf.Channel_Role.SECONDARY,
|
||||||
@@ -47,6 +46,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
|
|||||||
...channel?.settings,
|
...channel?.settings,
|
||||||
psk: fromByteArray(channel?.settings?.psk ?? new Uint8Array(0)),
|
psk: fromByteArray(channel?.settings?.psk ?? new Uint8Array(0)),
|
||||||
},
|
},
|
||||||
|
resolver: classValidatorResolver(ChannelSettingsValidation),
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -136,6 +136,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
|
|||||||
<Input
|
<Input
|
||||||
label="Name"
|
label="Name"
|
||||||
description="Max transmit power in dBm"
|
description="Max transmit power in dBm"
|
||||||
|
error={errors.name?.message}
|
||||||
{...register("name")}
|
{...register("name")}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
@@ -162,7 +163,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
|
|||||||
<Input
|
<Input
|
||||||
width="100%"
|
width="100%"
|
||||||
label="Pre-Shared Key"
|
label="Pre-Shared Key"
|
||||||
description="Max transmit power in dBm"
|
description="Channel key to encrypt data"
|
||||||
type={pskHidden ? "password" : "text"}
|
type={pskHidden ? "password" : "text"}
|
||||||
action={{
|
action={{
|
||||||
icon: pskHidden ? (
|
icon: pskHidden ? (
|
||||||
@@ -174,6 +175,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
|
|||||||
setPskHidden(!pskHidden);
|
setPskHidden(!pskHidden);
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
error={errors.psk?.message}
|
||||||
{...register("psk")}
|
{...register("psk")}
|
||||||
/>
|
/>
|
||||||
<Controller
|
<Controller
|
||||||
@@ -182,7 +184,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
|
|||||||
render={({ field: { value, ...rest } }) => (
|
render={({ field: { value, ...rest } }) => (
|
||||||
<Toggle
|
<Toggle
|
||||||
label="Uplink Enabled"
|
label="Uplink Enabled"
|
||||||
description="Description"
|
description="Send packets to designated MQTT server"
|
||||||
checked={value}
|
checked={value}
|
||||||
{...rest}
|
{...rest}
|
||||||
/>
|
/>
|
||||||
@@ -194,7 +196,7 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
|
|||||||
render={({ field: { value, ...rest } }) => (
|
render={({ field: { value, ...rest } }) => (
|
||||||
<Toggle
|
<Toggle
|
||||||
label="Downlink Enabled"
|
label="Downlink Enabled"
|
||||||
description="Description"
|
description="Recieve packets to designated MQTT server"
|
||||||
checked={value}
|
checked={value}
|
||||||
{...rest}
|
{...rest}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
import { IsBoolean, IsInt, Length } from "class-validator";
|
import { IsBoolean, IsInt, IsNumber, IsString, Length } from "class-validator";
|
||||||
|
|
||||||
import type { Protobuf } from "@meshtastic/meshtasticjs";
|
import type { Protobuf } from "@meshtastic/meshtasticjs";
|
||||||
|
|
||||||
export class ChannelSettingsValidation
|
export class ChannelSettingsValidation
|
||||||
implements Omit<Protobuf.ChannelSettings, "channelNum">
|
implements Omit<Protobuf.ChannelSettings, "psk">
|
||||||
{
|
{
|
||||||
psk: Uint8Array;
|
@IsBoolean()
|
||||||
|
enabled: boolean;
|
||||||
|
|
||||||
@Length(1, 30)
|
@IsString()
|
||||||
|
psk: string;
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
channelNum: number;
|
||||||
|
|
||||||
|
@Length(1, 11)
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@IsInt()
|
@IsInt()
|
||||||
|
|||||||
Reference in New Issue
Block a user