- added endpoints for dns and other
This commit is contained in:
@@ -2,7 +2,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { CAM_BASE } from "../utils/config";
|
||||
import { useEffect } from "react";
|
||||
import { toast } from "sonner";
|
||||
import type { BearerTypeFieldType, OptionalBOF2Constants } from "../types/types";
|
||||
import type { BearerTypeFieldType, OptionalBOF2Constants, OptionalBOF2LaneIDs } from "../types/types";
|
||||
|
||||
const getDispatcherConfig = async () => {
|
||||
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=Dispatcher`);
|
||||
@@ -63,11 +63,40 @@ const updateBackOfficeDispatcher = async (data: OptionalBOF2Constants) => {
|
||||
};
|
||||
|
||||
const getBof2DispatcherData = async () => {
|
||||
const response = await fetch(`http://100.118.196.113:8080/api/fetch-config?id=Dispatcher-bof2-constants`);
|
||||
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=Dispatcher-bof2-constants`);
|
||||
if (!response.ok) throw new Error("Cannot get BOF2 dispatcher config");
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const updateBOF2LaneId = async (data: OptionalBOF2LaneIDs) => {
|
||||
const bof2LaneIds = {
|
||||
id: "SightingAmmendA-lane-ids",
|
||||
fields: [
|
||||
{
|
||||
property: "propLaneID1",
|
||||
value: data?.LID1,
|
||||
},
|
||||
{
|
||||
property: "propLaneID2",
|
||||
value: data?.LID2,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const response = await fetch(`${CAM_BASE}/api/update-config?id=SightingAmmendA-lane-ids`, {
|
||||
method: "post",
|
||||
body: JSON.stringify(bof2LaneIds),
|
||||
});
|
||||
if (!response.ok) throw new Error("cannot send to lane IDs");
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const getBOF2LaneId = async () => {
|
||||
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=SightingAmmendA-lane-ids`);
|
||||
if (!response.ok) throw new Error("Canot get Lane Ids");
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const useCameraOutput = () => {
|
||||
const dispatcherQuery = useQuery({
|
||||
queryKey: ["dispatcher"],
|
||||
@@ -95,6 +124,16 @@ export const useCameraOutput = () => {
|
||||
},
|
||||
});
|
||||
|
||||
const bof2LandMutation = useMutation({
|
||||
mutationKey: ["updateBOF2LaneId"],
|
||||
mutationFn: updateBOF2LaneId,
|
||||
});
|
||||
|
||||
const laneIdQuery = useQuery({
|
||||
queryKey: ["getBOF2LaneId"],
|
||||
queryFn: getBOF2LaneId,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (dispatcherQuery.isError) toast.error(dispatcherQuery.error.message);
|
||||
}, [dispatcherQuery?.error?.message, dispatcherQuery.isError]);
|
||||
@@ -103,6 +142,8 @@ export const useCameraOutput = () => {
|
||||
dispatcherQuery,
|
||||
dispatcherMutation,
|
||||
backOfficeDispatcherMutation,
|
||||
bof2LandMutation,
|
||||
laneIdQuery,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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