Files
Mav-Mobile-UI/src/context/providers/IntegrationsContextProvider.tsx

37 lines
1.0 KiB
TypeScript
Raw Normal View History

import { useEffect, useReducer, type ReactNode } from "react";
2025-10-27 09:35:59 +00:00
import { IntegrationsContext } from "../IntegrationsContext";
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
2025-10-27 09:35:59 +00:00
import { initialState, reducer } from "../reducers/IntegrationsContextReducer";
2025-08-29 10:07:59 +01:00
2025-10-27 09:35:59 +00:00
type IntegrationsProviderType = {
2025-08-29 10:07:59 +01:00
children: ReactNode;
};
2025-10-27 09:35:59 +00:00
export const IntegrationsProvider = ({ children }: IntegrationsProviderType) => {
const [state, dispatch] = useReducer(reducer, initialState);
const { mutation } = useCameraBlackboard();
2025-08-29 10:07:59 +01:00
useEffect(() => {
const fetchData = async () => {
const result = await mutation.mutateAsync({
operation: "VIEW",
path: "sessionStats",
});
if (!result.result || typeof result.result === "string") return;
dispatch({ type: "UPDATE", payload: result?.result });
};
fetchData();
}, []);
2025-08-29 10:07:59 +01:00
return (
2025-10-27 09:35:59 +00:00
<IntegrationsContext.Provider
value={{
2025-10-27 09:35:59 +00:00
state,
dispatch,
}}
>
2025-08-29 10:07:59 +01:00
{children}
2025-10-27 09:35:59 +00:00
</IntegrationsContext.Provider>
2025-08-29 10:07:59 +01:00
);
};