diff --git a/src/App.tsx b/src/App.tsx index 3d9f929..980e322 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,7 +5,7 @@ import FrontCamera from "./pages/FrontCamera"; import RearCamera from "./pages/RearCamera"; import SystemSettings from "./pages/SystemSettings"; import Session from "./pages/Session"; -import { NPEDUserProvider } from "./context/providers/NPEDUserContextProvider"; +import { IntegrationsProvider } from "./context/providers/IntegrationsContextProvider"; import { AlertHitProvider } from "./context/providers/AlertHitProvider"; import { SoundProvider } from "react-sounds"; import SoundContextProvider from "./context/providers/SoundContextProvider"; @@ -14,7 +14,7 @@ function App() { return ( - + }> @@ -27,7 +27,7 @@ function App() { - + ); diff --git a/src/components/SessionForm/SessionCard.tsx b/src/components/SessionForm/SessionCard.tsx index 42cdd7f..4d0cab2 100644 --- a/src/components/SessionForm/SessionCard.tsx +++ b/src/components/SessionForm/SessionCard.tsx @@ -1,6 +1,6 @@ import Card from "../UI/Card"; import CardHeader from "../UI/CardHeader"; -import { useNPEDContext } from "../../context/NPEDUserContext"; +import { useIntegrationsContext } from "../../context/IntegrationsContext"; import type { ReducedSightingType } from "../../types/types"; import { toast } from "sonner"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; @@ -9,15 +9,18 @@ import VehicleSessionItem from "../UI/VehicleSessionItem"; import { useCameraBlackboard } from "../../hooks/useCameraBlackboard"; const SessionCard = () => { - const { sessionStarted, setSessionStarted, sessionList, setSessionPaused, sessionPaused, savedSightings } = - useNPEDContext(); + const { state, dispatch } = useIntegrationsContext(); const { mutation } = useCameraBlackboard(); - const sightings = [...new Map(sessionList.map((vehicle) => [vehicle.vrm, vehicle]))]; + const sessionStarted = state.sessionStarted; + const sessionPaused = state.sessionPaused; + const sessionList = state.sessionList; + + const sightings = [...new Map(sessionList?.map((vehicle) => [vehicle.vrm, vehicle]))]; const dedupedSightings = sightings.map((sighting) => sighting[1]); - const vehicles = savedSightings.reduce>( + const vehicles = dedupedSightings.reduce>( (acc, item) => { const hotlisthit = Object.values(item.metadata?.hotlistMatches ?? {}).includes(true); if (item.metadata?.npedJSON["NPED CATEGORY"] === "A") acc.npedCatA.push(item); @@ -43,13 +46,13 @@ const SessionCard = () => { ); const handleStartClick = () => { - setSessionStarted(!sessionStarted); - setSessionPaused(false); + dispatch({ type: "SESSIONSTART", payload: !sessionStarted }); + dispatch({ type: "SESSIONPAUSE", payload: false }); toast(`${sessionStarted ? "Vehicle tracking session ended" : "Vehicle tracking session started"}`); }; const handlepauseClick = () => { - setSessionPaused(!sessionPaused); + dispatch({ type: "SESSIONPAUSE", payload: !sessionPaused }); toast(`${sessionStarted ? "Vehicle tracking session paused" : "Vehicle tracking session resumed"}`); }; diff --git a/src/components/SettingForms/NPED/NPEDFields.tsx b/src/components/SettingForms/NPED/NPEDFields.tsx index 3e42d24..795c074 100644 --- a/src/components/SettingForms/NPED/NPEDFields.tsx +++ b/src/components/SettingForms/NPED/NPEDFields.tsx @@ -6,16 +6,18 @@ import { toast } from "sonner"; import { faEyeSlash, faEye } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useState } from "react"; +import { useIntegrationsContext } from "../../../context/IntegrationsContext"; const NPEDFields = () => { + const { state } = useIntegrationsContext(); const [showPwd, setShowPwd] = useState(false); - const { signIn, user, signOut } = useNPEDAuth(); + const { signIn, signOut } = useNPEDAuth(); - const initialValues = user + const initialValues = state.npedUser ? { - username: user?.propUsername?.value, - password: user?.propPassword?.value, - clientId: user?.propClientID?.value, + username: state.npedUser?.propUsername?.value, + password: state.npedUser?.propPassword?.value, + clientId: state.npedUser?.propClientID?.value, frontId: "NPED", rearId: "NPED", } @@ -48,20 +50,13 @@ const NPEDFields = () => { }; return ( - + {({ errors, touched, isSubmitting }) => (
{touched.username && errors.username && ( - - {errors.username} - + {errors.username} )} { className="p-2 border border-gray-400 rounded-lg w-full" /> {touched.password && errors.password && ( - - {errors.password} - + {errors.password} )} { {touched.clientId && errors.clientId && ( - - {errors.clientId} - + {errors.clientId} )} { className="p-1.5 border border-gray-400 rounded-lg" /> - {!user?.propClientID?.value ? ( + {!state.npedUser?.propClientID?.value ? (