2025-08-15 09:32:33 +01:00
|
|
|
import { Formik, Field, Form } from "formik";
|
|
|
|
|
import type {
|
|
|
|
|
CameraSettingErrorValues,
|
|
|
|
|
CameraSettingValues,
|
|
|
|
|
} from "../../types/types";
|
|
|
|
|
|
2025-09-12 08:21:52 +01:00
|
|
|
const CameraSettingFields = ({ initialData, updateCameraConfig }) => {
|
2025-08-18 12:53:30 +01:00
|
|
|
const initialValues: CameraSettingValues = {
|
2025-09-12 08:21:52 +01:00
|
|
|
friendlyName: initialData?.propLEDDriverControlURI?.value,
|
2025-08-15 09:32:33 +01:00
|
|
|
cameraAddress: "",
|
|
|
|
|
userName: "",
|
|
|
|
|
password: "",
|
2025-09-12 08:21:52 +01:00
|
|
|
id: initialData?.id,
|
2025-08-15 09:32:33 +01:00
|
|
|
};
|
2025-08-18 12:53:30 +01:00
|
|
|
|
2025-08-15 09:32:33 +01:00
|
|
|
const validateValues = (values: CameraSettingValues) => {
|
|
|
|
|
const errors: CameraSettingErrorValues = {};
|
|
|
|
|
if (!values.friendlyName) errors.friendlyName = "Required";
|
|
|
|
|
if (!values.cameraAddress) errors.cameraAddress = "Required";
|
|
|
|
|
if (!values.userName) errors.userName = "Required";
|
|
|
|
|
if (!values.password) errors.password = "Required";
|
2025-09-10 09:05:47 +01:00
|
|
|
|
2025-08-15 09:32:33 +01:00
|
|
|
return errors;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSubmit = (values: CameraSettingValues) => {
|
2025-09-12 08:21:52 +01:00
|
|
|
updateCameraConfig(values);
|
2025-09-12 13:28:14 +01:00
|
|
|
return;
|
2025-08-15 09:32:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Formik
|
|
|
|
|
initialValues={initialValues}
|
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
|
validate={validateValues}
|
|
|
|
|
validateOnChange={false}
|
|
|
|
|
>
|
2025-09-10 09:05:47 +01:00
|
|
|
{({ errors, touched }) => (
|
2025-08-18 12:53:30 +01:00
|
|
|
<Form className="flex flex-col space-y-4 p-2">
|
|
|
|
|
<div className="flex flex-col space-y-2 relative">
|
2025-09-10 09:05:47 +01:00
|
|
|
<label htmlFor="friendlyName">Name</label>
|
2025-08-18 12:53:30 +01:00
|
|
|
{touched.friendlyName && errors.friendlyName && (
|
|
|
|
|
<small className="absolute right-0 top-0 text-red-500">
|
|
|
|
|
{errors.friendlyName}
|
|
|
|
|
</small>
|
|
|
|
|
)}
|
|
|
|
|
<Field
|
|
|
|
|
id="friendlyName"
|
|
|
|
|
name="friendlyName"
|
|
|
|
|
type="text"
|
|
|
|
|
className="p-2 border border-gray-400 rounded-lg"
|
|
|
|
|
placeholder="Enter camera name"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-08-15 09:32:33 +01:00
|
|
|
|
2025-08-18 12:53:30 +01:00
|
|
|
<div className="flex flex-col space-y-2 relative">
|
|
|
|
|
<label htmlFor="cameraAddress">Camera Address</label>
|
|
|
|
|
{touched.cameraAddress && errors.cameraAddress && (
|
|
|
|
|
<small className="absolute right-0 top-0 text-red-500">
|
|
|
|
|
{errors.cameraAddress}
|
|
|
|
|
</small>
|
|
|
|
|
)}
|
|
|
|
|
<Field
|
|
|
|
|
id="cameraAddress"
|
|
|
|
|
name="cameraAddress"
|
|
|
|
|
type="text"
|
|
|
|
|
className="p-2 border border-gray-400 rounded-lg"
|
2025-09-10 09:05:47 +01:00
|
|
|
placeholder="RTSP://..."
|
2025-08-18 12:53:30 +01:00
|
|
|
autoComplete="street-address"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col space-y-2 relative">
|
|
|
|
|
<label htmlFor="userName">User Name</label>
|
|
|
|
|
{touched.userName && errors.userName && (
|
|
|
|
|
<small className="absolute right-0 top-0 text-red-500">
|
|
|
|
|
{errors.userName}
|
|
|
|
|
</small>
|
|
|
|
|
)}
|
|
|
|
|
<Field
|
|
|
|
|
id="userName"
|
|
|
|
|
name="userName"
|
|
|
|
|
type="text"
|
|
|
|
|
className="p-2 border border-gray-400 rounded-lg"
|
|
|
|
|
placeholder="Enter user name"
|
|
|
|
|
autoComplete="username"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col space-y-2 relative">
|
|
|
|
|
<label htmlFor="password">Password</label>
|
|
|
|
|
{touched.password && errors.password && (
|
|
|
|
|
<small className="absolute right-0 top-0 text-red-500">
|
|
|
|
|
{errors.password}
|
|
|
|
|
</small>
|
|
|
|
|
)}
|
|
|
|
|
<Field
|
|
|
|
|
id="password"
|
|
|
|
|
name="password"
|
|
|
|
|
type="password"
|
|
|
|
|
className="p-2 border border-gray-400 rounded-lg"
|
|
|
|
|
placeholder="Enter password"
|
|
|
|
|
autoComplete="new-password"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
type="submit"
|
|
|
|
|
className="bg-blue-800 text-white rounded-lg p-2 mx-auto"
|
|
|
|
|
>
|
|
|
|
|
Save settings
|
|
|
|
|
</button>
|
|
|
|
|
</Form>
|
|
|
|
|
)}
|
2025-08-15 09:32:33 +01:00
|
|
|
</Formik>
|
|
|
|
|
);
|
2025-08-13 14:23:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default CameraSettingFields;
|