2025-09-23 16:02:14 +01:00
|
|
|
import { faCheck, faTrash, faX } from "@fortawesome/free-solid-svg-icons";
|
2025-09-12 13:28:14 +01:00
|
|
|
import type { SightingType } from "../../types/types";
|
2025-09-12 08:21:52 +01:00
|
|
|
import NumberPlate from "../PlateStack/NumberPlate";
|
|
|
|
|
import ModalComponent from "../UI/ModalComponent";
|
2025-09-16 11:07:35 +01:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2025-09-18 15:14:47 +01:00
|
|
|
import { useAlertHitContext } from "../../context/AlertHitContext";
|
|
|
|
|
import { toast, Toaster } from "sonner";
|
2025-09-24 12:28:14 +01:00
|
|
|
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
2025-09-19 10:09:14 +01:00
|
|
|
import HotListImg from "/Hotlist_Hit.svg";
|
2025-09-22 09:26:45 +01:00
|
|
|
import NPED_CAT_A from "/NPED_Cat_A.svg";
|
|
|
|
|
import NPED_CAT_B from "/NPED_Cat_B.svg";
|
|
|
|
|
import NPED_CAT_C from "/NPED_Cat_C.svg";
|
2025-10-15 12:24:28 +01:00
|
|
|
import { checkIsHotListHit, getHotlistName, getNPEDCategory } from "../../utils/utils";
|
2025-09-12 08:21:52 +01:00
|
|
|
|
|
|
|
|
type SightingModalProps = {
|
|
|
|
|
isSightingModalOpen: boolean;
|
|
|
|
|
handleClose: () => void;
|
2025-09-12 13:28:14 +01:00
|
|
|
sighting: SightingType | null;
|
2025-10-13 11:48:10 +01:00
|
|
|
onDelete?: (deletedItem: SightingType | null) => void;
|
2025-09-12 08:21:52 +01:00
|
|
|
};
|
|
|
|
|
|
2025-10-15 12:24:28 +01:00
|
|
|
const SightingModal = ({ isSightingModalOpen, handleClose, sighting, onDelete }: SightingModalProps) => {
|
2025-09-18 15:14:47 +01:00
|
|
|
const { dispatch } = useAlertHitContext();
|
2025-09-24 12:28:14 +01:00
|
|
|
const { query, mutation } = useCameraBlackboard();
|
2025-09-16 11:07:35 +01:00
|
|
|
|
2025-10-24 10:49:04 +01:00
|
|
|
const hotlistNames = getHotlistName(sighting?.metadata?.hotlistMatches);
|
2025-09-18 15:14:47 +01:00
|
|
|
const handleAcknowledgeButton = () => {
|
2025-09-24 12:28:14 +01:00
|
|
|
try {
|
|
|
|
|
if (!sighting) {
|
|
|
|
|
toast.error("Cannot add sighting to alert list");
|
|
|
|
|
handleClose();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!query.data.alertHistory) {
|
|
|
|
|
mutation.mutate({
|
|
|
|
|
operation: "INSERT",
|
|
|
|
|
path: "alertHistory",
|
|
|
|
|
value: [sighting],
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
mutation.mutate({
|
|
|
|
|
operation: "APPEND",
|
|
|
|
|
path: "alertHistory",
|
|
|
|
|
value: sighting,
|
|
|
|
|
});
|
2025-10-13 11:48:10 +01:00
|
|
|
toast.success("Sighting Successfully added to alert list");
|
2025-09-24 12:28:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dispatch({ type: "ADD", payload: sighting });
|
|
|
|
|
handleClose();
|
|
|
|
|
} catch (error) {
|
2025-10-07 15:58:16 +01:00
|
|
|
console.error(error);
|
2025-09-24 12:28:14 +01:00
|
|
|
toast.error("Failed to add sighting to alert list");
|
2025-09-18 15:14:47 +01:00
|
|
|
handleClose();
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-09-16 11:07:35 +01:00
|
|
|
|
2025-10-13 11:48:10 +01:00
|
|
|
const handleDeleteClick = (deletedItem: SightingType | null) => {
|
2025-09-23 16:02:14 +01:00
|
|
|
if (!onDelete) return;
|
2025-10-13 11:48:10 +01:00
|
|
|
onDelete(deletedItem);
|
2025-09-23 16:02:14 +01:00
|
|
|
handleClose();
|
|
|
|
|
toast.success("Sighting removed from alert list");
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-18 15:14:47 +01:00
|
|
|
const motionAway = (sighting?.motion ?? "").toUpperCase() === "AWAY";
|
2025-10-09 14:11:58 +01:00
|
|
|
const isHotListHit = checkIsHotListHit(sighting);
|
2025-10-14 08:50:06 +01:00
|
|
|
const cat = getNPEDCategory(sighting);
|
|
|
|
|
const isNPEDHitA = cat === "A";
|
|
|
|
|
const isNPEDHitB = cat === "B";
|
|
|
|
|
const isNPEDHitC = cat === "C";
|
2025-09-16 11:07:35 +01:00
|
|
|
|
2025-09-18 15:14:47 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<ModalComponent isModalOpen={isSightingModalOpen} close={handleClose}>
|
|
|
|
|
<div className="max-w-screen-lg mx-auto py-4 px-2">
|
|
|
|
|
<div className="border-b border-gray-600 mb-4">
|
2025-10-15 12:24:28 +01:00
|
|
|
<h2 className="text-lg md:text-xl font-semibold">Sighting Details</h2>
|
2025-09-18 15:14:47 +01:00
|
|
|
</div>
|
2025-10-07 15:42:06 +01:00
|
|
|
<div className="mt-3 flex-col-reverse gap-3 md:flex-row md:justify-center flex md:hidden">
|
|
|
|
|
{onDelete ? (
|
|
|
|
|
<button
|
|
|
|
|
className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-red-600 text-white hover:bg-red-700 w-full md:w-full"
|
2025-10-13 11:48:10 +01:00
|
|
|
onClick={() => handleDeleteClick(sighting)}
|
2025-10-07 15:42:06 +01:00
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon={faTrash} />
|
|
|
|
|
Delete
|
|
|
|
|
</button>
|
|
|
|
|
) : (
|
|
|
|
|
<button
|
|
|
|
|
className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-red-600 text-white hover:bg-red-700 w-full md:w-full"
|
|
|
|
|
onClick={handleClose}
|
|
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon={faX} />
|
|
|
|
|
Deny
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
{onDelete ? (
|
|
|
|
|
<button
|
|
|
|
|
className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-blue-600 text-white hover:bg-blue-700 w-full md:w-full"
|
|
|
|
|
onClick={handleClose}
|
|
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon={faX} />
|
|
|
|
|
Close
|
|
|
|
|
</button>
|
|
|
|
|
) : (
|
|
|
|
|
<button
|
|
|
|
|
className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-green-600 text-white hover:bg-green-700 w-full md:w-full"
|
|
|
|
|
onClick={handleAcknowledgeButton}
|
|
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon={faCheck} />
|
2025-10-17 10:17:01 +01:00
|
|
|
Acknowledge
|
2025-10-07 15:42:06 +01:00
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2025-09-19 10:55:36 +01:00
|
|
|
<div className="flex flex-col md:flex-row gap-3 items-center mb-2 justify-between">
|
|
|
|
|
<div className="flex flex-col md:flex-row gap-3 items-center">
|
|
|
|
|
<NumberPlate vrm={sighting?.vrm} motion={motionAway} />
|
2025-10-15 12:24:28 +01:00
|
|
|
<img src={sighting?.plateUrlColour} alt="plate patch" className="h-16 object-contain rounded-md" />
|
2025-09-19 10:55:36 +01:00
|
|
|
</div>
|
|
|
|
|
|
2025-10-15 12:24:28 +01:00
|
|
|
{isHotListHit && <img src={HotListImg} alt="hotlistHit" className="h-20 object-contain rounded-md" />}
|
|
|
|
|
{isNPEDHitA && <img src={NPED_CAT_A} alt="hotlistHit" className="h-20 object-contain rounded-md" />}
|
|
|
|
|
{isNPEDHitB && <img src={NPED_CAT_B} alt="hotlistHit" className="h-20 object-contain rounded-md" />}
|
|
|
|
|
{isNPEDHitC && <img src={NPED_CAT_C} alt="hotlistHit" className="h-20 object-contain rounded-md" />}
|
2025-09-18 15:14:47 +01:00
|
|
|
</div>
|
2025-10-24 10:49:04 +01:00
|
|
|
{hotlistNames && (
|
|
|
|
|
<div className="flex flex-col border-b border-gray-600 mb-4">
|
|
|
|
|
<p className="text-gray-300">Hotlists</p>
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-x-[90%] lg:gap-x-[15%] w-[50%]">
|
2025-10-27 11:04:53 +00:00
|
|
|
{hotlistNames.map((hotlistName, index) => (
|
|
|
|
|
<div className="items-center px-2.5 py-0.5 rounded-sm me-2 bg-amber-500 w-55 m-2" key={index}>
|
2025-10-24 10:49:04 +01:00
|
|
|
<p className="font-medium text-2xl break-all text-amber-800">
|
|
|
|
|
{hotlistName ? hotlistName?.replace(/\.csv$/i, "") : "-"}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-10-07 15:42:06 +01:00
|
|
|
<div className="flex flex-col lg:flex-row items-center gap-3">
|
2025-09-16 11:07:35 +01:00
|
|
|
<img
|
|
|
|
|
src={sighting?.overviewUrl}
|
|
|
|
|
alt="overview patch"
|
|
|
|
|
className="w-full h-56 sm:h-72 md:h-96 rounded-lg object-cover border border-gray-700"
|
|
|
|
|
/>
|
2025-10-07 15:42:06 +01:00
|
|
|
<aside className="w-full lg:w-80 bg-gray-800/70 text-white rounded-xl py-4 px-2 border h-[70%] border-gray-700">
|
2025-10-15 12:24:28 +01:00
|
|
|
<h3 className="text-base md:text-lg font-semibold pb-2 border-b border-gray-700">Vehicle Info</h3>
|
2025-09-18 15:14:47 +01:00
|
|
|
<dl className="mt-3 gap-x-4 gap-y-2 text-sm">
|
|
|
|
|
<div>
|
|
|
|
|
<dt className="text-gray-300">VRM</dt>
|
2025-10-15 12:24:28 +01:00
|
|
|
<dd className="font-medium text-2xl break-all">{sighting?.vrm ?? "-"}</dd>
|
2025-09-18 15:14:47 +01:00
|
|
|
</div>
|
2025-10-15 12:24:28 +01:00
|
|
|
|
2025-09-18 15:14:47 +01:00
|
|
|
<div>
|
|
|
|
|
<dt className="text-gray-300">Motion</dt>
|
2025-10-15 12:24:28 +01:00
|
|
|
<dd className="font-medium text-2xl">{sighting?.motion ?? "-"}</dd>
|
2025-09-18 15:14:47 +01:00
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<dt className="text-gray-300">Seen Count</dt>
|
2025-10-15 12:24:28 +01:00
|
|
|
<dd className="font-medium text-2xl">{sighting?.seenCount ?? "-"}</dd>
|
2025-09-18 15:14:47 +01:00
|
|
|
</div>
|
2025-09-16 11:07:35 +01:00
|
|
|
|
2025-10-17 10:17:01 +01:00
|
|
|
{sighting?.make && (
|
|
|
|
|
<div>
|
|
|
|
|
<dt className="text-gray-300">Make</dt>
|
|
|
|
|
<dd className="font-medium text-2xl">{sighting?.make ?? "-"}</dd>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{sighting?.model ||
|
|
|
|
|
(!sighting?.model.trim() && (
|
|
|
|
|
<div>
|
|
|
|
|
<dt className="text-gray-300">Model</dt>
|
|
|
|
|
<dd className="font-medium text-2xl">{sighting?.model ?? "-"}</dd>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
{sighting?.color && (
|
|
|
|
|
<div className="sm:col-span-2">
|
|
|
|
|
<dt className="text-gray-300">Colour</dt>
|
|
|
|
|
<dd className="font-medium text-2xl">{sighting?.color ?? "-"}</dd>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-09-18 15:14:47 +01:00
|
|
|
<div>
|
|
|
|
|
<dt className="text-gray-300">Time</dt>
|
2025-10-15 12:24:28 +01:00
|
|
|
<dd className="font-medium text-xl">{sighting?.timeStamp ?? "-"}</dd>
|
2025-09-18 15:14:47 +01:00
|
|
|
</div>
|
|
|
|
|
</dl>
|
|
|
|
|
</aside>
|
2025-09-16 11:07:35 +01:00
|
|
|
</div>
|
|
|
|
|
|
2025-10-07 15:42:06 +01:00
|
|
|
<div className="mt-3 flex-col-reverse gap-3 md:flex-row md:justify-center hidden md:flex">
|
2025-09-23 16:02:14 +01:00
|
|
|
{onDelete ? (
|
|
|
|
|
<button
|
|
|
|
|
className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-blue-600 text-white hover:bg-blue-700 w-full md:w-full"
|
|
|
|
|
onClick={handleClose}
|
|
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon={faX} />
|
|
|
|
|
Close
|
|
|
|
|
</button>
|
|
|
|
|
) : (
|
|
|
|
|
<button
|
|
|
|
|
className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-green-600 text-white hover:bg-green-700 w-full md:w-full"
|
|
|
|
|
onClick={handleAcknowledgeButton}
|
|
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon={faCheck} />
|
2025-10-17 10:17:01 +01:00
|
|
|
Acknowledge
|
2025-09-23 16:02:14 +01:00
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
{onDelete ? (
|
|
|
|
|
<button
|
|
|
|
|
className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-red-600 text-white hover:bg-red-700 w-full md:w-full"
|
2025-10-13 11:48:10 +01:00
|
|
|
onClick={() => handleDeleteClick(sighting)}
|
2025-09-23 16:02:14 +01:00
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon={faTrash} />
|
|
|
|
|
Delete
|
|
|
|
|
</button>
|
|
|
|
|
) : (
|
|
|
|
|
<button
|
|
|
|
|
className="inline-flex items-center justify-center gap-2 rounded-lg px-5 py-3 bg-red-600 text-white hover:bg-red-700 w-full md:w-full"
|
|
|
|
|
onClick={handleClose}
|
|
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon={faX} />
|
|
|
|
|
Deny
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
2025-09-18 15:14:47 +01:00
|
|
|
</div>
|
2025-09-12 13:28:14 +01:00
|
|
|
</div>
|
2025-09-18 15:14:47 +01:00
|
|
|
</ModalComponent>
|
|
|
|
|
<Toaster />
|
|
|
|
|
</>
|
2025-09-12 08:21:52 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SightingModal;
|