2025-10-03 10:19:49 +01:00
|
|
|
import { Formik, Form, Field } from "formik";
|
|
|
|
|
import FormGroup from "../components/FormGroup";
|
|
|
|
|
import type { ModemSettingsType } from "../../../types/types";
|
|
|
|
|
import { useWifiAndModem } from "../../../hooks/useCameraWifiandModem";
|
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
import ModemToggle from "./ModemToggle";
|
2025-10-15 11:00:52 +01:00
|
|
|
import { faEyeSlash, faEye } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2025-10-03 10:19:49 +01:00
|
|
|
|
|
|
|
|
const ModemSettings = () => {
|
|
|
|
|
const [showSettings, setShowSettings] = useState(false);
|
2025-10-15 11:00:52 +01:00
|
|
|
const [showPwd, setShowPwd] = useState(false);
|
2025-10-03 10:19:49 +01:00
|
|
|
const { modemQuery, modemMutation } = useWifiAndModem();
|
|
|
|
|
|
|
|
|
|
const apn = modemQuery?.data?.propAPN?.value;
|
|
|
|
|
const username = modemQuery?.data?.propUsername.value;
|
|
|
|
|
const password = modemQuery?.data?.propPassword?.value;
|
|
|
|
|
const mode = modemQuery?.data?.propMode?.value;
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setShowSettings(mode === "AUTO");
|
|
|
|
|
}, [mode]);
|
|
|
|
|
|
|
|
|
|
const inititalValues = {
|
|
|
|
|
apn: apn ?? "",
|
|
|
|
|
username: username ?? "",
|
|
|
|
|
password: password ?? "",
|
|
|
|
|
authenticationType: "PAP",
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-06 15:18:58 +01:00
|
|
|
const handleSubmit = async (values: ModemSettingsType) => {
|
2025-10-03 10:19:49 +01:00
|
|
|
const modemConfig = {
|
|
|
|
|
id: "ModemAndWifiManager-modem",
|
|
|
|
|
fields: [
|
|
|
|
|
{
|
|
|
|
|
property: "propAPN",
|
|
|
|
|
value: values.apn,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
property: "propPassword",
|
|
|
|
|
value: values.password,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
property: "propUsername",
|
|
|
|
|
value: values.username,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
property: "propMode",
|
|
|
|
|
value: showSettings ? "AUTO" : "MANUAL",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
2025-10-06 15:18:58 +01:00
|
|
|
await modemMutation.mutateAsync(modemConfig);
|
2025-10-03 10:19:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2025-10-20 10:50:16 +01:00
|
|
|
<ModemToggle showSettings={showSettings} onShowSettings={setShowSettings} />
|
2025-11-04 16:09:24 +00:00
|
|
|
|
|
|
|
|
<Formik initialValues={inititalValues} onSubmit={handleSubmit} enableReinitialize>
|
|
|
|
|
{({ isSubmitting }) => (
|
|
|
|
|
<Form className="flex flex-col space-y-5 px-2">
|
|
|
|
|
{!showSettings && (
|
|
|
|
|
<>
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label htmlFor="apn" className="font-medium whitespace-nowrap md:w-2/3">
|
|
|
|
|
APN
|
|
|
|
|
</label>
|
2025-10-15 11:00:52 +01:00
|
|
|
<Field
|
2025-11-04 16:09:24 +00:00
|
|
|
placeholder="Enter APN"
|
|
|
|
|
name="apn"
|
|
|
|
|
id="apn"
|
|
|
|
|
type="text"
|
|
|
|
|
className="p-1.5 border border-gray-400 rounded-lg"
|
2025-10-15 11:00:52 +01:00
|
|
|
/>
|
2025-11-04 16:09:24 +00:00
|
|
|
</FormGroup>
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label htmlFor="username" className="font-medium whitespace-nowrap md:w-2/3">
|
|
|
|
|
Username
|
|
|
|
|
</label>
|
|
|
|
|
<Field
|
|
|
|
|
placeholder="Enter Username"
|
|
|
|
|
name="username"
|
|
|
|
|
id="username"
|
|
|
|
|
type="text"
|
|
|
|
|
className="p-1.5 border border-gray-400 rounded-lg"
|
2025-10-15 11:00:52 +01:00
|
|
|
/>
|
2025-11-04 16:09:24 +00:00
|
|
|
</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"
|
|
|
|
|
/>
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
type="button"
|
|
|
|
|
className="absolute right-5 end-0"
|
|
|
|
|
onClick={() => setShowPwd((s) => !s)}
|
|
|
|
|
icon={showPwd ? faEyeSlash : faEye}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label htmlFor="password" className="font-medium whitespace-nowrap md:w-2/3">
|
|
|
|
|
Password
|
|
|
|
|
</label>
|
|
|
|
|
<Field
|
|
|
|
|
name="authenticationType"
|
|
|
|
|
as="select"
|
|
|
|
|
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] flex-1 w-2/3"
|
|
|
|
|
>
|
|
|
|
|
<option value="PAP">PAP</option>
|
|
|
|
|
<option value="CHAP">CHAP</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"
|
|
|
|
|
>
|
|
|
|
|
{isSubmitting || modemMutation.isPending ? "Saving..." : "Save Modem settings"}
|
|
|
|
|
</button>
|
|
|
|
|
</Form>
|
|
|
|
|
)}
|
|
|
|
|
</Formik>
|
2025-10-03 10:19:49 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ModemSettings;
|