- added endpoints for dns and other
This commit is contained in:
@@ -1,11 +1,41 @@
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { sendBlobFileUpload } from "../components/SettingForms/System/Upload";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
handleSystemSave,
|
||||
handleSystemRecall,
|
||||
} from "../components/SettingForms/System/SettingSaveRecall";
|
||||
import { handleSystemSave, handleSystemRecall } from "../components/SettingForms/System/SettingSaveRecall";
|
||||
import { useEffect } from "react";
|
||||
import { CAM_BASE } from "../utils/config";
|
||||
import type { DNSSettingsType } from "../types/types";
|
||||
|
||||
const camBase = import.meta.env.MODE !== "development" ? CAM_BASE : "";
|
||||
|
||||
const getDNSSettings = async () => {
|
||||
const response = await fetch(`${camBase}/api/fetch-config?id=GLOBAL--NetworkConfig`);
|
||||
if (!response.ok) throw new Error("Cannot get DNS Settings");
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const updateDNSSettings = async (data: DNSSettingsType) => {
|
||||
const dnsSettingsPayload = {
|
||||
id: "GLOBAL--NetworkConfig",
|
||||
fields: [
|
||||
{
|
||||
property: "propNameServerPrimary",
|
||||
value: data?.serverPrimary,
|
||||
},
|
||||
{
|
||||
property: "propNameServerSecondary",
|
||||
value: data?.serverSecondary,
|
||||
},
|
||||
],
|
||||
};
|
||||
const response = await fetch(`${camBase}/api/update-config?id=GLOBAL--NetworkConfig`, {
|
||||
method: "post",
|
||||
body: JSON.stringify(dnsSettingsPayload),
|
||||
});
|
||||
if (!response.ok) throw new Error("cannot send to dns endpoint");
|
||||
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const useSystemConfig = () => {
|
||||
const uploadSettingsMutation = useMutation({
|
||||
@@ -51,3 +81,20 @@ export const useSystemConfig = () => {
|
||||
saveSystemSettingsLoading: saveSystemSettings.isPending,
|
||||
};
|
||||
};
|
||||
|
||||
export const useDNSSettings = () => {
|
||||
const dnsQuery = useQuery({
|
||||
queryKey: ["getDNSSettings"],
|
||||
queryFn: getDNSSettings,
|
||||
});
|
||||
|
||||
const dnsMutation = useMutation({
|
||||
mutationKey: ["updateDNSSettings"],
|
||||
mutationFn: updateDNSSettings,
|
||||
});
|
||||
|
||||
return {
|
||||
dnsQuery,
|
||||
dnsMutation,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user