- improved ui for dashboard

- added refetch fn
This commit is contained in:
2025-11-24 20:32:52 +00:00
parent 31b6bd45f5
commit 27d2c6a1b9
4 changed files with 32 additions and 15 deletions

View File

@@ -1,13 +1,17 @@
import type { SystemHealthStatus } from "../../../types/types"; import type { SystemHealthStatus } from "../../../types/types";
import Badge from "../../../ui/Badge"; import Badge from "../../../ui/Badge";
import { useGetSystemHealth } from "../hooks/useGetSystemHealth";
const SystemHealth = () => { type SystemHealthProps = {
const { query } = useGetSystemHealth(); startTime: string;
uptime: string;
statuses: SystemHealthStatus[];
isLoading: boolean;
};
const startTime = query?.data?.StartTimeHumane; const SystemHealth = ({ startTime, uptime, statuses, isLoading }: SystemHealthProps) => {
const uptime = query?.data?.UptimeHumane; if (isLoading) {
const statuses = query?.data?.Status; return <span className="text-slate-500">Loading system health</span>;
}
return ( return (
<div className="h-100 md:h-70"> <div className="h-100 md:h-70">

View File

@@ -1,12 +1,20 @@
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 { useGetSystemHealth } from "../hooks/useGetSystemHealth";
import SystemHealth from "./SystemHealth"; import SystemHealth from "./SystemHealth";
const SystemOverview = () => { const SystemOverview = () => {
const { query } = useGetSystemHealth();
const startTime = query?.data?.StartTimeHumane;
const uptime = query?.data?.UptimeHumane;
const statuses = query?.data?.Status;
const isLoading = query?.isLoading;
return ( return (
<Card className="p-4"> <Card className="p-4">
<CardHeader title="System Health" /> <CardHeader title="System Health" refetch={query?.refetch} icon={faArrowsRotate} />
<SystemHealth /> <SystemHealth startTime={startTime} uptime={uptime} statuses={statuses} isLoading={isLoading} />
</Card> </Card>
); );
}; };

View File

@@ -1,7 +1,7 @@
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
const fetchData = async () => { const fetchData = async () => {
const response = await fetch(`http://192.168.202.121/api/system-health`); const response = await fetch(`http://100.115.148.59/api/system-health`);
if (!response.ok) throw new Error("Cannot get System overview"); if (!response.ok) throw new Error("Cannot get System overview");
return response.json(); return response.json();
}; };

View File

@@ -1,22 +1,27 @@
import clsx from "clsx"; import clsx from "clsx";
import StatusIndicators from "./StatusIndicators"; import StatusIndicators from "./StatusIndicators";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import type { IconProp } from "@fortawesome/fontawesome-svg-core";
type CameraOverviewHeaderProps = { type CameraOverviewHeaderProps = {
title?: string; title?: string;
status?: string; status?: string;
refetch?: () => void;
icon?: IconProp;
}; };
const CardHeader = ({ title, status }: CameraOverviewHeaderProps) => { const CardHeader = ({ title, status, icon, refetch }: CameraOverviewHeaderProps) => {
console.log(status);
return ( return (
<div <div
className={clsx( className={clsx(
"w-full border-b border-gray-600 flex flex-row items-center space-x-2 mb-6 relative justify-between", "w-full border-b border-gray-600 flex flex-row items-center space-x-2 mb-6 relative justify-between",
)} )}
> >
<div className="flex items-center space-x-1"> <div className="flex flex-row items-center w-full justify-between">
{/* {icon && <FontAwesomeIcon icon={icon} className="size-4" />} */} <h2 className="flex flex-row text-xl items-center">
{status && <StatusIndicators status={status} />} {status && <StatusIndicators status={status} />}
<h2 className="text-xl">{title}</h2> {title}
</h2>
{icon && <FontAwesomeIcon icon={icon} className="size-4" onClick={refetch} />}
</div> </div>
</div> </div>
); );