- added form fetch and post for optional constants for UTMC

This commit is contained in:
2025-11-26 15:31:19 +00:00
parent e07f769288
commit 97ff9a981d
5 changed files with 113 additions and 10 deletions

View File

@@ -0,0 +1,62 @@
import { useQuery, useMutation } from "@tanstack/react-query";
import type { OptionalBOF2Constants } from "../../../types/types";
const fetchOptionalConstants = async (format: string) => {
if (!format || format === "json") return null;
const response = await fetch(`http://100.115.148.59/api/fetch-config?id=Dispatcher0-${format}-constants`);
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
const postOptionalConstants = async (config: OptionalBOF2Constants) => {
const fields = [
{
property: "propSourceIdentifier",
value: config?.SCID,
},
{
property: "propTimeZoneType",
value: config?.timestampSource,
},
{
property: "propGpsFormat",
value: config?.GPSFormat,
},
];
if (config.FFID) {
fields.push({
property: "propFeedIdentifier",
value: config.FFID,
});
}
const updateConfigPayload = {
id: `Dispatcher0-${config.format?.toLowerCase()}-constants`,
fields: fields,
};
const response = await fetch(`http://100.115.148.59/api/update-config`, {
method: "POST",
body: JSON.stringify(updateConfigPayload),
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
export const useOptionalConstants = (format: string) => {
const optionalConstantsQuery = useQuery({
queryKey: ["optionalConstants", format],
queryFn: () => fetchOptionalConstants(format),
enabled: !!format && format !== "json",
});
const optionalConstantsMutation = useMutation({
mutationKey: ["postOptionalConstants"],
mutationFn: postOptionalConstants,
});
return { optionalConstantsQuery, optionalConstantsMutation };
};