mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-31 15:09:39 +02:00
Add delete
This commit is contained in:
parent
99daa2220e
commit
ed07150528
3 changed files with 37 additions and 3 deletions
|
@ -12,6 +12,7 @@ import { Button } from "@app/components/ui/button";
|
|||
import { ArrowUpDown, MoreHorizontal } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import api from "@app/api";
|
||||
|
||||
export type ResourceRow = {
|
||||
id: string;
|
||||
|
@ -61,8 +62,20 @@ export const columns: ColumnDef<ResourceRow>[] = [
|
|||
{
|
||||
id: "actions",
|
||||
cell: ({ row }) => {
|
||||
const router = useRouter();
|
||||
|
||||
const resourceRow = row.original;
|
||||
|
||||
const deleteResource = (resourceId: string) => {
|
||||
api.delete(`/resource/${resourceId}`)
|
||||
.catch((e) => {
|
||||
console.error("Error deleting resource", e);
|
||||
})
|
||||
.then(() => {
|
||||
router.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
@ -79,6 +92,9 @@ export const columns: ColumnDef<ResourceRow>[] = [
|
|||
View settings
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<button onClick={() => deleteResource(resourceRow.id)} className="text-red-600 hover:text-red-800 hover:underline cursor-pointer">Delete</button>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
|
|
|
@ -12,9 +12,11 @@ import { Button } from "@app/components/ui/button";
|
|||
import { ArrowUpDown, MoreHorizontal } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import api from "@app/api";
|
||||
|
||||
export type SiteRow = {
|
||||
id: string;
|
||||
id: number;
|
||||
nice: string;
|
||||
name: string;
|
||||
mbIn: number;
|
||||
mbOut: number;
|
||||
|
@ -39,7 +41,7 @@ export const columns: ColumnDef<SiteRow>[] = [
|
|||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "id",
|
||||
accessorKey: "nice",
|
||||
header: ({ column }) => {
|
||||
return (
|
||||
<Button
|
||||
|
@ -65,8 +67,20 @@ export const columns: ColumnDef<SiteRow>[] = [
|
|||
{
|
||||
id: "actions",
|
||||
cell: ({ row }) => {
|
||||
const router = useRouter();
|
||||
|
||||
const siteRow = row.original;
|
||||
|
||||
const deleteSite = (siteId: number) => {
|
||||
api.delete(`/site/${siteId}`)
|
||||
.catch((e) => {
|
||||
console.error("Error deleting site", e);
|
||||
})
|
||||
.then(() => {
|
||||
router.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
@ -83,6 +97,9 @@ export const columns: ColumnDef<SiteRow>[] = [
|
|||
View settings
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<button onClick={() => deleteSite(siteRow.id)} className="text-red-600 hover:text-red-800 hover:underline cursor-pointer">Delete</button>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
|
|
|
@ -23,7 +23,8 @@ export default async function Page({ params }: SitesPageProps) {
|
|||
const siteRows: SiteRow[] = sites.map((site) => {
|
||||
return {
|
||||
name: site.name,
|
||||
id: site.niceId.toString(),
|
||||
id: site.siteId,
|
||||
nice: site.niceId.toString(),
|
||||
mbIn: site.megabytesIn || 0,
|
||||
mbOut: site.megabytesOut || 0,
|
||||
orgId: params.orgId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue