Compare commits
7 Commits
enhancemen
...
10590e5658
| Author | SHA1 | Date | |
|---|---|---|---|
| 10590e5658 | |||
| f7964d4fc0 | |||
| 2a4afc7eae | |||
| 1810fc04b5 | |||
| d9594546a0 | |||
| dbadc7388c | |||
| 748be931ed |
@@ -1,8 +1,8 @@
|
|||||||
import type { SystemHealthStatus } from "../../../types/types";
|
import type { SystemHealthStatus } from "../../../types/types";
|
||||||
import { useGetSystemHealth } from "../hooks/useGetSystemHealth";
|
import { useGetSystemHealth } from "../hooks/useGetSystemHealth";
|
||||||
import CameraStatus from "./CameraStatus";
|
import CameraStatus from "./cameraStatus/CameraStatus";
|
||||||
import SystemOverview from "./SystemOverview";
|
import SystemHealthCard from "./systemHealth/SystemHealthCard";
|
||||||
import SystemStatusCard from "./SystemStatusCard";
|
import SystemStatusCard from "./systemStatus/SystemStatusCard";
|
||||||
|
|
||||||
const DashboardGrid = () => {
|
const DashboardGrid = () => {
|
||||||
const { query } = useGetSystemHealth();
|
const { query } = useGetSystemHealth();
|
||||||
@@ -37,7 +37,7 @@ const DashboardGrid = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-1 md:grid-rows-2 md:grid-cols-2">
|
<div className="grid grid-cols-1 md:grid-rows-2 md:grid-cols-2">
|
||||||
<SystemStatusCard />
|
<SystemStatusCard />
|
||||||
<SystemOverview
|
<SystemHealthCard
|
||||||
startTime={startTime}
|
startTime={startTime}
|
||||||
uptime={uptime}
|
uptime={uptime}
|
||||||
statuses={statuses}
|
statuses={statuses}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { SystemHealthStatus } from "../../../types/types";
|
import type { SystemHealthStatus } from "../../../../types/types";
|
||||||
import Card from "../../../ui/Card";
|
import Card from "../../../../ui/Card";
|
||||||
import StatusIndicators from "../../../ui/StatusIndicators";
|
import StatusIndicators from "../../../../ui/StatusIndicators";
|
||||||
import { capitalize } from "../../../utils/utils";
|
import { capitalize } from "../../../../utils/utils";
|
||||||
import CameraStatusGridItem from "./CameraStatusGridItem";
|
import CameraStatusGridItem from "./CameraStatusGridItem";
|
||||||
|
|
||||||
type CameraStatusProps = {
|
type CameraStatusProps = {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import type { SystemHealthStatus } from "../../../types/types";
|
import type { SystemHealthStatus } from "../../../../types/types";
|
||||||
import { capitalize } from "../../../utils/utils";
|
import { capitalize } from "../../../../utils/utils";
|
||||||
import SystemHealthModal from "./systemHealthModal/SystemHealthModal";
|
import SystemHealthModal from "../systemHealth/systemHealthModal/SystemHealthModal";
|
||||||
|
|
||||||
type CameraStatusGridItemProps = {
|
type CameraStatusGridItemProps = {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -2,7 +2,7 @@ import { useState } from "react";
|
|||||||
import type { SystemHealthStatus } from "../../../../types/types";
|
import type { SystemHealthStatus } from "../../../../types/types";
|
||||||
import StatusIndicators from "../../../../ui/StatusIndicators";
|
import StatusIndicators from "../../../../ui/StatusIndicators";
|
||||||
import { capitalize } from "../../../../utils/utils";
|
import { capitalize } from "../../../../utils/utils";
|
||||||
import SystemHealthModal from "../systemHealthModal/SystemHealthModal";
|
import SystemHealthModal from "../systemHealth/systemHealthModal/SystemHealthModal";
|
||||||
|
|
||||||
type StatusGridItemProps = {
|
type StatusGridItemProps = {
|
||||||
title: string;
|
title: string;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { SystemHealthStatus } from "../../../types/types";
|
import type { SystemHealthStatus } from "../../../../types/types";
|
||||||
import StatusGridItem from "./statusGridItem/StatusGridItem";
|
import StatusGridItem from "../statusGridItem/StatusGridItem";
|
||||||
|
|
||||||
type SystemHealthProps = {
|
type SystemHealthProps = {
|
||||||
startTime: string;
|
startTime: string;
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import { faArrowsRotate } from "@fortawesome/free-solid-svg-icons";
|
import { faArrowsRotate } from "@fortawesome/free-solid-svg-icons";
|
||||||
import Card from "../../../ui/Card";
|
import Card from "../../../../ui/Card";
|
||||||
import CardHeader from "../../../ui/CardHeader";
|
import CardHeader from "../../../../ui/CardHeader";
|
||||||
|
|
||||||
import SystemHealth from "./SystemHealth";
|
import SystemHealth from "./SystemHealth";
|
||||||
import type { SystemHealthStatus } from "../../../types/types";
|
import type { SystemHealthStatus } from "../../../../types/types";
|
||||||
|
|
||||||
type SystemOverviewProps = {
|
type SystemOverviewProps = {
|
||||||
startTime: string;
|
startTime: string;
|
||||||
@@ -15,7 +15,7 @@ type SystemOverviewProps = {
|
|||||||
refetch: () => void;
|
refetch: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SystemOverview = ({
|
const SystemHealthCard = ({
|
||||||
startTime,
|
startTime,
|
||||||
uptime,
|
uptime,
|
||||||
statuses,
|
statuses,
|
||||||
@@ -39,4 +39,4 @@ const SystemOverview = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SystemOverview;
|
export default SystemHealthCard;
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { SystemHealthStatus } from "../../../../types/types";
|
import type { SystemHealthStatus } from "../../../../../types/types";
|
||||||
import Badge from "../../../../ui/Badge";
|
import Badge from "../../../../../ui/Badge";
|
||||||
import ModalComponent from "../../../../ui/ModalComponent";
|
import ModalComponent from "../../../../../ui/ModalComponent";
|
||||||
import StatusIndicators from "../../../../ui/StatusIndicators";
|
import StatusIndicators from "../../../../../ui/StatusIndicators";
|
||||||
import { capitalize } from "../../../../utils/utils";
|
import { capitalize } from "../../../../../utils/utils";
|
||||||
|
|
||||||
type SystemHealthModalProps = {
|
type SystemHealthModalProps = {
|
||||||
isSystemHealthModalOpen: boolean;
|
isSystemHealthModalOpen: boolean;
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { faDownload } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { useDownloadLogFiles } from "../../../hooks/useDownloadLogFiles";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
|
const DownloadLogButton = () => {
|
||||||
|
const { downloadLogFilesQuery } = useDownloadLogFiles();
|
||||||
|
const isLoading = downloadLogFilesQuery?.isFetching;
|
||||||
|
|
||||||
|
const handleDownloadClick = async () => {
|
||||||
|
try {
|
||||||
|
const blob = await downloadLogFilesQuery?.refetch().then((res) => res.data);
|
||||||
|
if (!blob) {
|
||||||
|
throw new Error("No log file data received");
|
||||||
|
}
|
||||||
|
const url = window.URL.createObjectURL(new Blob([blob]));
|
||||||
|
const link = document.createElement("a");
|
||||||
|
if (!link) {
|
||||||
|
throw new Error("Failed to create download link");
|
||||||
|
} else {
|
||||||
|
link.href = url;
|
||||||
|
link.setAttribute("download", "FlexiAI-0.log");
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.parentNode?.removeChild(link);
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
||||||
|
toast.error(errorMessage);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
className="p-3 border border-gray-700 rounded-lg hover:bg-[#233241] hover:cursor-pointer"
|
||||||
|
onClick={handleDownloadClick}
|
||||||
|
>
|
||||||
|
<div className="flex flex-row gap-2 items-center">
|
||||||
|
<span className="font-bold text-xl bg-slate-700 p-1 px-2 rounded-md">
|
||||||
|
<FontAwesomeIcon icon={faDownload} />
|
||||||
|
</span>
|
||||||
|
<p className="text-lg">{"Download Log Files"}</p>
|
||||||
|
</div>
|
||||||
|
<p className="text-slate-400 italic text-start">{isLoading ? "Downloading..." : "View logs"}</p>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DownloadLogButton;
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { faChartSimple } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
|
||||||
|
type StatusReadsProps = {
|
||||||
|
reads: {
|
||||||
|
totalPending: number;
|
||||||
|
totalActive: number;
|
||||||
|
totalSent: number;
|
||||||
|
totalReceived: number;
|
||||||
|
totalLost: number;
|
||||||
|
sanityCheck: boolean;
|
||||||
|
sanityCheckFormula: string;
|
||||||
|
};
|
||||||
|
isReadsLoading?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const StatusReads = ({ reads, isReadsLoading }: StatusReadsProps) => {
|
||||||
|
const totalPending = reads?.totalPending ?? 0;
|
||||||
|
const totalActive = reads?.totalActive ?? 0;
|
||||||
|
const totalSent = reads?.totalSent ?? 0;
|
||||||
|
const totalLost = reads?.totalLost ?? 0;
|
||||||
|
const totalReceived = reads?.totalReceived ?? 0;
|
||||||
|
|
||||||
|
if (isReadsLoading) {
|
||||||
|
return <p className="text-slate-400">Loading reads…</p>;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className="p-3 border border-gray-700 rounded-lg hover:bg-[#233241]">
|
||||||
|
<div className="flex flex-row gap-2 items-center">
|
||||||
|
<span className="font-bold text-xl bg-slate-700 p-1 px-2 rounded-md">
|
||||||
|
<FontAwesomeIcon icon={faChartSimple} />
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<p className="text-lg">Reads</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="text-slate-400 mt-1">
|
||||||
|
Pending: <span className="text-yellow-500">{totalPending}</span> | Active:{" "}
|
||||||
|
<span className="text-cyan-500">{totalActive}</span> | Lost: <span className="text-red-500">{totalLost}</span>
|
||||||
|
<br />
|
||||||
|
Sent / Received: <span className="text-blue-500">{totalSent}</span> |{" "}
|
||||||
|
<span className="text-green-500">{totalReceived}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default StatusReads;
|
||||||
@@ -1,13 +1,23 @@
|
|||||||
import { useInfoSocket } from "../../../app/context/WebSocketContext";
|
import { useEffect } from "react";
|
||||||
import Card from "../../../ui/Card";
|
import { useInfoSocket } from "../../../../app/context/WebSocketContext";
|
||||||
import CardHeader from "../../../ui/CardHeader";
|
import Card from "../../../../ui/Card";
|
||||||
import StatusItemCPU from "./StatusItems/StatusItemCPU";
|
import CardHeader from "../../../../ui/CardHeader";
|
||||||
|
import DownloadLogButton from "./StatusItems/DownloadLogButton";
|
||||||
import StatusItemLocal from "./StatusItems/StatusItemLocal";
|
import StatusItemLocal from "./StatusItems/StatusItemLocal";
|
||||||
import StatusItemThreads from "./StatusItems/StatusItemThreads";
|
|
||||||
import StatusItemUTC from "./StatusItems/StatusItemUTC";
|
import StatusItemUTC from "./StatusItems/StatusItemUTC";
|
||||||
|
import StatusReads from "./StatusItems/StatusReads";
|
||||||
|
import { useGetStore } from "../../hooks/useGetStore";
|
||||||
|
|
||||||
const SystemStatusCard = () => {
|
const SystemStatusCard = () => {
|
||||||
const { data: stats } = useInfoSocket();
|
const { data: stats } = useInfoSocket();
|
||||||
|
const { storeQuery } = useGetStore();
|
||||||
|
|
||||||
|
const reads = storeQuery?.data;
|
||||||
|
const isReadsLoading = storeQuery.isFetching;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
storeQuery.refetch();
|
||||||
|
}, [reads]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="p-4">
|
<Card className="p-4">
|
||||||
@@ -16,8 +26,8 @@ const SystemStatusCard = () => {
|
|||||||
<div className="grid grid-cols-2 grid-rows-2 gap-4 col-span-2">
|
<div className="grid grid-cols-2 grid-rows-2 gap-4 col-span-2">
|
||||||
<StatusItemUTC statusInfoItem={stats["system-clock-utc"]} description={"UTC Time"} />
|
<StatusItemUTC statusInfoItem={stats["system-clock-utc"]} description={"UTC Time"} />
|
||||||
<StatusItemLocal statusInfoItem={stats["system-clock-local"]} description={"Local Time"} />
|
<StatusItemLocal statusInfoItem={stats["system-clock-local"]} description={"Local Time"} />
|
||||||
<StatusItemCPU statusInfoItem={stats["memory-cpu-status"]} description={"CPU"} />
|
<DownloadLogButton />
|
||||||
<StatusItemThreads statusInfoItem={stats["thread-count"]} description={"Threads"} />
|
<StatusReads reads={reads} isReadsLoading={isReadsLoading} />
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-slate-500">Loading system status…</span>
|
<span className="text-slate-500">Loading system status…</span>
|
||||||
20
src/features/dashboard/hooks/useDownloadLogFiles.ts
Normal file
20
src/features/dashboard/hooks/useDownloadLogFiles.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { CAMBASE } from "../../../utils/config";
|
||||||
|
|
||||||
|
const getDownloadLogFiles = async () => {
|
||||||
|
const response = await fetch(`${CAMBASE}/LogView/download?filename=FlexiAI-0.log`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to download log files");
|
||||||
|
}
|
||||||
|
return response.blob();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDownloadLogFiles = () => {
|
||||||
|
const downloadLogFilesQuery = useQuery({
|
||||||
|
queryKey: ["downloadLogFiles"],
|
||||||
|
queryFn: getDownloadLogFiles,
|
||||||
|
enabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
return { downloadLogFilesQuery };
|
||||||
|
};
|
||||||
19
src/features/dashboard/hooks/useGetStore.ts
Normal file
19
src/features/dashboard/hooks/useGetStore.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { CAMBASE } from "../../../utils/config";
|
||||||
|
|
||||||
|
const getStoreData = async () => {
|
||||||
|
const response = await fetch(`${CAMBASE}/Store0/diagnostics-json`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Network response was not ok");
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetStore = () => {
|
||||||
|
const storeQuery = useQuery({
|
||||||
|
queryKey: ["storeData"],
|
||||||
|
queryFn: getStoreData,
|
||||||
|
// refetchInterval: 10 * 60 * 1000,
|
||||||
|
});
|
||||||
|
return { storeQuery };
|
||||||
|
};
|
||||||
25
src/features/settings/components/Settings.tsx
Normal file
25
src/features/settings/components/Settings.tsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { Tabs, Tab, TabList, TabPanel } from "react-tabs";
|
||||||
|
import "react-tabs/style/react-tabs.css";
|
||||||
|
import Card from "../../../ui/Card";
|
||||||
|
import SystemConfig from "./SystemConfig";
|
||||||
|
import CardHeader from "../../../ui/CardHeader";
|
||||||
|
|
||||||
|
const Settings = () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Tabs>
|
||||||
|
<TabList>
|
||||||
|
<Tab>Systems</Tab>
|
||||||
|
</TabList>
|
||||||
|
<TabPanel>
|
||||||
|
<Card className="p-4">
|
||||||
|
<CardHeader title="System Configuration" />
|
||||||
|
<SystemConfig />
|
||||||
|
</Card>
|
||||||
|
</TabPanel>
|
||||||
|
</Tabs>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Settings;
|
||||||
133
src/features/settings/components/SystemConfig.tsx
Normal file
133
src/features/settings/components/SystemConfig.tsx
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import { Formik, Form, Field } from "formik";
|
||||||
|
import { useSystemSettings } from "../hooks/useSystemSettings";
|
||||||
|
import type { SystemSettings } from "../../../types/types";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
|
const SystemConfig = () => {
|
||||||
|
const { systemSettingsQuery, systemSettingsMutation } = useSystemSettings();
|
||||||
|
|
||||||
|
const timeZoneOptions = systemSettingsQuery?.data?.propLocalTimeZone?.accepted;
|
||||||
|
const timeZoneOpts = timeZoneOptions?.split(",").map((option: string) => option.trim().replace(/\[|\]/g, ""));
|
||||||
|
const timeSourceOptions = systemSettingsQuery?.data?.propTimeSource?.accepted;
|
||||||
|
const timeSourceOpts = timeSourceOptions?.split(",").map((option: string) => option.trim().replace(/\[|\]/g, ""));
|
||||||
|
const deviceName = systemSettingsQuery?.data?.propDeviceName?.value;
|
||||||
|
const timeZone = systemSettingsQuery?.data?.propLocalTimeZone?.value;
|
||||||
|
const SNTPServer = systemSettingsQuery?.data?.propSNTPServer?.value;
|
||||||
|
const SNTPInterval = systemSettingsQuery?.data?.propSNTPIntervalMinutes?.value;
|
||||||
|
const timeSource = systemSettingsQuery?.data?.propTimeSource?.value;
|
||||||
|
// const primaryServer = systemSettingsQuery?.data?.propPrimaryDNSServer?.value;
|
||||||
|
// const secondaryServer = systemSettingsQuery?.data?.propSecondaryDNSServer?.value;
|
||||||
|
|
||||||
|
const initialValues = {
|
||||||
|
deviceName: deviceName ?? "",
|
||||||
|
timeZone: timeZone ?? "",
|
||||||
|
localTimeZone: timeZone ?? "",
|
||||||
|
SNTPServer: SNTPServer ?? "",
|
||||||
|
SNTPInterval: SNTPInterval ?? 60,
|
||||||
|
SNTPIntervalMinutes: SNTPInterval ?? 60,
|
||||||
|
primaryServer: "",
|
||||||
|
secondaryServer: "",
|
||||||
|
timeSource: timeSource ?? "",
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async (values: SystemSettings) => {
|
||||||
|
const result = await systemSettingsMutation.mutateAsync(values);
|
||||||
|
console.log(result);
|
||||||
|
if (result.id) {
|
||||||
|
toast.success("System settings updated successfully");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Formik initialValues={initialValues} onSubmit={handleSubmit} enableReinitialize>
|
||||||
|
<Form>
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="deviceName">Device Name</label>
|
||||||
|
<Field
|
||||||
|
name="deviceName"
|
||||||
|
type="text"
|
||||||
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||||
|
placeholder="Enter device name"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="timeZone">Timezone</label>
|
||||||
|
<Field
|
||||||
|
name="timeZone"
|
||||||
|
as="select"
|
||||||
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs bg-[#253445] "
|
||||||
|
autoComplete="off"
|
||||||
|
>
|
||||||
|
{timeZoneOpts?.map((option: string) => (
|
||||||
|
<option key={option} value={option}>
|
||||||
|
{option}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="timeSource">Time Source</label>
|
||||||
|
<Field
|
||||||
|
name="timeSource"
|
||||||
|
as="select"
|
||||||
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs bg-[#253445] "
|
||||||
|
autoComplete="off"
|
||||||
|
>
|
||||||
|
{timeSourceOpts?.map((option: string) => (
|
||||||
|
<option key={option} value={option}>
|
||||||
|
{option}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="SNTPServer">SNTP Server</label>
|
||||||
|
<Field
|
||||||
|
name="SNTPServer"
|
||||||
|
type="text"
|
||||||
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||||
|
placeholder="Enter SNTP server"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="SNTPInterval">SNTP Interval</label>
|
||||||
|
<Field
|
||||||
|
name="SNTPInterval"
|
||||||
|
type="number"
|
||||||
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||||
|
placeholder="Enter SNTP interval"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="primaryServer">Primary DNS Server</label>
|
||||||
|
<Field
|
||||||
|
name="primaryServer"
|
||||||
|
type="text"
|
||||||
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||||
|
placeholder="Enter primary DNS server"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="secondaryServer">Secondary DNS Server</label>
|
||||||
|
<Field
|
||||||
|
name="secondaryServer"
|
||||||
|
type="text"
|
||||||
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||||
|
placeholder="Enter secondary DNS server"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button type="submit" className="px-4 py-2 bg-green-700 text-white rounded-lg">
|
||||||
|
Save Settings
|
||||||
|
</button>
|
||||||
|
</Form>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SystemConfig;
|
||||||
54
src/features/settings/hooks/useSystemSettings.ts
Normal file
54
src/features/settings/hooks/useSystemSettings.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||||
|
import { CAMBASE } from "../../../utils/config";
|
||||||
|
import type { SystemSettings } from "../../../types/types";
|
||||||
|
const camBase = import.meta.env.MODE !== "development" ? CAMBASE : "";
|
||||||
|
|
||||||
|
const fetchSystemSettings = async () => {
|
||||||
|
const response = await fetch(`${camBase}/api/fetch-config?id=GLOBAL--Device`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to fetch system settings");
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
const postSystemSettings = async (settings: SystemSettings) => {
|
||||||
|
const systemSettingConfig = {
|
||||||
|
id: "GLOBAL--Device",
|
||||||
|
fields: [
|
||||||
|
{ property: "propDeviceName", value: settings.deviceName },
|
||||||
|
{ property: "propSNTPServer", value: settings.SNTPServer },
|
||||||
|
{
|
||||||
|
property: "propSNTPIntervalMinutes",
|
||||||
|
value: Number(settings.SNTPIntervalMinutes),
|
||||||
|
},
|
||||||
|
{ property: "propLocalTimeZone", value: settings.localTimeZone },
|
||||||
|
{ property: "propTimeSource", value: settings.timeSource },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(`${camBase}/api/update-config`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(systemSettingConfig),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to update system settings");
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useSystemSettings = () => {
|
||||||
|
const systemSettingsQuery = useQuery({
|
||||||
|
queryKey: ["systemSettings"],
|
||||||
|
queryFn: fetchSystemSettings,
|
||||||
|
});
|
||||||
|
|
||||||
|
const systemSettingsMutation = useMutation({
|
||||||
|
mutationKey: ["updateSystemSettings"],
|
||||||
|
mutationFn: postSystemSettings,
|
||||||
|
});
|
||||||
|
|
||||||
|
return { systemSettingsQuery, systemSettingsMutation };
|
||||||
|
};
|
||||||
@@ -2,12 +2,14 @@ import { createRootRoute, Outlet } from "@tanstack/react-router";
|
|||||||
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
|
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
|
||||||
import Header from "../ui/Header";
|
import Header from "../ui/Header";
|
||||||
import Footer from "../ui/Footer";
|
import Footer from "../ui/Footer";
|
||||||
|
import { Toaster } from "sonner";
|
||||||
|
|
||||||
const RootLayout = () => (
|
const RootLayout = () => (
|
||||||
<>
|
<>
|
||||||
<Header />
|
<Header />
|
||||||
<main className="p-4 min-h-screen">
|
<main className="p-4 min-h-screen">
|
||||||
<Outlet />
|
<Outlet />
|
||||||
|
<Toaster />
|
||||||
</main>
|
</main>
|
||||||
<Footer />
|
<Footer />
|
||||||
<TanStackRouterDevtools position="bottom-right" />
|
<TanStackRouterDevtools position="bottom-right" />
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { createFileRoute } from "@tanstack/react-router";
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
import CameraGrid from "../features/cameras/components/CameraGrid";
|
import CameraGrid from "../features/cameras/components/CameraGrid";
|
||||||
import { Toaster } from "sonner";
|
|
||||||
|
|
||||||
export const Route = createFileRoute("/baywatch")({
|
export const Route = createFileRoute("/baywatch")({
|
||||||
component: RouteComponent,
|
component: RouteComponent,
|
||||||
@@ -10,7 +9,6 @@ function RouteComponent() {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<CameraGrid />
|
<CameraGrid />
|
||||||
<Toaster />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,5 @@ export const Route = createFileRoute("/")({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function HomePage() {
|
function HomePage() {
|
||||||
return (
|
return <DashboardGrid />;
|
||||||
<div>
|
|
||||||
<DashboardGrid />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
|
import Settings from "../features/settings/components/Settings";
|
||||||
|
|
||||||
export const Route = createFileRoute('/settings')({
|
export const Route = createFileRoute("/settings")({
|
||||||
component: RouteComponent,
|
component: RouteComponent,
|
||||||
})
|
});
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
return <div>Hello "/settings"!</div>
|
return (
|
||||||
|
<div>
|
||||||
|
<Settings />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,3 +175,13 @@ export type ColourDetectionPayload = {
|
|||||||
cameraFeedID: "A" | "B" | "C";
|
cameraFeedID: "A" | "B" | "C";
|
||||||
regions: ColourData[];
|
regions: ColourData[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type SystemSettings = {
|
||||||
|
deviceName: string;
|
||||||
|
localTimeZone: string;
|
||||||
|
timeSource: string;
|
||||||
|
SNTPServer: string;
|
||||||
|
SNTPIntervalMinutes: number;
|
||||||
|
primaryServer?: string;
|
||||||
|
secondaryServer?: string;
|
||||||
|
};
|
||||||
|
|||||||
@@ -13,4 +13,12 @@ export default defineConfig({
|
|||||||
react(),
|
react(),
|
||||||
tailwindcss(),
|
tailwindcss(),
|
||||||
],
|
],
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
"/api": {
|
||||||
|
target: "http://100.115.125.56",
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user