- can get data need to post

This commit is contained in:
2025-11-25 23:04:40 +00:00
parent 225a2a6168
commit 90eb976092
5 changed files with 80 additions and 6 deletions

View File

@@ -0,0 +1,20 @@
import { useQuery } from "@tanstack/react-query";
const fetchOutputs = async (format: string) => {
const response = await fetch(`http://100.115.148.59/api/fetch-config?id=Dispatcher0-${format}`, {
method: "GET",
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
export const useGetOutputs = (format: string) => {
const query = useQuery({
queryKey: ["outputs", format],
queryFn: () => fetchOutputs(format),
});
return { query };
};

View File

@@ -0,0 +1,21 @@
import { useMutation } from "@tanstack/react-query";
import type { BearerTypeFields } from "../../../types/types";
const postQuery = async (query: BearerTypeFields) => {
const response = await fetch("/api/outputs", {
method: "POST",
body: JSON.stringify({ query }),
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
export const usePostOutputs = () => {
const mutation = useMutation({
mutationFn: (query: BearerTypeFields) => postQuery(query),
mutationKey: ["outputs"],
});
return { mutation };
};