diff --git a/app/api/applications/add/route.ts b/app/api/applications/add/route.ts index 7af7265..7c9f110 100644 --- a/app/api/applications/add/route.ts +++ b/app/api/applications/add/route.ts @@ -2,6 +2,7 @@ import { NextResponse, NextRequest } from "next/server"; import { PrismaClient } from '@/lib/generated/prisma' interface AddRequest { + serverId: number; name: string; description: string; icon: string; @@ -14,10 +15,11 @@ const prisma = new PrismaClient(); export async function POST(request: NextRequest) { try { const body: AddRequest = await request.json(); - const { name, description, icon, publicURL, localURL } = body; + const { serverId, name, description, icon, publicURL, localURL } = body; const application = await prisma.application.create({ data: { + serverId, name, description, icon, diff --git a/app/api/applications/get/route.ts b/app/api/applications/get/route.ts index 383e9e3..354f915 100644 --- a/app/api/applications/get/route.ts +++ b/app/api/applications/get/route.ts @@ -19,11 +19,29 @@ export async function POST(request: NextRequest) { orderBy: { name: 'asc' } }); + const serverIds = applications + .map(app => app.serverId) + .filter((id): id is number => id !== null); + + const servers = await prisma.server.findMany({ + where: { + id: { + in: serverIds + } + } + }); + + const applicationsWithServers = applications.map(app => ({ + ...app, + server: servers.find(s => s.id === app.serverId)?.name || 'No server' + })); + const totalCount = await prisma.application.count(); const maxPage = Math.ceil(totalCount / ITEMS_PER_PAGE); return NextResponse.json({ - applications, + applications: applicationsWithServers, + servers, maxPage }); } catch (error: any) { diff --git a/app/dashboard/applications/Applications.tsx b/app/dashboard/applications/Applications.tsx index 5ebb1c6..1a4d214 100644 --- a/app/dashboard/applications/Applications.tsx +++ b/app/dashboard/applications/Applications.tsx @@ -1,6 +1,6 @@ "use client"; -import { AppSidebar } from "@/components/app-sidebar" +import { AppSidebar } from "@/components/app-sidebar"; import { Breadcrumb, BreadcrumbItem, @@ -8,15 +8,15 @@ import { BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, -} from "@/components/ui/breadcrumb" -import { Separator } from "@/components/ui/separator" +} 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 } from "lucide-react" // Importiere Icons +} from "@/components/ui/sidebar"; +import { Button } from "@/components/ui/button"; +import { Plus, Link, Home, Trash2 } from "lucide-react"; import { Card, CardContent, @@ -24,7 +24,7 @@ import { CardFooter, CardHeader, CardTitle, -} from "@/components/ui/card" +} from "@/components/ui/card"; import { Pagination, PaginationContent, @@ -33,7 +33,7 @@ import { PaginationLink, PaginationNext, PaginationPrevious, -} from "@/components/ui/pagination" +} from "@/components/ui/pagination"; import { AlertDialog, AlertDialogAction, @@ -44,10 +44,17 @@ import { 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" +} 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 { useState, useEffect } from "react"; import axios from 'axios'; @@ -58,14 +65,22 @@ export default function Dashboard() { 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 [applications, setApplications] = useState([]); + const [servers, setServers] = useState([]); const add = async () => { try { - const response = await axios.post('/api/applications/add', { name, description, icon, publicURL, localURL }); + await axios.post('/api/applications/add', { + name, + description, + icon, + publicURL, + localURL, + serverId + }); getApplications(); } catch (error: any) { console.log(error.response.data); @@ -76,6 +91,7 @@ export default function Dashboard() { try { const response = await axios.post('/api/applications/get', { page: currentPage }); setApplications(response.data.applications); + setServers(response.data.servers); setMaxPage(response.data.maxPage); } catch (error: any) { console.log(error.response); @@ -86,13 +102,8 @@ export default function Dashboard() { getApplications(); }, [currentPage]); - const handlePrevious = () => { - setCurrentPage(prev => Math.max(1, prev - 1)); - } - - const handleNext = () => { - setCurrentPage(prev => Math.min(maxPage, prev + 1)); - } + const handlePrevious = () => setCurrentPage(prev => Math.max(1, prev - 1)); + const handleNext = () => setCurrentPage(prev => Math.min(maxPage, prev + 1)); const deleteApplication = async (id: number) => { try { @@ -129,48 +140,69 @@ export default function Dashboard() {
-
+
Your Applications - - - - - - - Add an application - -
-
- - setName(e.target.value)}/> + {servers.length === 0 ? ( +

You must first add a server.

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