"use client"; import { AppSidebar } from "@/components/app-sidebar"; import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb"; import { Separator } from "@/components/ui/separator"; import { SidebarInset, SidebarProvider, SidebarTrigger, } from "@/components/ui/sidebar"; import { Button } from "@/components/ui/button"; import { Plus, Link, Home, Trash2, LayoutGrid, List } from "lucide-react"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, } from "@/components/ui/pagination"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import Cookies from "js-cookie"; import { useState, useEffect } from "react"; import axios from "axios"; interface Application { id: number; name: string; description?: string; icon?: string; publicURL: string; localURL?: string; server?: string; online: boolean; serverId: number; } interface Server { id: number; name: string; } interface ApplicationsResponse { applications: Application[]; servers: Server[]; maxPage: number; } export default function Dashboard() { const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [icon, setIcon] = useState(""); const [publicURL, setPublicURL] = useState(""); const [localURL, setLocalURL] = useState(""); const [serverId, setServerId] = useState(null); const [currentPage, setCurrentPage] = useState(1); const [maxPage, setMaxPage] = useState(1); const [itemsPerPage, setItemsPerPage] = useState(5); const [applications, setApplications] = useState([]); const [servers, setServers] = useState([]); const [isGridLayout, setIsGridLayout] = useState(false); const [loading, setLoading] = useState(true); useEffect(() => { const savedLayout = Cookies.get('layoutPreference-app'); const layout_bool = savedLayout === 'grid'; setIsGridLayout(layout_bool); setItemsPerPage(layout_bool ? 15 : 5); }, []); const toggleLayout = () => { const newLayout = !isGridLayout; setIsGridLayout(newLayout); Cookies.set('layoutPreference-app', newLayout ? 'grid' : 'standard', { expires: 365, path: '/', sameSite: 'strict' }); setItemsPerPage(newLayout ? 15 : 5); }; const add = async () => { try { await axios.post('/api/applications/add', { name, description, icon, publicURL, localURL, serverId }); getApplications(); } catch (error: any) { console.log(error.response?.data); } } const getApplications = async () => { try { setLoading(true); const response = await axios.post( '/api/applications/get', { page: currentPage, ITEMS_PER_PAGE: itemsPerPage } ); setApplications(response.data.applications); setServers(response.data.servers); setMaxPage(response.data.maxPage); setLoading(false); } catch (error: any) { console.log(error.response?.data); } } useEffect(() => { getApplications(); }, [currentPage, itemsPerPage]); const handlePrevious = () => setCurrentPage(prev => Math.max(1, prev - 1)); const handleNext = () => setCurrentPage(prev => Math.min(maxPage, prev + 1)); const deleteApplication = async (id: number) => { try { await axios.post('/api/applications/delete', { id }); getApplications(); } catch (error: any) { console.log(error.response?.data); } } return (
/ My Infrastructure Applications
Your Applications
{servers.length === 0 ? (

You must first add a server.

) : ( Add an application
setName(e.target.value)}/>