Compare commits
22 Commits
bugfix/Mat
...
bugfix/NPE
| Author | SHA1 | Date | |
|---|---|---|---|
| dd1cd342c1 | |||
| 0a1ac97c57 | |||
| 3ceca96276 | |||
| e7b741af78 | |||
| ed271964d8 | |||
| 9b996430d0 | |||
| 2ccc26ebdc | |||
| 3d1cc09a5b | |||
| f571ab80a2 | |||
| b2335d2d4d | |||
| a873da8ef5 | |||
| 5014c97b4d | |||
| e374456588 | |||
| ee3e111e9b | |||
| a8178269c2 | |||
| c057ce5084 | |||
| 0c7d99f7ea | |||
| f2e10f958d | |||
| 903b856303 | |||
| 672ff1d2f1 | |||
| 08a07b7ffb | |||
| d60c546db1 |
163
README.md
163
README.md
@@ -1,69 +1,116 @@
|
||||
# React + TypeScript + Vite
|
||||
# Mav Mobile UI
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
This is a React-based web application built with Vite (react and typescript).
|
||||
|
||||
Currently, two official plugins are available:
|
||||
## Getting started
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
### Prerequisites
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
- Node.js (v18 or higher recommended)
|
||||
- Yarn (v1.22+) (https://yarnpkg.com/)
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
### Installation
|
||||
|
||||
```js
|
||||
export default tseslint.config([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
...tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
...tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
...tseslint.configs.stylisticTypeChecked,
|
||||
|
||||
// Other configs...
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```bash
|
||||
git clone https://mavportal.com/TobaOjo/Mav-Mobile-UI.git
|
||||
cd Mav-Mobile-UI
|
||||
yarn install
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
### Running Locally
|
||||
|
||||
```bash
|
||||
yarn dev
|
||||
```
|
||||
|
||||
The app will be available at `http://localhost:5173`.
|
||||
|
||||
To run on locally on other devices
|
||||
|
||||
```bash
|
||||
yarn dev --host
|
||||
```
|
||||
|
||||
The app will be available at the exposed addresses to access e.g. http://1xx.xxx.x.xxx:<PORT>/Mobile
|
||||
|
||||
## Tech Stack
|
||||
|
||||
- **React** – UI library
|
||||
- **Vite** – Build tool
|
||||
- **Yarn** – Package manager
|
||||
|
||||
## Configuration
|
||||
|
||||
Create a `.env` file to access the Mav Mobile box in unit 5 for or for any environment-specific settings:
|
||||
|
||||
```env
|
||||
VITE_AGX_BOX_URL=http://1xx.xxx.xxx.xxx:<PORT>
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
### Linting & Formatting
|
||||
|
||||
```bash
|
||||
yarn lint
|
||||
yarn format
|
||||
```
|
||||
|
||||
### Testing
|
||||
|
||||
(Currently not implemented – consider adding Jest or Vitest)
|
||||
|
||||
## Deployment
|
||||
|
||||
To build for production:
|
||||
Navigate to the Mav-Mobile-UI folder
|
||||
|
||||
```bash
|
||||
cd Mav-Mobile-UI
|
||||
```
|
||||
|
||||
**Delete** the local .env (Production will use its own domain)
|
||||
|
||||
run
|
||||
|
||||
```bash
|
||||
yarn build
|
||||
```
|
||||
|
||||
- Navigate to your Mav-Mobile-UI folder
|
||||
- Select the Dist folder
|
||||
- Compress to (ZIP)
|
||||
- Log into box on Moba using Session > SSH and putting IP in Remote Host.
|
||||
- Creds are mav:mav
|
||||
- Drag and drop dist.zip into file explorer menu on left hand side (has to be named dist.zip exactly).
|
||||
- Run command
|
||||
|
||||
```bash
|
||||
sudo ./integrate-web-ui.sh
|
||||
```
|
||||
|
||||
Run
|
||||
|
||||
```bash
|
||||
sudo nano web-static/index.html
|
||||
```
|
||||
|
||||
- add the following between the lines </body> & </html>
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default tseslint.config([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
<foot>
|
||||
<script>
|
||||
if (window.location.pathname !== "/Mobile") {
|
||||
window.location.replace(window.location.origin + "/Mobile");
|
||||
}
|
||||
</script>
|
||||
</foot>
|
||||
```
|
||||
|
||||
- Run
|
||||
|
||||
```bash
|
||||
sudo reboot
|
||||
```
|
||||
|
||||
It should come back up all working
|
||||
|
||||
65
src/components/PopupSettings/NPEDCategoryPopup.tsx
Normal file
65
src/components/PopupSettings/NPEDCategoryPopup.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
import Card from "../UI/Card";
|
||||
import CardHeader from "../UI/CardHeader";
|
||||
import NPEDCatToggle from "../SettingForms/NPED/NPEDCatToggle";
|
||||
import FormGroup from "../SettingForms/components/FormGroup";
|
||||
import { Form, Formik } from "formik";
|
||||
import { useIntegrationsContext } from "../../context/IntegrationsContext";
|
||||
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
||||
import type { CategoryPopups } from "../../types/types";
|
||||
|
||||
const NPEDCategoryPopup = () => {
|
||||
const { state, dispatch } = useIntegrationsContext();
|
||||
const { mutation } = useCameraBlackboard();
|
||||
|
||||
const isCatAEnabled = state?.iscatEnabled?.catA;
|
||||
const isCatBEnabled = state?.iscatEnabled?.catB;
|
||||
const isCatCEnabled = state?.iscatEnabled?.catC;
|
||||
const isCatDEnabled = state?.iscatEnabled?.catD;
|
||||
|
||||
const initialValues = {
|
||||
catA: isCatAEnabled ?? true,
|
||||
catB: isCatBEnabled ?? true,
|
||||
catC: isCatCEnabled ?? true,
|
||||
catD: isCatDEnabled ?? false,
|
||||
};
|
||||
|
||||
const handleSubmit = async (values: CategoryPopups) => {
|
||||
await mutation.mutateAsync({
|
||||
operation: "INSERT",
|
||||
value: values,
|
||||
path: "CategoryPopup",
|
||||
});
|
||||
dispatch({ type: "NPEDCATENABLED", payload: values });
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<CardHeader title={"Alert Pop ups"} />
|
||||
<p className="italic my-2">Allows alerts to pop up to user.</p>
|
||||
<Formik initialValues={initialValues} onSubmit={handleSubmit}>
|
||||
<Form className="flex flex-col space-y-5 px-2">
|
||||
<FormGroup>
|
||||
<NPEDCatToggle name={"catA"} label="NPED Category A" />
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<NPEDCatToggle name={"catB"} label="NPED Category B" />
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<NPEDCatToggle name={"catC"} label="NPED Category C" />
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<NPEDCatToggle name={"catD"} label="NPED Category D" />
|
||||
</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"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
</Form>
|
||||
</Formik>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default NPEDCategoryPopup;
|
||||
22
src/components/SettingForms/NPED/NPEDCatToggle.tsx
Normal file
22
src/components/SettingForms/NPED/NPEDCatToggle.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Field } from "formik";
|
||||
|
||||
type NPEDToggleProps = {
|
||||
name: string;
|
||||
label: string;
|
||||
};
|
||||
|
||||
const NPEDCatToggle = ({ name, label }: NPEDToggleProps) => {
|
||||
return (
|
||||
<label className="flex items-center gap-3 cursor-pointer select-none w-full justify-between">
|
||||
<span className="text-lg">{label}</span>
|
||||
<Field id={name} type="checkbox" name={name} className="sr-only peer" />
|
||||
<div
|
||||
className="relative w-10 h-5 rounded-full bg-gray-300 transition peer-checked:bg-blue-500 after:content-['']
|
||||
after:absolute after:top-0.5 after:left-0.5 after:w-4 after:h-4 after:rounded-full after:bg-white after:shadow after:transition
|
||||
after:duration-300 peer-checked:after:translate-x-5"
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
};
|
||||
|
||||
export default NPEDCatToggle;
|
||||
@@ -13,20 +13,18 @@ const NPEDFields = () => {
|
||||
const [showPwd, setShowPwd] = useState(false);
|
||||
const { signIn, signOut } = useNPEDAuth();
|
||||
|
||||
const initialValues = state.npedUser
|
||||
? {
|
||||
username: state.npedUser?.propUsername?.value,
|
||||
password: state.npedUser?.propPassword?.value,
|
||||
clientId: state.npedUser?.propClientID?.value,
|
||||
frontId: "NPED",
|
||||
rearId: "NPED",
|
||||
}
|
||||
: {
|
||||
username: "",
|
||||
password: "",
|
||||
clientId: "",
|
||||
frontId: "NPED",
|
||||
rearId: "NPED",
|
||||
const username = state.npedUser?.propUsername?.value;
|
||||
const password = state.npedUser?.propPassword?.value;
|
||||
const clientId = state.npedUser?.propClientID?.value;
|
||||
const frontId = "NPED";
|
||||
const rearId = "NPED";
|
||||
|
||||
const initialValues = {
|
||||
username: username ?? "",
|
||||
password: password ?? "",
|
||||
clientId: clientId ?? "",
|
||||
frontId: frontId,
|
||||
rearId: rearId,
|
||||
};
|
||||
|
||||
const handleSubmit = async (values: NPEDFieldType) => {
|
||||
@@ -100,6 +98,7 @@ const NPEDFields = () => {
|
||||
className="p-1.5 border border-gray-400 rounded-lg"
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
{!state.npedUser?.propClientID?.value ? (
|
||||
<button
|
||||
type="submit"
|
||||
|
||||
@@ -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,6 +45,7 @@ const WiFiSettingsForm = () => {
|
||||
await wifiMutation.mutateAsync(wifiConfig);
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<Formik initialValues={initialValues} onSubmit={handleSubmit} enableReinitialize>
|
||||
{({ isSubmitting }) => (
|
||||
<Form className="flex flex-col space-y-5 px-2">
|
||||
@@ -63,7 +72,9 @@ const WiFiSettingsForm = () => {
|
||||
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"
|
||||
@@ -97,6 +108,8 @@ const WiFiSettingsForm = () => {
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
<Toaster />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ type SightingModalProps = {
|
||||
|
||||
const SightingModal = ({ isSightingModalOpen, handleClose, sighting, onDelete }: SightingModalProps) => {
|
||||
const { dispatch } = useAlertHitContext();
|
||||
|
||||
const { query, mutation } = useCameraBlackboard();
|
||||
|
||||
const hotlistNames = getHotlistName(sighting?.metadata?.hotlistMatches);
|
||||
@@ -160,23 +161,24 @@ const SightingModal = ({ isSightingModalOpen, handleClose, sighting, onDelete }:
|
||||
<dd className="font-medium text-2xl">{sighting?.seenCount ?? "-"}</dd>
|
||||
</div>
|
||||
|
||||
{sighting?.make && (
|
||||
{sighting?.make && sighting.make.trim() && sighting.make.toLowerCase() !== "disabled" && (
|
||||
<div>
|
||||
<dt className="text-gray-300">Make</dt>
|
||||
<dd className="font-medium text-2xl">{sighting?.make ?? "-"}</dd>
|
||||
<dd className="font-medium text-2xl">{sighting.make}</dd>
|
||||
</div>
|
||||
)}
|
||||
{sighting?.model ||
|
||||
(!sighting?.model.trim() && (
|
||||
|
||||
{sighting?.model && sighting.model.trim() && sighting.model.toLowerCase() !== "disabled" && (
|
||||
<div>
|
||||
<dt className="text-gray-300">Model</dt>
|
||||
<dd className="font-medium text-2xl">{sighting?.model ?? "-"}</dd>
|
||||
<dd className="font-medium text-2xl">{sighting.model}</dd>
|
||||
</div>
|
||||
))}
|
||||
{sighting?.color && (
|
||||
)}
|
||||
|
||||
{sighting?.color && sighting.color.trim() && sighting.color.toLowerCase() !== "disabled" && (
|
||||
<div className="sm:col-span-2">
|
||||
<dt className="text-gray-300">Colour</dt>
|
||||
<dd className="font-medium text-2xl">{sighting?.color ?? "-"}</dd>
|
||||
<dd className="font-medium text-2xl">{sighting.color}</dd>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -68,6 +68,11 @@ export default function SightingHistoryWidget({ className, title }: SightingHist
|
||||
const hasAutoOpenedRef = useRef(false);
|
||||
const npedRef = useRef(false);
|
||||
|
||||
const isCatAEnabled = integrationState?.iscatEnabled?.catA;
|
||||
const isCatBEnabled = integrationState?.iscatEnabled?.catB;
|
||||
const isCatCEnabled = integrationState?.iscatEnabled?.catC;
|
||||
const isCatDEnabled = integrationState?.iscatEnabled?.catD;
|
||||
|
||||
const enqueue = useCallback((sighting: SightingType, kind: HitKind) => {
|
||||
const id = sighting.vrm ?? sighting.ref;
|
||||
if (processedRefs.current.has(id)) return;
|
||||
@@ -118,7 +123,11 @@ export default function SightingHistoryWidget({ className, title }: SightingHist
|
||||
if (processedRefs.current.has(id)) continue;
|
||||
const isHotlistHit = checkIsHotListHit(sighting);
|
||||
const npedcategory = sighting?.metadata?.npedJSON?.["NPED CATEGORY"];
|
||||
const isNPED = npedcategory === "A" || npedcategory === "B" || npedcategory === "C";
|
||||
const isNPED =
|
||||
(npedcategory === "A" && isCatAEnabled) ||
|
||||
(npedcategory === "B" && isCatBEnabled) ||
|
||||
(npedcategory === "C" && isCatCEnabled) ||
|
||||
(npedcategory === "D" && isCatDEnabled);
|
||||
|
||||
if (isNPED || isHotlistHit) {
|
||||
enqueue(sighting, isNPED ? "NPED" : "HOTLIST"); // enqueue ONLY
|
||||
@@ -148,7 +157,8 @@ export default function SightingHistoryWidget({ className, title }: SightingHist
|
||||
const isNPEDHitA = cat === "A";
|
||||
const isNPEDHitB = cat === "B";
|
||||
const isNPEDHitC = cat === "C";
|
||||
return isNPEDHitA || isNPEDHitB || isNPEDHitC;
|
||||
const isNPEDHitD = cat === "D";
|
||||
return isNPEDHitA || isNPEDHitB || isNPEDHitC || isNPEDHitD;
|
||||
});
|
||||
const firstHot = rows?.find((r) => {
|
||||
const isHotListHit = checkIsHotListHit(r);
|
||||
|
||||
@@ -12,17 +12,39 @@ export const IntegrationsProvider = ({ children }: IntegrationsProviderType) =>
|
||||
const { mutation } = useCameraBlackboard();
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const result = await mutation.mutateAsync({
|
||||
operation: "VIEW",
|
||||
path: "sessionStats",
|
||||
});
|
||||
if (!result.result || typeof result.result === "string") return;
|
||||
|
||||
dispatch({ type: "UPDATE", payload: result?.result });
|
||||
if (!isMounted) return;
|
||||
|
||||
const catResult = await mutation.mutateAsync({
|
||||
operation: "VIEW",
|
||||
path: "CategoryPopup",
|
||||
});
|
||||
|
||||
if (!isMounted) return;
|
||||
if (!result?.result || typeof result.result === "string") return;
|
||||
|
||||
dispatch({ type: "UPDATE", payload: result.result });
|
||||
dispatch({ type: "NPEDCATENABLED", payload: catResult.result });
|
||||
} catch (error) {
|
||||
console.error("Error in fetchData:", error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchData();
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<IntegrationsContext.Provider
|
||||
value={{
|
||||
|
||||
@@ -6,6 +6,12 @@ export const initialState = {
|
||||
sessionPaused: false,
|
||||
savedSightings: [],
|
||||
npedUser: null,
|
||||
iscatEnabled: {
|
||||
catA: true,
|
||||
catB: true,
|
||||
catC: true,
|
||||
catD: false,
|
||||
},
|
||||
};
|
||||
|
||||
export function reducer(state: NPEDSTATE, action: NPEDACTION) {
|
||||
@@ -40,6 +46,11 @@ export function reducer(state: NPEDSTATE, action: NPEDACTION) {
|
||||
...state,
|
||||
sessionList: action.payload,
|
||||
};
|
||||
case "NPEDCATENABLED":
|
||||
return {
|
||||
...state,
|
||||
iscatEnabled: action.payload,
|
||||
};
|
||||
default:
|
||||
return { ...state };
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ const getCameraMode = async (options: { camera: string }) => {
|
||||
};
|
||||
|
||||
const updateCameraMode = async (options: { camera: string; mode: string }) => {
|
||||
console.log(options);
|
||||
const dayNightPayload = {
|
||||
id: options.camera,
|
||||
fields: [
|
||||
|
||||
@@ -10,6 +10,7 @@ import { Toaster } from "sonner";
|
||||
import { useNPEDAuth } from "../hooks/useNPEDAuth";
|
||||
import SoundSettingsCard from "../components/SettingForms/Sound/SoundSettingsCard";
|
||||
import SoundUploadCard from "../components/SettingForms/Sound/SoundUploadCard";
|
||||
import NPEDCategoryPopup from "../components/PopupSettings/NPEDCategoryPopup";
|
||||
|
||||
const SystemSettings = () => {
|
||||
useNPEDAuth();
|
||||
@@ -38,6 +39,7 @@ const SystemSettings = () => {
|
||||
<div className="mx-auto grid grid-cols-1 sm:grid-cols-1 lg:grid-cols-2 gap-2 px-2 sm:px-4 lg:px-0 w-full">
|
||||
<NPEDCard />
|
||||
<NPEDHotlistCard />
|
||||
<NPEDCategoryPopup />
|
||||
</div>
|
||||
</TabPanel>
|
||||
<TabPanel>
|
||||
|
||||
@@ -403,6 +403,8 @@ export type ModemSettingsType = {
|
||||
username: string;
|
||||
password: string;
|
||||
authenticationType: string;
|
||||
serverPrimary: string;
|
||||
serverSecondary: string;
|
||||
};
|
||||
|
||||
export type HitKind = "NPED" | "HOTLIST";
|
||||
@@ -421,6 +423,7 @@ export type NPEDSTATE = {
|
||||
sessionPaused: boolean;
|
||||
savedSightings: DedupedSightings;
|
||||
npedUser: NPEDUser;
|
||||
iscatEnabled: CategoryPopups;
|
||||
};
|
||||
|
||||
export type NPEDACTION = {
|
||||
@@ -428,3 +431,10 @@ export type NPEDACTION = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
payload: any;
|
||||
};
|
||||
|
||||
export type CategoryPopups = {
|
||||
catA: boolean;
|
||||
catB: boolean;
|
||||
catC: boolean;
|
||||
catD: boolean;
|
||||
};
|
||||
|
||||
@@ -184,3 +184,14 @@ export const reverseZoomMapping = (magnification: string) => {
|
||||
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