- refactor: replace Output component with OutputForms and update related hooks and types

This commit is contained in:
2025-11-26 13:00:41 +00:00
parent 90eb976092
commit e07f769288
14 changed files with 232 additions and 104 deletions

View File

@@ -0,0 +1,47 @@
import { useQuery, useMutation } from "@tanstack/react-query";
import type { DispatcherConfig } from "../../../types/types";
const getDispatcherConfig = async () => {
const response = await fetch(`http://192.168.202.121/api/fetch-config?id=Dispatcher0`);
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
const postDispatcherConfig = async (config: DispatcherConfig) => {
const updateConfigPayload = {
id: "Dispatcher0",
fields: [
{
property: "propEnabled",
value: config.enabled,
},
{
property: "propFormat",
value: config.format,
},
],
};
const response = await fetch(`http://192.168.202.121/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 useDispatcherConfig = () => {
const dispatcherQuery = useQuery({
queryKey: ["dispatcherConfig"],
queryFn: () => getDispatcherConfig(),
});
const dispatcherMutation = useMutation({
mutationKey: ["postDispatcherConfig"],
mutationFn: (config: DispatcherConfig) => postDispatcherConfig(config),
});
return { dispatcherQuery, dispatcherMutation };
};