- updated form to include bof2 constants

- refactored code to make more scalable and use one form
This commit is contained in:
2025-11-04 10:24:06 +00:00
parent 933c101cbc
commit 538b623ac6
7 changed files with 237 additions and 159 deletions

View File

@@ -2,7 +2,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
import { CAM_BASE } from "../utils/config";
import { useEffect } from "react";
import { toast } from "sonner";
import type { BearerTypeFieldType } from "../types/types";
import type { BearerTypeFieldType, OptionalBOF2Constants } from "../types/types";
const getDispatcherConfig = async () => {
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=Dispatcher`);
@@ -32,6 +32,37 @@ const updateDispatcherConfig = async (data: BearerTypeFieldType) => {
return response.json();
};
const updateBackOfficeDispatcher = async (data: OptionalBOF2Constants) => {
console.log(data);
const bof2ContantsPayload = {
id: "Dispatcher-bof2-constants",
fields: [
{
property: "propFeedIdentifier",
value: data?.FFID,
},
{
property: "propSourceIdentifier",
value: data?.SCID,
},
{
property: "propTimeZoneType",
value: data?.timestampSource,
},
{
property: "propGpsFormat",
value: data?.GPSFormat,
},
],
};
const response = await fetch(`${CAM_BASE}/api/update-config?id=Dispatcher-bof2-constants`, {
method: "POST",
body: JSON.stringify(bof2ContantsPayload),
});
if (!response.ok) throw new Error("Cannot update dispatcher configuration");
return response.json();
};
export const useCameraOutput = () => {
const dispatcherQuery = useQuery({
queryKey: ["dispatcher"],
@@ -49,6 +80,11 @@ export const useCameraOutput = () => {
},
});
const backOfficeDispatcherMutation = useMutation({
mutationKey: ["backofficedDispatcher"],
mutationFn: updateBackOfficeDispatcher,
});
useEffect(() => {
if (dispatcherQuery.isError) toast.error(dispatcherQuery.error.message);
}, [dispatcherQuery?.error?.message, dispatcherQuery.isError]);
@@ -56,5 +92,6 @@ export const useCameraOutput = () => {
return {
dispatcherQuery,
dispatcherMutation,
backOfficeDispatcherMutation,
};
};