Merge pull request 'develop' (#9) from develop into main
Reviewed-on: #9
This commit is contained in:
@@ -5,6 +5,8 @@ import { timezones } from "./timezones";
|
|||||||
import SystemFileUpload from "./SystemFileUpload";
|
import SystemFileUpload from "./SystemFileUpload";
|
||||||
import type { SystemValues, SystemValuesErrors } from "../../../types/types";
|
import type { SystemValues, SystemValuesErrors } from "../../../types/types";
|
||||||
import { useDNSSettings, useSystemConfig } from "../../../hooks/useSystemConfig";
|
import { useDNSSettings, useSystemConfig } from "../../../hooks/useSystemConfig";
|
||||||
|
import { ValidateIPaddress } from "../../../utils/utils";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
const SystemConfigFields = () => {
|
const SystemConfigFields = () => {
|
||||||
const { saveSystemSettings, systemSettingsData, saveSystemSettingsLoading } = useSystemConfig();
|
const { saveSystemSettings, systemSettingsData, saveSystemSettingsLoading } = useSystemConfig();
|
||||||
@@ -35,6 +37,14 @@ const SystemConfigFields = () => {
|
|||||||
if (!values.timeZone) errors.timeZone = "Required";
|
if (!values.timeZone) errors.timeZone = "Required";
|
||||||
if (isNaN(interval) || interval <= 0) errors.sntpInterval = "Cannot be less than 0";
|
if (isNaN(interval) || interval <= 0) errors.sntpInterval = "Cannot be less than 0";
|
||||||
if (!values.sntpServer) errors.sntpServer = "Required";
|
if (!values.sntpServer) errors.sntpServer = "Required";
|
||||||
|
const invalidPrimary = ValidateIPaddress(values.serverPrimary);
|
||||||
|
const invalidSecondary = ValidateIPaddress(values.serverSecondary);
|
||||||
|
|
||||||
|
if (invalidPrimary || invalidSecondary) {
|
||||||
|
toast.error(invalidPrimary || invalidSecondary, {
|
||||||
|
id: "invalid-ip",
|
||||||
|
});
|
||||||
|
}
|
||||||
return errors;
|
return errors;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -52,7 +62,7 @@ const SystemConfigFields = () => {
|
|||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
validate={validateValues}
|
validate={validateValues}
|
||||||
enableReinitialize
|
enableReinitialize
|
||||||
validateOnChange
|
validateOnChange={false}
|
||||||
validateOnBlur
|
validateOnBlur
|
||||||
>
|
>
|
||||||
{({ values, errors, touched, isSubmitting }) => (
|
{({ values, errors, touched, isSubmitting }) => (
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const ModemCard = () => {
|
|||||||
return (
|
return (
|
||||||
<Card className="p-4">
|
<Card className="p-4">
|
||||||
<CardHeader title={"Modem"} />
|
<CardHeader title={"Modem"} />
|
||||||
|
|
||||||
<ModemSettings />
|
<ModemSettings />
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { useEffect, useState } from "react";
|
|||||||
import ModemToggle from "./ModemToggle";
|
import ModemToggle from "./ModemToggle";
|
||||||
import { faEyeSlash, faEye } from "@fortawesome/free-solid-svg-icons";
|
import { faEyeSlash, faEye } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { ValidateIPaddress } from "../../../utils/utils";
|
||||||
|
import { toast, Toaster } from "sonner";
|
||||||
|
|
||||||
const ModemSettings = () => {
|
const ModemSettings = () => {
|
||||||
const [showSettings, setShowSettings] = useState(false);
|
const [showSettings, setShowSettings] = useState(false);
|
||||||
@@ -16,6 +18,8 @@ const ModemSettings = () => {
|
|||||||
const username = modemQuery?.data?.propUsername.value;
|
const username = modemQuery?.data?.propUsername.value;
|
||||||
const password = modemQuery?.data?.propPassword?.value;
|
const password = modemQuery?.data?.propPassword?.value;
|
||||||
const mode = modemQuery?.data?.propMode?.value;
|
const mode = modemQuery?.data?.propMode?.value;
|
||||||
|
const serverPrimary = modemQuery?.data?.propNameServerPrimary?.value;
|
||||||
|
const serverSecondary = modemQuery?.data?.propNameServerSecondary?.value;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setShowSettings(mode === "AUTO");
|
setShowSettings(mode === "AUTO");
|
||||||
@@ -26,9 +30,19 @@ const ModemSettings = () => {
|
|||||||
username: username ?? "",
|
username: username ?? "",
|
||||||
password: password ?? "",
|
password: password ?? "",
|
||||||
authenticationType: "PAP",
|
authenticationType: "PAP",
|
||||||
|
serverPrimary: serverPrimary ?? "",
|
||||||
|
serverSecondary: serverSecondary ?? "",
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (values: ModemSettingsType) => {
|
const handleSubmit = async (values: ModemSettingsType) => {
|
||||||
|
const invalidPrimary = ValidateIPaddress(values.serverPrimary);
|
||||||
|
const invalidSecondary = ValidateIPaddress(values.serverSecondary);
|
||||||
|
if (invalidPrimary || invalidSecondary) {
|
||||||
|
toast.error(invalidPrimary || invalidSecondary, {
|
||||||
|
id: "invalid-ip",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const modemConfig = {
|
const modemConfig = {
|
||||||
id: "ModemAndWifiManager-modem",
|
id: "ModemAndWifiManager-modem",
|
||||||
fields: [
|
fields: [
|
||||||
@@ -49,9 +63,24 @@ const ModemSettings = () => {
|
|||||||
property: "propMode",
|
property: "propMode",
|
||||||
value: showSettings ? "AUTO" : "MANUAL",
|
value: showSettings ? "AUTO" : "MANUAL",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
property: "propNameServerPrimary",
|
||||||
|
value: values.serverPrimary,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: "propNameServerSecondary",
|
||||||
|
value: values.serverSecondary,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
await modemMutation.mutateAsync(modemConfig);
|
|
||||||
|
const response = await modemMutation.mutateAsync(modemConfig);
|
||||||
|
|
||||||
|
if (!response?.id) {
|
||||||
|
toast.success("Modem settings updated successfully", {
|
||||||
|
id: "modemSettings",
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -107,9 +136,33 @@ const ModemSettings = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
<FormGroup>
|
||||||
|
<label htmlFor="serverPrimary" className="font-medium whitespace-nowrap md:w-2/3">
|
||||||
|
Name server primary
|
||||||
|
</label>
|
||||||
|
<Field
|
||||||
|
placeholder="Enter Server primary"
|
||||||
|
name="serverPrimary"
|
||||||
|
id="serverPrimary"
|
||||||
|
type="text"
|
||||||
|
className="p-1.5 border border-gray-400 rounded-lg"
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
<FormGroup>
|
||||||
|
<label htmlFor="serverSecondary" className="font-medium whitespace-nowrap md:w-2/3">
|
||||||
|
Name server secondary
|
||||||
|
</label>
|
||||||
|
<Field
|
||||||
|
placeholder="Enter Server secondary"
|
||||||
|
name="serverSecondary"
|
||||||
|
id="serverSecondary"
|
||||||
|
type="text"
|
||||||
|
className="p-1.5 border border-gray-400 rounded-lg"
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<label htmlFor="password" className="font-medium whitespace-nowrap md:w-2/3">
|
<label htmlFor="password" className="font-medium whitespace-nowrap md:w-2/3">
|
||||||
Password
|
Authentication Type
|
||||||
</label>
|
</label>
|
||||||
<Field
|
<Field
|
||||||
name="authenticationType"
|
name="authenticationType"
|
||||||
@@ -132,6 +185,7 @@ const ModemSettings = () => {
|
|||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
|
<Toaster />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -403,6 +403,8 @@ export type ModemSettingsType = {
|
|||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
authenticationType: string;
|
authenticationType: string;
|
||||||
|
serverPrimary: string;
|
||||||
|
serverSecondary: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type HitKind = "NPED" | "HOTLIST";
|
export type HitKind = "NPED" | "HOTLIST";
|
||||||
|
|||||||
@@ -184,3 +184,14 @@ export const reverseZoomMapping = (magnification: string) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ValidateIPaddress = (value: string | undefined) => {
|
||||||
|
if (!value) return;
|
||||||
|
|
||||||
|
const regex =
|
||||||
|
/^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
|
||||||
|
|
||||||
|
if (!regex.test(value)) {
|
||||||
|
return "Invalid IP address format";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user