2025-11-26 13:00:41 +00:00
|
|
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
|
|
|
import type { BearerTypeFields } from "../../../types/types";
|
2025-11-27 09:43:09 +00:00
|
|
|
import { CAMBASE } from "../../../utils/config";
|
2025-11-26 13:00:41 +00:00
|
|
|
|
|
|
|
|
const fetchBearerConfig = async (bearerConfig: string) => {
|
2025-11-27 09:43:09 +00:00
|
|
|
const response = await fetch(`${CAMBASE}/api/fetch-config?id=Dispatcher0-${bearerConfig}`, {
|
2025-11-26 13:00:41 +00:00
|
|
|
method: "GET",
|
|
|
|
|
});
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error("Network response was not ok");
|
|
|
|
|
}
|
|
|
|
|
return response.json();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const postBearerConfig = async (config: BearerTypeFields) => {
|
|
|
|
|
const channelConfigPayload = {
|
|
|
|
|
id: `Dispatcher0-${config.format.toLowerCase()}`,
|
|
|
|
|
fields: [
|
|
|
|
|
{
|
|
|
|
|
property: "propBackofficeURL",
|
|
|
|
|
value: config.backOfficeURL,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
property: "propConnectTimeoutSeconds",
|
|
|
|
|
value: config.connectTimeoutSeconds,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
property: "propPassword",
|
|
|
|
|
value: config.password,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
property: "propReadTimeoutSeconds",
|
|
|
|
|
value: config.readTimeoutSeconds,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
property: "propUsername",
|
|
|
|
|
value: config.username,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
2025-11-27 09:43:09 +00:00
|
|
|
const response = await fetch(`${CAMBASE}/api/update-config`, {
|
2025-11-26 13:00:41 +00:00
|
|
|
method: "POST",
|
|
|
|
|
body: JSON.stringify(channelConfigPayload),
|
|
|
|
|
});
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error("Network response was not ok");
|
|
|
|
|
}
|
|
|
|
|
return response.json();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const usePostBearerConfig = () => {
|
|
|
|
|
const bearerMutation = useMutation({
|
|
|
|
|
mutationFn: (query: BearerTypeFields) => postBearerConfig(query),
|
|
|
|
|
mutationKey: ["outputs"],
|
|
|
|
|
});
|
|
|
|
|
return { bearerMutation };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const useGetBearerConfig = (bearerConfig: string) => {
|
|
|
|
|
const bearerQuery = useQuery({
|
|
|
|
|
queryKey: ["outputs", bearerConfig],
|
|
|
|
|
queryFn: () => fetchBearerConfig(bearerConfig),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return { bearerQuery };
|
|
|
|
|
};
|