Files
Mav-Mobile-UI/src/context/providers/IntegrationsContextProvider.tsx
Toba Ojo dd1cd342c1 - added nped category options for alert popups
- minor fix on modal for 'DISABLED' MCC
2025-11-14 15:01:01 +00:00

59 lines
1.5 KiB
TypeScript

import { useEffect, useReducer, type ReactNode } from "react";
import { IntegrationsContext } from "../IntegrationsContext";
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
import { initialState, reducer } from "../reducers/IntegrationsContextReducer";
type IntegrationsProviderType = {
children: ReactNode;
};
export const IntegrationsProvider = ({ children }: IntegrationsProviderType) => {
const [state, dispatch] = useReducer(reducer, initialState);
const { mutation } = useCameraBlackboard();
useEffect(() => {
let isMounted = true;
const fetchData = async () => {
try {
const result = await mutation.mutateAsync({
operation: "VIEW",
path: "sessionStats",
});
if (!isMounted) return;
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();
return () => {
isMounted = false;
};
}, []);
return (
<IntegrationsContext.Provider
value={{
state,
dispatch,
}}
>
{children}
</IntegrationsContext.Provider>
);
};