21 Commits

Author SHA1 Message Date
0a1ac97c57 - removed console.log 2025-11-14 11:55:01 +00:00
3ceca96276 Merge branch 'main' into develop 2025-11-12 09:50:09 +00:00
e7b741af78 Merge pull request 'updated and improved ip address validation' (#8) from bugfix/ipaddress into develop
Reviewed-on: #8
2025-11-12 09:49:03 +00:00
ed271964d8 updated and improved ip address validation 2025-11-12 09:46:59 +00:00
9b996430d0 Merge pull request '- added additional modem settings and ip validation' (#6) from bugfix/modem into develop
Reviewed-on: #6
2025-11-11 16:24:02 +00:00
2ccc26ebdc - added additional modem settings and ip validation 2025-11-11 16:22:30 +00:00
3d1cc09a5b Merge pull request '- removed dist and updated readme' (#5) from develop into main
Reviewed-on: #5
2025-11-11 14:27:59 +00:00
f571ab80a2 Merge branch 'main' into develop 2025-11-11 14:27:50 +00:00
b2335d2d4d - removed dist and updated readme 2025-11-11 14:26:52 +00:00
a873da8ef5 Merge pull request 'develop' (#4) from develop into main
Reviewed-on: #4
2025-11-11 13:58:46 +00:00
5014c97b4d updated readme 2025-11-11 13:57:05 +00:00
e374456588 updated readme 2025-11-11 13:52:58 +00:00
ee3e111e9b Merge pull request 'Update README.md' (#3) from tobaojo-patch-1 into develop
Reviewed-on: #3
2025-11-11 13:50:02 +00:00
a8178269c2 Update README.md 2025-11-11 13:49:46 +00:00
c057ce5084 Merge pull request 'develop' (#2) from develop into main
Reviewed-on: #2
2025-11-11 12:52:29 +00:00
0c7d99f7ea minor bugfix: removed csv check for update files 2025-11-11 12:50:48 +00:00
f2e10f958d Merge pull request 'added wifi validation' (#1) from bugfix/wifi into develop
Reviewed-on: #1
2025-11-11 12:40:15 +00:00
903b856303 added wifi validation 2025-11-11 12:37:28 +00:00
672ff1d2f1 Merged main into develop 2025-11-11 10:49:06 +00:00
08a07b7ffb Merged in develop (pull request #38)
Develop
2025-11-11 10:46:53 +00:00
d60c546db1 Merged in bugfix/Matttesting (pull request #37)
Bugfix/Matttesting
2025-11-11 10:45:25 +00:00
10 changed files with 269 additions and 135 deletions

163
README.md
View File

@@ -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 ### Prerequisites
- [@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
## 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 ```bash
export default tseslint.config([ git clone https://mavportal.com/TobaOjo/Mav-Mobile-UI.git
globalIgnores(['dist']), cd Mav-Mobile-UI
{ yarn install
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...
},
},
])
``` ```
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 ```js
// eslint.config.js <foot>
import reactX from 'eslint-plugin-react-x' <script>
import reactDom from 'eslint-plugin-react-dom' if (window.location.pathname !== "/Mobile") {
window.location.replace(window.location.origin + "/Mobile");
export default tseslint.config([ }
globalIgnores(['dist']), </script>
{ </foot>
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...
},
},
])
``` ```
- Run
```bash
sudo reboot
```
It should come back up all working

View File

@@ -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 }) => (

View File

@@ -14,9 +14,6 @@ export async function sendBlobFileUpload({ file, opts }: BlobFileUpload): Promis
if (!file) throw new Error("No file supplied"); if (!file) throw new Error("No file supplied");
if (!opts?.uploadUrl) throw new Error("No URL 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 timeoutMs = opts?.timeoutMs ?? 30000;
const fieldName = opts?.fieldName ?? "upload"; const fieldName = opts?.fieldName ?? "upload";
const fileName = opts?.overrideFileName ?? file?.name; const fileName = opts?.overrideFileName ?? file?.name;

View File

@@ -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>
); );

View File

@@ -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 />
</> </>
); );
}; };

View File

@@ -5,6 +5,7 @@ import { useWifiAndModem } from "../../../hooks/useCameraWifiandModem";
import { useState } from "react"; import { useState } from "react";
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 { toast, Toaster } from "sonner";
const WiFiSettingsForm = () => { const WiFiSettingsForm = () => {
const [showPwd, setShowPwd] = useState(false); const [showPwd, setShowPwd] = useState(false);
@@ -19,6 +20,13 @@ const WiFiSettingsForm = () => {
encryption: "WPA2", 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 handleSubmit = async (values: WifiSettingValues) => {
const wifiConfig = { const wifiConfig = {
id: "ModemAndWifiManager-wifi", id: "ModemAndWifiManager-wifi",
@@ -37,66 +45,71 @@ const WiFiSettingsForm = () => {
await wifiMutation.mutateAsync(wifiConfig); await wifiMutation.mutateAsync(wifiConfig);
}; };
return ( return (
<Formik initialValues={initialValues} onSubmit={handleSubmit} enableReinitialize> <>
{({ isSubmitting }) => ( <Formik initialValues={initialValues} onSubmit={handleSubmit} enableReinitialize>
<Form className="flex flex-col space-y-5 px-2"> {({ isSubmitting }) => (
<FormGroup> <Form className="flex flex-col space-y-5 px-2">
<label htmlFor="ssid" className="font-medium whitespace-nowrap md:w-2/3"> <FormGroup>
SSID <label htmlFor="ssid" className="font-medium whitespace-nowrap md:w-2/3">
</label> SSID
<Field </label>
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">
<Field <Field
id="password" id="ssid"
name="password" name="ssid"
type={showPwd ? "text" : "password"} type="text"
className="p-2 border border-gray-400 rounded-lg w-full" className="p-1.5 border border-gray-400 rounded-lg"
placeholder="Enter Password" placeholder="Enter SSID"
/> />
<FontAwesomeIcon </FormGroup>
type="button" <FormGroup>
className="absolute right-5 end-0" <label htmlFor="password" className="font-medium whitespace-nowrap md:w-2/3">
onClick={() => setShowPwd((s) => !s)} Password
icon={showPwd ? faEyeSlash : faEye} </label>
/> <div className="flex gap-2 items-center relative mb-4">
</div> <Field
</FormGroup> id="password"
<FormGroup> name="password"
<label htmlFor="encryption" className="font-medium whitespace-nowrap md:w-2/3"> type={showPwd ? "text" : "password"}
WPA/Encryption Type className="p-2 border border-gray-400 rounded-lg w-full"
</label> placeholder="Enter Password"
<Field validate={validatePassword}
id="encryption" />
name="encryption"
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] flex-1 w-2/3" <FontAwesomeIcon
as="select" 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> {isSubmitting || wifiMutation.isPending ? "Saving..." : " Save WiFi settings"}
<option value="WPA3">WPA3</option> </button>
<option value="WEP">WEP</option> </Form>
<option value="None">None</option> )}
</Field> </Formik>
</FormGroup> <Toaster />
<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 || wifiMutation.isPending ? "Saving..." : " Save WiFi settings"}
</button>
</Form>
)}
</Formik>
); );
}; };

View File

@@ -160,12 +160,13 @@ const SightingModal = ({ isSightingModalOpen, handleClose, sighting, onDelete }:
<dd className="font-medium text-2xl">{sighting?.seenCount ?? "-"}</dd> <dd className="font-medium text-2xl">{sighting?.seenCount ?? "-"}</dd>
</div> </div>
{sighting?.make && ( {sighting?.make ||
<div> (sighting?.make.trim() && (
<dt className="text-gray-300">Make</dt> <div>
<dd className="font-medium text-2xl">{sighting?.make ?? "-"}</dd> <dt className="text-gray-300">Make</dt>
</div> <dd className="font-medium text-2xl">{sighting?.make ?? "-"}</dd>
)} </div>
))}
{sighting?.model || {sighting?.model ||
(!sighting?.model.trim() && ( (!sighting?.model.trim() && (
<div> <div>
@@ -173,12 +174,13 @@ const SightingModal = ({ isSightingModalOpen, handleClose, sighting, onDelete }:
<dd className="font-medium text-2xl">{sighting?.model ?? "-"}</dd> <dd className="font-medium text-2xl">{sighting?.model ?? "-"}</dd>
</div> </div>
))} ))}
{sighting?.color && ( {sighting?.color ||
<div className="sm:col-span-2"> (!sighting?.color.trim() && (
<dt className="text-gray-300">Colour</dt> <div className="sm:col-span-2">
<dd className="font-medium text-2xl">{sighting?.color ?? "-"}</dd> <dt className="text-gray-300">Colour</dt>
</div> <dd className="font-medium text-2xl">{sighting?.color ?? "-"}</dd>
)} </div>
))}
<div> <div>
<dt className="text-gray-300">Time</dt> <dt className="text-gray-300">Time</dt>

View File

@@ -11,7 +11,6 @@ const getCameraMode = async (options: { camera: string }) => {
}; };
const updateCameraMode = async (options: { camera: string; mode: string }) => { const updateCameraMode = async (options: { camera: string; mode: string }) => {
console.log(options);
const dayNightPayload = { const dayNightPayload = {
id: options.camera, id: options.camera,
fields: [ fields: [

View File

@@ -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";

View File

@@ -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";
}
};