import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuTrigger,
} from "@/components/ui/context-menu";
import { Label } from "@/components/ui/label";
import { Progress } from "@/components/ui/progress";
import Session from "@/lib/session";
import { cn } from "@/lib/utils";
import Server from "@/types/server";
import {
Cpu,
HardDrive,
MapPin,
MemoryStick,
Network,
Pencil,
ServerIcon,
Trash,
Wifi,
} from "lucide-react";
import { redirect } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
export function UsageBar({
value,
Icon,
text,
color,
}: {
value: number;
Icon: React.ElementType;
text: string;
color: string;
}) {
return (
);
}
function formatBytes(bytes: number, decimals = 2): string {
if (bytes === 0) return "0 Bytes";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
const size = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
return `${size} ${sizes[i]}`;
}
export function ByteUnit({
value,
Icon,
text,
color,
}: {
value: number;
Icon: React.ElementType;
text: string;
color: string;
}) {
return (
{text}
{formatBytes(value)}
)
}
export default function ServerComponent({
server,
index,
session,
nonInteractive,
}: {
server: Server;
index: number;
session: Session | null;
nonInteractive?: boolean;
}) {
const [deleteAlert, setDeleteAlert] = useState(false);
return (
<>
{
if (nonInteractive) return;
redirect(`/servers/${index}`);
}}
>
{server.name}
{server.status[0].toUpperCase() + server.status.slice(1)}
{" ยท "}
{server.ip}
{server.location && (
{server.location}
)}
Network
{formatBytes(server.network)}
Edit
{if (nonInteractive) return;setDeleteAlert(true)}}
>
Delete
Are you sure?
This action will permanently remove your server from the server
list
Cancel
{
if (nonInteractive) return;
session
?.removeServer(index)
.then(() => {
toast.info("Server successfully deleted");
})
.catch((e) => {
toast.error(
`Error deleting server: ` + e.response.data.message
);
})
}}
>
Delete
>
);
}