"use client"; import { ColumnDef } from "@tanstack/react-table"; import { SitesDataTable } from "./SitesDataTable"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@app/components/ui/dropdown-menu"; 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"; import { AxiosResponse } from "axios"; import { useState } from "react"; import CreateSiteForm from "./CreateSiteForm"; import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog"; export type SiteRow = { id: number; nice: string; name: string; mbIn: number; mbOut: number; orgId: string; }; type SitesTableProps = { sites: SiteRow[]; orgId: string; }; export default function SitesTable({ sites, orgId }: SitesTableProps) { const router = useRouter(); const [isCreateModalOpen, setIsCreateModalOpen] = useState(false); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [selectedSite, setSelectedSite] = useState(null); const callApi = async () => { const res = await api.put>(`/newt`); console.log(res); }; const deleteSite = (siteId: number) => { api.delete(`/site/${siteId}`) .catch((e) => { console.error("Error deleting site", e); }) .then(() => { router.refresh(); setIsDeleteModalOpen(false); }); }; const columns: ColumnDef[] = [ { accessorKey: "name", header: ({ column }) => { return ( ); }, }, { accessorKey: "nice", header: ({ column }) => { return ( ); }, }, { accessorKey: "mbIn", header: "MB In", }, { accessorKey: "mbOut", header: "MB Out", }, { id: "actions", cell: ({ row }) => { const router = useRouter(); const siteRow = row.original; return ( View settings ); }, }, ]; return ( <> {selectedSite && ( { setIsDeleteModalOpen(val); setSelectedSite(null); }} dialog={

Are you sure you want to remove the site{" "} {selectedSite?.name || selectedSite?.id}{" "} from the organization?

Once removed, the site will no longer be accessible.{" "} All resources and targets associated with the site will also be removed.

To confirm, please type the name of the site below.

} buttonText="Confirm delete site" onConfirm={async () => deleteSite(selectedSite!.id)} string={selectedSite.name} title="Delete site" /> )} { setIsCreateModalOpen(true); }} /> ); }