- added endpoints for dns and other
This commit is contained in:
@@ -2,6 +2,8 @@ import { toast } from "sonner";
|
||||
import type { SystemValues } from "../../../types/types";
|
||||
import { CAM_BASE } from "../../../utils/config";
|
||||
|
||||
const camBase = import.meta.env.MODE !== "development" ? CAM_BASE : "";
|
||||
|
||||
export async function handleSystemSave(values: SystemValues) {
|
||||
const payload = {
|
||||
// Build JSON
|
||||
@@ -18,7 +20,7 @@ export async function handleSystemSave(values: SystemValues) {
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch(`${CAM_BASE}/api/update-config`, {
|
||||
const response = await fetch(`${camBase}/api/update-config`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -29,11 +31,7 @@ export async function handleSystemSave(values: SystemValues) {
|
||||
|
||||
if (!response.ok) {
|
||||
const text = await response.text().catch(() => "");
|
||||
throw new Error(
|
||||
`HTTP ${response.status} ${response.statusText}${
|
||||
text ? ` - ${text}` : ""
|
||||
}`
|
||||
);
|
||||
throw new Error(`HTTP ${response.status} ${response.statusText}${text ? ` - ${text}` : ""}`);
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
@@ -47,7 +45,7 @@ export async function handleSystemSave(values: SystemValues) {
|
||||
}
|
||||
|
||||
export async function handleSystemRecall() {
|
||||
const url = `${CAM_BASE}/api/fetch-config?id=GLOBAL--Device`;
|
||||
const url = `${camBase}/api/fetch-config?id=GLOBAL--Device`;
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 7000);
|
||||
@@ -61,11 +59,7 @@ export async function handleSystemRecall() {
|
||||
|
||||
if (!response.ok) {
|
||||
const text = await response.text().catch(() => "");
|
||||
throw new Error(
|
||||
`HTTP ${response.status} ${response.statusText}${
|
||||
text ? ` - ${text}` : ""
|
||||
}`
|
||||
);
|
||||
throw new Error(`HTTP ${response.status} ${response.statusText}${text ? ` - ${text}` : ""}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
@@ -76,9 +70,7 @@ export async function handleSystemRecall() {
|
||||
|
||||
const sntpIntervalRaw = data?.propSNTPIntervalMinutes?.value;
|
||||
let sntpInterval =
|
||||
typeof sntpIntervalRaw === "number"
|
||||
? sntpIntervalRaw
|
||||
: Number.parseInt(String(sntpIntervalRaw).trim(), 10);
|
||||
typeof sntpIntervalRaw === "number" ? sntpIntervalRaw : Number.parseInt(String(sntpIntervalRaw).trim(), 10);
|
||||
|
||||
if (!Number.isFinite(sntpInterval)) {
|
||||
sntpInterval = 60;
|
||||
|
||||
@@ -4,21 +4,30 @@ import { useReboots } from "../../../hooks/useReboots";
|
||||
import { timezones } from "./timezones";
|
||||
import SystemFileUpload from "./SystemFileUpload";
|
||||
import type { SystemValues, SystemValuesErrors } from "../../../types/types";
|
||||
import { useSystemConfig } from "../../../hooks/useSystemConfig";
|
||||
import { useDNSSettings, useSystemConfig } from "../../../hooks/useSystemConfig";
|
||||
|
||||
const SystemConfigFields = () => {
|
||||
const { saveSystemSettings, systemSettingsData, saveSystemSettingsLoading } = useSystemConfig();
|
||||
const { softRebootMutation, hardRebootMutation } = useReboots();
|
||||
const { dnsQuery, dnsMutation } = useDNSSettings();
|
||||
console.log(dnsQuery?.data);
|
||||
|
||||
const dnsPrimary = dnsQuery?.data?.propNameServerPrimary?.value;
|
||||
const dnsSecondary = dnsQuery?.data?.propNameServerSecondary?.value;
|
||||
const initialvalues: SystemValues = {
|
||||
deviceName: systemSettingsData?.deviceName ?? "",
|
||||
timeZone: systemSettingsData?.timeZone ?? "",
|
||||
sntpServer: systemSettingsData?.sntpServer ?? "",
|
||||
sntpInterval: systemSettingsData?.sntpInterval ?? 60,
|
||||
serverPrimary: dnsPrimary ?? "",
|
||||
serverSecondary: dnsSecondary ?? "",
|
||||
softwareUpdate: null,
|
||||
};
|
||||
|
||||
const handleSubmit = (values: SystemValues) => saveSystemSettings(values);
|
||||
const handleSubmit = async (values: SystemValues) => {
|
||||
saveSystemSettings(values);
|
||||
await dnsMutation.mutateAsync(values);
|
||||
};
|
||||
|
||||
const validateValues = (values: SystemValues) => {
|
||||
const errors: SystemValuesErrors = {};
|
||||
@@ -102,6 +111,34 @@ const SystemConfigFields = () => {
|
||||
autoComplete="off"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="serverPrimary" className="font-medium whitespace-nowrap md:w-1/2 text-left">
|
||||
Server Primary
|
||||
</label>
|
||||
|
||||
<Field
|
||||
id="serverPrimary"
|
||||
name="serverPrimary"
|
||||
type="text"
|
||||
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||
placeholder="Enter DNS primary address"
|
||||
autoComplete="off"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="serverSecondary" className="font-medium whitespace-nowrap md:w-1/2 text-left">
|
||||
Server Secondary
|
||||
</label>
|
||||
|
||||
<Field
|
||||
id="serverSecondary"
|
||||
name="serverSecondary"
|
||||
type="text"
|
||||
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||
placeholder="Enter DNS secondary address"
|
||||
autoComplete="off"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label htmlFor="sntpInterval" className="font-medium whitespace-nowrap md:w-1/2 text-left">
|
||||
SNTP Interval minutes
|
||||
|
||||
Reference in New Issue
Block a user