From 251a2f5e7b3c45210bc235f86e16def21b4b6c26 Mon Sep 17 00:00:00 2001 From: Toba Ojo Date: Mon, 27 Oct 2025 09:35:59 +0000 Subject: [PATCH 1/2] - refactored NPED Login & logout --- src/App.tsx | 6 ++-- src/components/SessionForm/SessionCard.tsx | 4 +-- .../SettingForms/NPED/NPEDFields.tsx | 33 +++++++------------ .../SightingsWidget/SightingWidget.tsx | 6 ++-- src/components/UI/Header.tsx | 4 +-- src/context/IntegrationsContext.ts | 22 +++++++++++++ src/context/NPEDUserContext.ts | 22 ------------- ...er.tsx => IntegrationsContextProvider.tsx} | 21 ++++++------ ...ducer.ts => IntegrationsContextReducer.ts} | 13 +++++++- src/hooks/useNPEDAuth.ts | 20 +++++------ src/types/types.ts | 1 + 11 files changed, 76 insertions(+), 76 deletions(-) create mode 100644 src/context/IntegrationsContext.ts delete mode 100644 src/context/NPEDUserContext.ts rename src/context/providers/{NPEDUserContextProvider.tsx => IntegrationsContextProvider.tsx} (68%) rename src/context/reducers/{NPEDContextReducer.ts => IntegrationsContextReducer.ts} (63%) 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..1341ca4 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"; @@ -10,7 +10,7 @@ import { useCameraBlackboard } from "../../hooks/useCameraBlackboard"; const SessionCard = () => { const { sessionStarted, setSessionStarted, sessionList, setSessionPaused, sessionPaused, savedSightings } = - useNPEDContext(); + useIntegrationsContext(); const { mutation } = useCameraBlackboard(); const sightings = [...new Map(sessionList.map((vehicle) => [vehicle.vrm, vehicle]))]; 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 ? (