CoreControl/app/dashboard/Dashboard.tsx

158 lines
6.5 KiB
TypeScript
Raw Normal View History

2025-04-13 21:10:17 +02:00
import { AppSidebar } from "@/components/app-sidebar";
2025-04-11 14:48:12 +02:00
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
2025-04-13 21:10:17 +02:00
} from "@/components/ui/breadcrumb";
import { Separator } from "@/components/ui/separator";
2025-04-11 14:48:12 +02:00
import {
SidebarInset,
SidebarProvider,
SidebarTrigger,
2025-04-13 21:10:17 +02:00
} from "@/components/ui/sidebar";
import { useEffect, useState } from "react";
import axios from "axios"; // Korrekter Import
2025-04-15 14:49:07 +02:00
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"
import { Activity, Layers, Network, Server } from "lucide-react";
import { Button } from "@/components/ui/button";
2025-04-13 21:10:17 +02:00
interface StatsResponse {
serverCount: number;
applicationCount: number;
onlineApplicationsCount: number;
}
2025-04-15 14:49:07 +02:00
import Link from "next/link";
2025-04-11 14:48:12 +02:00
2025-04-11 14:53:00 +02:00
export default function Dashboard() {
2025-04-13 21:10:17 +02:00
const [serverCount, setServerCount] = useState<number>(0);
const [applicationCount, setApplicationCount] = useState<number>(0);
const [onlineApplicationsCount, setOnlineApplicationsCount] = useState<number>(0);
2025-04-12 19:34:20 +02:00
const getStats = async () => {
try {
2025-04-13 21:10:17 +02:00
const response = await axios.post<StatsResponse>('/api/dashboard/get', {});
setServerCount(response.data.serverCount);
setApplicationCount(response.data.applicationCount);
setOnlineApplicationsCount(response.data.onlineApplicationsCount);
2025-04-12 19:34:20 +02:00
} catch (error: any) {
2025-04-13 21:10:17 +02:00
console.log("Axios error:", error.response?.data);
2025-04-12 19:34:20 +02:00
}
2025-04-13 21:10:17 +02:00
};
2025-04-12 19:34:20 +02:00
useEffect(() => {
getStats();
}, []);
2025-04-11 14:48:12 +02:00
return (
<SidebarProvider>
<AppSidebar />
<SidebarInset>
<header className="flex h-16 shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-[[data-collapsible=icon]]/sidebar-wrapper:h-12">
<div className="flex items-center gap-2 px-4">
<SidebarTrigger className="-ml-1" />
<Separator orientation="vertical" className="mr-2 h-4" />
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem className="hidden md:block">
<BreadcrumbPage>
/
</BreadcrumbPage>
</BreadcrumbItem>
<BreadcrumbSeparator className="hidden md:block" />
<BreadcrumbItem>
<BreadcrumbPage>Dashboard</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
</div>
</header>
2025-04-12 19:34:20 +02:00
<div className="pl-4 pr-4">
2025-04-15 14:49:07 +02:00
<h1 className="text-3xl font-bold tracking-tight">Dashboard</h1>
</div>
<div className="grid gap-6 md:grid-cols-1 lg:grid-cols-2 pl-4 pr-4 pt-6">
<Card className="overflow-hidden">
<CardHeader className="bg-gradient-to-rpb-4">
<div className="flex items-center justify-between">
<CardTitle className="text-lg">Servers</CardTitle>
<Server className="h-5 w-5 text-slate-500" />
2025-04-12 19:34:20 +02:00
</div>
2025-04-15 14:49:07 +02:00
<CardDescription>Manage your server infrastructure</CardDescription>
2025-04-12 19:34:20 +02:00
</CardHeader>
2025-04-15 14:49:07 +02:00
<CardContent className="pt-6">
<div className="text-2xl font-bold">{serverCount}</div>
<p className="text-xs text-muted-foreground">Active servers</p>
</CardContent>
<CardFooter className="border-t p-3">
<Button variant="ghost" size="sm" className="w-full" asChild>
<Link href="/dashboard/servers">View all servers</Link>
</Button>
</CardFooter>
2025-04-12 19:34:20 +02:00
</Card>
2025-04-15 14:49:07 +02:00
<Card className="overflow-hidden">
<CardHeader className="bg-gradient-to-rpb-4">
<div className="flex items-center justify-between">
<CardTitle className="text-lg">Applications</CardTitle>
<Layers className="h-5 w-5 text-slate-500" />
2025-04-12 19:34:20 +02:00
</div>
2025-04-15 14:49:07 +02:00
<CardDescription>Manage your deployed applications</CardDescription>
2025-04-12 19:34:20 +02:00
</CardHeader>
2025-04-15 14:49:07 +02:00
<CardContent className="pt-6">
<div className="text-2xl font-bold">{applicationCount}</div>
<p className="text-xs text-muted-foreground">Running applications</p>
</CardContent>
<CardFooter className="border-t p-3">
<Button variant="ghost" size="sm" className="w-full" asChild>
<Link href="/dashboard/applications">View all applications</Link>
</Button>
</CardFooter>
2025-04-12 19:34:20 +02:00
</Card>
2025-04-15 14:49:07 +02:00
<Card className="overflow-hidden">
<CardHeader className="bg-gradient-to-r pb-4">
<div className="flex items-center justify-between">
<CardTitle className="text-lg">Uptime</CardTitle>
<Activity className="h-5 w-5 text-slate-500" />
2025-04-12 19:34:20 +02:00
</div>
2025-04-15 14:49:07 +02:00
<CardDescription>Monitor your service availability</CardDescription>
2025-04-12 19:34:20 +02:00
</CardHeader>
2025-04-15 14:49:07 +02:00
<CardContent className="pt-6">
<div className="text-2xl font-bold">{onlineApplicationsCount}/{applicationCount}</div>
<p className="text-xs text-muted-foreground">online Applications</p>
</CardContent>
<CardFooter className="border-t p-3">
<Button variant="ghost" size="sm" className="w-full" asChild>
<Link href="/dashboard/uptime">View uptime metrics</Link>
</Button>
</CardFooter>
</Card>
<Card className="overflow-hidden">
<CardHeader className="bg-gradient-to-rpb-4">
<div className="flex items-center justify-between">
<CardTitle className="text-lg">Network</CardTitle>
<Network className="h-5 w-5 text-slate-500" />
</div>
<CardDescription>Manage network configuration</CardDescription>
</CardHeader>
<CardContent className="pt-6">
<div className="text-2xl font-bold">{serverCount + applicationCount}</div>
<p className="text-xs text-muted-foreground">Active connections</p>
</CardContent>
<CardFooter className="border-t p-3">
<Button variant="ghost" size="sm" className="w-full" asChild>
<Link href="/dashboard/network">View network details</Link>
</Button>
</CardFooter>
2025-04-12 19:34:20 +02:00
</Card>
</div>
2025-04-11 14:48:12 +02:00
</SidebarInset>
</SidebarProvider>
2025-04-15 14:49:07 +02:00
)
}