diff --git a/app/api/applications/add/route.ts b/app/api/applications/add/route.ts new file mode 100644 index 0000000..7af7265 --- /dev/null +++ b/app/api/applications/add/route.ts @@ -0,0 +1,33 @@ +import { NextResponse, NextRequest } from "next/server"; +import { PrismaClient } from '@/lib/generated/prisma' + +interface AddRequest { + name: string; + description: string; + icon: string; + publicURL: string; + localURL: string; +} + +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 application = await prisma.application.create({ + data: { + name, + description, + icon, + publicURL, + localURL + } + }); + + return NextResponse.json({ message: "Success", application }); + } catch (error: any) { + return NextResponse.json({ error: error.message }, { status: 500 }); + } +} diff --git a/app/dashboard/applications/Applications.tsx b/app/dashboard/applications/Applications.tsx index b08da73..4a00a76 100644 --- a/app/dashboard/applications/Applications.tsx +++ b/app/dashboard/applications/Applications.tsx @@ -1,3 +1,5 @@ +"use client"; + import { AppSidebar } from "@/components/app-sidebar" import { Breadcrumb, @@ -46,7 +48,24 @@ import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Textarea } from "@/components/ui/textarea" +import { useState } from "react"; +import axios from 'axios'; + 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 add = async () => { + try { + const response = await axios.post('/api/applications/add', { name, description, icon, publicURL, localURL }); + } catch (error: any) { + console.log(error.response.data); + } + } + return ( @@ -88,30 +107,30 @@ export default function Dashboard() {

- + setName(e.target.value)}/>
-