Merge branch 'develop' into feature/mobile-menu
This commit is contained in:
@@ -5,6 +5,8 @@ import { timezones } from "./timezones";
|
||||
import SystemFileUpload from "./SystemFileUpload";
|
||||
import type { SystemValues, SystemValuesErrors } from "../../../types/types";
|
||||
import { useDNSSettings, useSystemConfig } from "../../../hooks/useSystemConfig";
|
||||
import { ValidateIPaddress } from "../../../utils/utils";
|
||||
import { toast } from "sonner";
|
||||
|
||||
const SystemConfigFields = () => {
|
||||
const { saveSystemSettings, systemSettingsData, saveSystemSettingsLoading } = useSystemConfig();
|
||||
@@ -35,6 +37,14 @@ const SystemConfigFields = () => {
|
||||
if (!values.timeZone) errors.timeZone = "Required";
|
||||
if (isNaN(interval) || interval <= 0) errors.sntpInterval = "Cannot be less than 0";
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -52,7 +62,7 @@ const SystemConfigFields = () => {
|
||||
onSubmit={handleSubmit}
|
||||
validate={validateValues}
|
||||
enableReinitialize
|
||||
validateOnChange
|
||||
validateOnChange={false}
|
||||
validateOnBlur
|
||||
>
|
||||
{({ values, errors, touched, isSubmitting }) => (
|
||||
|
||||
@@ -14,9 +14,6 @@ export async function sendBlobFileUpload({ file, opts }: BlobFileUpload): Promis
|
||||
if (!file) throw new Error("No file supplied");
|
||||
if (!opts?.uploadUrl) throw new Error("No URL supplied");
|
||||
|
||||
if (file?.type !== "text/csv") {
|
||||
throw new Error("This file is not supported, please upload a CSV file.");
|
||||
}
|
||||
const timeoutMs = opts?.timeoutMs ?? 30000;
|
||||
const fieldName = opts?.fieldName ?? "upload";
|
||||
const fileName = opts?.overrideFileName ?? file?.name;
|
||||
|
||||
@@ -6,7 +6,6 @@ const ModemCard = () => {
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<CardHeader title={"Modem"} />
|
||||
|
||||
<ModemSettings />
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -6,6 +6,8 @@ import { useEffect, useState } from "react";
|
||||
import ModemToggle from "./ModemToggle";
|
||||
import { faEyeSlash, faEye } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { ValidateIPaddress } from "../../../utils/utils";
|
||||
import { toast, Toaster } from "sonner";
|
||||
|
||||
const ModemSettings = () => {
|
||||
const [showSettings, setShowSettings] = useState(false);
|
||||
@@ -16,6 +18,8 @@ const ModemSettings = () => {
|
||||
const username = modemQuery?.data?.propUsername.value;
|
||||
const password = modemQuery?.data?.propPassword?.value;
|
||||
const mode = modemQuery?.data?.propMode?.value;
|
||||
const serverPrimary = modemQuery?.data?.propNameServerPrimary?.value;
|
||||
const serverSecondary = modemQuery?.data?.propNameServerSecondary?.value;
|
||||
|
||||
useEffect(() => {
|
||||
setShowSettings(mode === "AUTO");
|
||||
@@ -26,9 +30,19 @@ const ModemSettings = () => {
|
||||
username: username ?? "",
|
||||
password: password ?? "",
|
||||
authenticationType: "PAP",
|
||||
serverPrimary: serverPrimary ?? "",
|
||||
serverSecondary: serverSecondary ?? "",
|
||||
};
|
||||
|
||||
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 = {
|
||||
id: "ModemAndWifiManager-modem",
|
||||
fields: [
|
||||
@@ -49,9 +63,24 @@ const ModemSettings = () => {
|
||||
property: "propMode",
|
||||
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 (
|
||||
@@ -107,9 +136,33 @@ const ModemSettings = () => {
|
||||
/>
|
||||
</div>
|
||||
</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>
|
||||
<label htmlFor="password" className="font-medium whitespace-nowrap md:w-2/3">
|
||||
Password
|
||||
Authentication Type
|
||||
</label>
|
||||
<Field
|
||||
name="authenticationType"
|
||||
@@ -132,6 +185,7 @@ const ModemSettings = () => {
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
<Toaster />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useWifiAndModem } from "../../../hooks/useCameraWifiandModem";
|
||||
import { useState } from "react";
|
||||
import { faEyeSlash, faEye } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { toast, Toaster } from "sonner";
|
||||
|
||||
const WiFiSettingsForm = () => {
|
||||
const [showPwd, setShowPwd] = useState(false);
|
||||
@@ -19,6 +20,13 @@ const WiFiSettingsForm = () => {
|
||||
encryption: "WPA2",
|
||||
};
|
||||
|
||||
const validatePassword = (password: string) => {
|
||||
if (password.length < 8) {
|
||||
toast.error("Password must be at least 8 characters long", { id: "password" });
|
||||
return "Password must be at least 8 characters long";
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async (values: WifiSettingValues) => {
|
||||
const wifiConfig = {
|
||||
id: "ModemAndWifiManager-wifi",
|
||||
@@ -37,66 +45,71 @@ const WiFiSettingsForm = () => {
|
||||
await wifiMutation.mutateAsync(wifiConfig);
|
||||
};
|
||||
return (
|
||||
<Formik initialValues={initialValues} onSubmit={handleSubmit} enableReinitialize>
|
||||
{({ isSubmitting }) => (
|
||||
<Form className="flex flex-col space-y-5 px-2">
|
||||
<FormGroup>
|
||||
<label htmlFor="ssid" className="font-medium whitespace-nowrap md:w-2/3">
|
||||
SSID
|
||||
</label>
|
||||
<Field
|
||||
id="ssid"
|
||||
name="ssid"
|
||||
type="text"
|
||||
className="p-1.5 border border-gray-400 rounded-lg"
|
||||
placeholder="Enter SSID"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="password" className="font-medium whitespace-nowrap md:w-2/3">
|
||||
Password
|
||||
</label>
|
||||
<div className="flex gap-2 items-center relative mb-4">
|
||||
<>
|
||||
<Formik initialValues={initialValues} onSubmit={handleSubmit} enableReinitialize>
|
||||
{({ isSubmitting }) => (
|
||||
<Form className="flex flex-col space-y-5 px-2">
|
||||
<FormGroup>
|
||||
<label htmlFor="ssid" className="font-medium whitespace-nowrap md:w-2/3">
|
||||
SSID
|
||||
</label>
|
||||
<Field
|
||||
id="password"
|
||||
name="password"
|
||||
type={showPwd ? "text" : "password"}
|
||||
className="p-2 border border-gray-400 rounded-lg w-full"
|
||||
placeholder="Enter Password"
|
||||
id="ssid"
|
||||
name="ssid"
|
||||
type="text"
|
||||
className="p-1.5 border border-gray-400 rounded-lg"
|
||||
placeholder="Enter SSID"
|
||||
/>
|
||||
<FontAwesomeIcon
|
||||
type="button"
|
||||
className="absolute right-5 end-0"
|
||||
onClick={() => setShowPwd((s) => !s)}
|
||||
icon={showPwd ? faEyeSlash : faEye}
|
||||
/>
|
||||
</div>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="encryption" className="font-medium whitespace-nowrap md:w-2/3">
|
||||
WPA/Encryption Type
|
||||
</label>
|
||||
<Field
|
||||
id="encryption"
|
||||
name="encryption"
|
||||
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] flex-1 w-2/3"
|
||||
as="select"
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="password" className="font-medium whitespace-nowrap md:w-2/3">
|
||||
Password
|
||||
</label>
|
||||
<div className="flex gap-2 items-center relative mb-4">
|
||||
<Field
|
||||
id="password"
|
||||
name="password"
|
||||
type={showPwd ? "text" : "password"}
|
||||
className="p-2 border border-gray-400 rounded-lg w-full"
|
||||
placeholder="Enter Password"
|
||||
validate={validatePassword}
|
||||
/>
|
||||
|
||||
<FontAwesomeIcon
|
||||
type="button"
|
||||
className="absolute right-5 end-0"
|
||||
onClick={() => setShowPwd((s) => !s)}
|
||||
icon={showPwd ? faEyeSlash : faEye}
|
||||
/>
|
||||
</div>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="encryption" className="font-medium whitespace-nowrap md:w-2/3">
|
||||
WPA/Encryption Type
|
||||
</label>
|
||||
<Field
|
||||
id="encryption"
|
||||
name="encryption"
|
||||
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] flex-1 w-2/3"
|
||||
as="select"
|
||||
>
|
||||
<option value="WPA2">WPA2</option>
|
||||
<option value="WPA3">WPA3</option>
|
||||
<option value="WEP">WEP</option>
|
||||
<option value="None">None</option>
|
||||
</Field>
|
||||
</FormGroup>
|
||||
<button
|
||||
type="submit"
|
||||
className="w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5"
|
||||
>
|
||||
<option value="WPA2">WPA2</option>
|
||||
<option value="WPA3">WPA3</option>
|
||||
<option value="WEP">WEP</option>
|
||||
<option value="None">None</option>
|
||||
</Field>
|
||||
</FormGroup>
|
||||
<button
|
||||
type="submit"
|
||||
className="w-full md:w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5"
|
||||
>
|
||||
{isSubmitting || wifiMutation.isPending ? "Saving..." : " Save WiFi settings"}
|
||||
</button>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
{isSubmitting || wifiMutation.isPending ? "Saving..." : " Save WiFi settings"}
|
||||
</button>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
<Toaster />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user