mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Edit network
This commit is contained in:
33
app/api/sites/networks/edit/route.ts
Normal file
33
app/api/sites/networks/edit/route.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import prisma from "@/app/prisma";
|
||||
|
||||
interface Body {
|
||||
id: string;
|
||||
name: string;
|
||||
ipv4Subnet?: string;
|
||||
ipv6Subnet?: string;
|
||||
gateway?: string;
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body: Body = await request.json();
|
||||
|
||||
try {
|
||||
const network = await prisma.network.update({
|
||||
where: {
|
||||
id: Number(body.id),
|
||||
},
|
||||
data: {
|
||||
name: body.name,
|
||||
ipv4Subnet: body.ipv4Subnet,
|
||||
ipv6Subnet: body.ipv6Subnet,
|
||||
gateway: body.gateway,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ network }, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error("Error editing network:", error);
|
||||
return NextResponse.json({ error: "Failed to edit network" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import useSite from "@/hooks/useSite"
|
||||
import { useEffect, useState } from "react"
|
||||
import { EditModeToggle } from "@/components/EditModeToggle"
|
||||
import AddNetwork from "@/components/dialogues/AddNetwork"
|
||||
import { Plus } from "lucide-react"
|
||||
import { Plus, Pencil } from "lucide-react"
|
||||
import EditNetwork from "@/components/dialogues/EditNetwork"
|
||||
|
||||
interface SitesPageProps {
|
||||
username: string
|
||||
@@ -57,6 +58,7 @@ export default function SitesPage({ username, name, siteId }: SitesPageProps) {
|
||||
<th>IPv4 Subnet</th>
|
||||
<th>IPv6 Subnet</th>
|
||||
<th>Gateway</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -67,6 +69,12 @@ export default function SitesPage({ username, name, siteId }: SitesPageProps) {
|
||||
<td>{network.ipv4Subnet}</td>
|
||||
<td>{network.ipv6Subnet}</td>
|
||||
<td>{network.gateway}</td>
|
||||
<td>
|
||||
<button className="btn btn-primary btn-sm" onClick={() => document.getElementById('edit_network')?.showModal()}>
|
||||
<Pencil className="w-5 h-5" />
|
||||
</button>
|
||||
<EditNetwork siteId={site.id} network={network} />
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user