- updated form to include bof2 constants
- refactored code to make more scalable and use one form
This commit is contained in:
@@ -36,8 +36,7 @@ const updateBackOfficeConfig = async (data: InitialValuesForm) => {
|
||||
},
|
||||
],
|
||||
};
|
||||
console.log(updateConfigPayload);
|
||||
const response = await fetch(`${CAM_BASE}/api/update-config?id=Dispatcher-${data.format.toLowerCase()}`, {
|
||||
const response = await fetch(`${CAM_BASE}/api/update-config?id=Dispatcher`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(updateConfigPayload),
|
||||
});
|
||||
@@ -52,6 +51,16 @@ export const useCameraBackOfficeOutput = (format: string) => {
|
||||
enabled: !!format,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (backOfficeQuery.isError) toast.error(backOfficeQuery.error.message);
|
||||
}, [backOfficeQuery?.error?.message, backOfficeQuery.isError]);
|
||||
|
||||
return {
|
||||
backOfficeQuery,
|
||||
};
|
||||
};
|
||||
|
||||
export const useUpdateBackOfficeConfig = () => {
|
||||
const backOfficeMutation = useMutation({
|
||||
mutationKey: ["backOfficeUpdate"],
|
||||
mutationFn: updateBackOfficeConfig,
|
||||
@@ -62,13 +71,5 @@ export const useCameraBackOfficeOutput = (format: string) => {
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (backOfficeQuery.isError) toast.error(backOfficeQuery.error.message);
|
||||
}, [backOfficeQuery?.error?.message, backOfficeQuery.isError]);
|
||||
|
||||
return {
|
||||
backOfficeQuery,
|
||||
backOfficeMutation,
|
||||
};
|
||||
return { backOfficeMutation };
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user