Compare commits
1 Commits
bugfix/NPE
...
96a880a4df
| Author | SHA1 | Date | |
|---|---|---|---|
| 96a880a4df |
@@ -1,65 +0,0 @@
|
|||||||
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;
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
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,18 +13,20 @@ const NPEDFields = () => {
|
|||||||
const [showPwd, setShowPwd] = useState(false);
|
const [showPwd, setShowPwd] = useState(false);
|
||||||
const { signIn, signOut } = useNPEDAuth();
|
const { signIn, signOut } = useNPEDAuth();
|
||||||
|
|
||||||
const username = state.npedUser?.propUsername?.value;
|
const initialValues = state.npedUser
|
||||||
const password = state.npedUser?.propPassword?.value;
|
? {
|
||||||
const clientId = state.npedUser?.propClientID?.value;
|
username: state.npedUser?.propUsername?.value,
|
||||||
const frontId = "NPED";
|
password: state.npedUser?.propPassword?.value,
|
||||||
const rearId = "NPED";
|
clientId: state.npedUser?.propClientID?.value,
|
||||||
|
frontId: "NPED",
|
||||||
const initialValues = {
|
rearId: "NPED",
|
||||||
username: username ?? "",
|
}
|
||||||
password: password ?? "",
|
: {
|
||||||
clientId: clientId ?? "",
|
username: "",
|
||||||
frontId: frontId,
|
password: "",
|
||||||
rearId: rearId,
|
clientId: "",
|
||||||
|
frontId: "NPED",
|
||||||
|
rearId: "NPED",
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (values: NPEDFieldType) => {
|
const handleSubmit = async (values: NPEDFieldType) => {
|
||||||
@@ -98,7 +100,6 @@ const NPEDFields = () => {
|
|||||||
className="p-1.5 border border-gray-400 rounded-lg"
|
className="p-1.5 border border-gray-400 rounded-lg"
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
||||||
{!state.npedUser?.propClientID?.value ? (
|
{!state.npedUser?.propClientID?.value ? (
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ type SightingModalProps = {
|
|||||||
|
|
||||||
const SightingModal = ({ isSightingModalOpen, handleClose, sighting, onDelete }: SightingModalProps) => {
|
const SightingModal = ({ isSightingModalOpen, handleClose, sighting, onDelete }: SightingModalProps) => {
|
||||||
const { dispatch } = useAlertHitContext();
|
const { dispatch } = useAlertHitContext();
|
||||||
|
|
||||||
const { query, mutation } = useCameraBlackboard();
|
const { query, mutation } = useCameraBlackboard();
|
||||||
|
|
||||||
const hotlistNames = getHotlistName(sighting?.metadata?.hotlistMatches);
|
const hotlistNames = getHotlistName(sighting?.metadata?.hotlistMatches);
|
||||||
@@ -161,26 +160,27 @@ 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.trim() && sighting.make.toLowerCase() !== "disabled" && (
|
{sighting?.make ||
|
||||||
|
(sighting?.make.trim() && (
|
||||||
<div>
|
<div>
|
||||||
<dt className="text-gray-300">Make</dt>
|
<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>
|
</div>
|
||||||
)}
|
))}
|
||||||
|
{sighting?.model ||
|
||||||
{sighting?.model && sighting.model.trim() && sighting.model.toLowerCase() !== "disabled" && (
|
(!sighting?.model.trim() && (
|
||||||
<div>
|
<div>
|
||||||
<dt className="text-gray-300">Model</dt>
|
<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>
|
</div>
|
||||||
)}
|
))}
|
||||||
|
{sighting?.color ||
|
||||||
{sighting?.color && sighting.color.trim() && sighting.color.toLowerCase() !== "disabled" && (
|
(!sighting?.color.trim() && (
|
||||||
<div className="sm:col-span-2">
|
<div className="sm:col-span-2">
|
||||||
<dt className="text-gray-300">Colour</dt>
|
<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>
|
</div>
|
||||||
)}
|
))}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<dt className="text-gray-300">Time</dt>
|
<dt className="text-gray-300">Time</dt>
|
||||||
|
|||||||
@@ -68,11 +68,6 @@ export default function SightingHistoryWidget({ className, title }: SightingHist
|
|||||||
const hasAutoOpenedRef = useRef(false);
|
const hasAutoOpenedRef = useRef(false);
|
||||||
const npedRef = 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 enqueue = useCallback((sighting: SightingType, kind: HitKind) => {
|
||||||
const id = sighting.vrm ?? sighting.ref;
|
const id = sighting.vrm ?? sighting.ref;
|
||||||
if (processedRefs.current.has(id)) return;
|
if (processedRefs.current.has(id)) return;
|
||||||
@@ -123,11 +118,7 @@ export default function SightingHistoryWidget({ className, title }: SightingHist
|
|||||||
if (processedRefs.current.has(id)) continue;
|
if (processedRefs.current.has(id)) continue;
|
||||||
const isHotlistHit = checkIsHotListHit(sighting);
|
const isHotlistHit = checkIsHotListHit(sighting);
|
||||||
const npedcategory = sighting?.metadata?.npedJSON?.["NPED CATEGORY"];
|
const npedcategory = sighting?.metadata?.npedJSON?.["NPED CATEGORY"];
|
||||||
const isNPED =
|
const isNPED = npedcategory === "A" || npedcategory === "B" || npedcategory === "C";
|
||||||
(npedcategory === "A" && isCatAEnabled) ||
|
|
||||||
(npedcategory === "B" && isCatBEnabled) ||
|
|
||||||
(npedcategory === "C" && isCatCEnabled) ||
|
|
||||||
(npedcategory === "D" && isCatDEnabled);
|
|
||||||
|
|
||||||
if (isNPED || isHotlistHit) {
|
if (isNPED || isHotlistHit) {
|
||||||
enqueue(sighting, isNPED ? "NPED" : "HOTLIST"); // enqueue ONLY
|
enqueue(sighting, isNPED ? "NPED" : "HOTLIST"); // enqueue ONLY
|
||||||
@@ -157,8 +148,7 @@ export default function SightingHistoryWidget({ className, title }: SightingHist
|
|||||||
const isNPEDHitA = cat === "A";
|
const isNPEDHitA = cat === "A";
|
||||||
const isNPEDHitB = cat === "B";
|
const isNPEDHitB = cat === "B";
|
||||||
const isNPEDHitC = cat === "C";
|
const isNPEDHitC = cat === "C";
|
||||||
const isNPEDHitD = cat === "D";
|
return isNPEDHitA || isNPEDHitB || isNPEDHitC;
|
||||||
return isNPEDHitA || isNPEDHitB || isNPEDHitC || isNPEDHitD;
|
|
||||||
});
|
});
|
||||||
const firstHot = rows?.find((r) => {
|
const firstHot = rows?.find((r) => {
|
||||||
const isHotListHit = checkIsHotListHit(r);
|
const isHotListHit = checkIsHotListHit(r);
|
||||||
|
|||||||
@@ -12,39 +12,17 @@ export const IntegrationsProvider = ({ children }: IntegrationsProviderType) =>
|
|||||||
const { mutation } = useCameraBlackboard();
|
const { mutation } = useCameraBlackboard();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let isMounted = true;
|
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
|
||||||
const result = await mutation.mutateAsync({
|
const result = await mutation.mutateAsync({
|
||||||
operation: "VIEW",
|
operation: "VIEW",
|
||||||
path: "sessionStats",
|
path: "sessionStats",
|
||||||
});
|
});
|
||||||
|
if (!result.result || typeof result.result === "string") return;
|
||||||
|
|
||||||
if (!isMounted) return;
|
dispatch({ type: "UPDATE", payload: result?.result });
|
||||||
|
|
||||||
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();
|
fetchData();
|
||||||
|
|
||||||
return () => {
|
|
||||||
isMounted = false;
|
|
||||||
};
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IntegrationsContext.Provider
|
<IntegrationsContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
|||||||
@@ -6,12 +6,6 @@ export const initialState = {
|
|||||||
sessionPaused: false,
|
sessionPaused: false,
|
||||||
savedSightings: [],
|
savedSightings: [],
|
||||||
npedUser: null,
|
npedUser: null,
|
||||||
iscatEnabled: {
|
|
||||||
catA: true,
|
|
||||||
catB: true,
|
|
||||||
catC: true,
|
|
||||||
catD: false,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function reducer(state: NPEDSTATE, action: NPEDACTION) {
|
export function reducer(state: NPEDSTATE, action: NPEDACTION) {
|
||||||
@@ -46,11 +40,6 @@ export function reducer(state: NPEDSTATE, action: NPEDACTION) {
|
|||||||
...state,
|
...state,
|
||||||
sessionList: action.payload,
|
sessionList: action.payload,
|
||||||
};
|
};
|
||||||
case "NPEDCATENABLED":
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
iscatEnabled: action.payload,
|
|
||||||
};
|
|
||||||
default:
|
default:
|
||||||
return { ...state };
|
return { ...state };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ 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: [
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { Toaster } from "sonner";
|
|||||||
import { useNPEDAuth } from "../hooks/useNPEDAuth";
|
import { useNPEDAuth } from "../hooks/useNPEDAuth";
|
||||||
import SoundSettingsCard from "../components/SettingForms/Sound/SoundSettingsCard";
|
import SoundSettingsCard from "../components/SettingForms/Sound/SoundSettingsCard";
|
||||||
import SoundUploadCard from "../components/SettingForms/Sound/SoundUploadCard";
|
import SoundUploadCard from "../components/SettingForms/Sound/SoundUploadCard";
|
||||||
import NPEDCategoryPopup from "../components/PopupSettings/NPEDCategoryPopup";
|
|
||||||
|
|
||||||
const SystemSettings = () => {
|
const SystemSettings = () => {
|
||||||
useNPEDAuth();
|
useNPEDAuth();
|
||||||
@@ -39,7 +38,6 @@ 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">
|
<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 />
|
<NPEDCard />
|
||||||
<NPEDHotlistCard />
|
<NPEDHotlistCard />
|
||||||
<NPEDCategoryPopup />
|
|
||||||
</div>
|
</div>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel>
|
<TabPanel>
|
||||||
|
|||||||
@@ -423,7 +423,6 @@ export type NPEDSTATE = {
|
|||||||
sessionPaused: boolean;
|
sessionPaused: boolean;
|
||||||
savedSightings: DedupedSightings;
|
savedSightings: DedupedSightings;
|
||||||
npedUser: NPEDUser;
|
npedUser: NPEDUser;
|
||||||
iscatEnabled: CategoryPopups;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NPEDACTION = {
|
export type NPEDACTION = {
|
||||||
@@ -431,10 +430,3 @@ export type NPEDACTION = {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
payload: any;
|
payload: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CategoryPopups = {
|
|
||||||
catA: boolean;
|
|
||||||
catB: boolean;
|
|
||||||
catC: boolean;
|
|
||||||
catD: boolean;
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user