"use client"; import { ColumnDef } from "@tanstack/react-table"; import { ClientsDataTable } from "./ClientsDataTable"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@app/components/ui/dropdown-menu"; import { Button } from "@app/components/ui/button"; import { ArrowRight, ArrowUpDown, ArrowUpRight, Check, MoreHorizontal, X } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog"; import { toast } from "@app/hooks/useToast"; import { formatAxiosError } from "@app/lib/api"; import { createApiClient } from "@app/lib/api"; import { useEnvContext } from "@app/hooks/useEnvContext"; export type ClientRow = { id: number; name: string; subnet: string; // siteIds: string; mbIn: string; mbOut: string; orgId: string; online: boolean; }; type ClientTableProps = { clients: ClientRow[]; orgId: string; }; export default function ClientsTable({ clients, orgId }: ClientTableProps) { const router = useRouter(); const [isCreateModalOpen, setIsCreateModalOpen] = useState(false); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [selectedClient, setSelectedClient] = useState( null ); const [rows, setRows] = useState(clients); const api = createApiClient(useEnvContext()); const deleteClient = (clientId: number) => { api.delete(`/client/${clientId}`) .catch((e) => { console.error("Error deleting client", e); toast({ variant: "destructive", title: "Error deleting client", description: formatAxiosError(e, "Error deleting client") }); }) .then(() => { router.refresh(); setIsDeleteModalOpen(false); const newRows = rows.filter((row) => row.id !== clientId); setRows(newRows); }); }; const columns: ColumnDef[] = [ { accessorKey: "name", header: ({ column }) => { return ( ); } }, // { // accessorKey: "siteName", // header: ({ column }) => { // return ( // // ); // }, // cell: ({ row }) => { // const r = row.original; // return ( // // // // ); // } // }, { accessorKey: "online", header: ({ column }) => { return ( ); }, cell: ({ row }) => { const originalRow = row.original; if (originalRow.online) { return (
Connected
); } else { return (
Disconnected
); } } }, { accessorKey: "mbIn", header: ({ column }) => { return ( ); } }, { accessorKey: "mbOut", header: ({ column }) => { return ( ); } }, { accessorKey: "subnet", header: ({ column }) => { return ( ); } }, { id: "actions", cell: ({ row }) => { const clientRow = row.original; return (
{/* */} {/* */} {/* View settings */} {/* */} {/* */} { setSelectedClient(clientRow); setIsDeleteModalOpen(true); }} > Delete
); } } ]; return ( <> {selectedClient && ( { setIsDeleteModalOpen(val); setSelectedClient(null); }} dialog={

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

Once removed, the client will no longer be able to connect to the site.{" "}

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

} buttonText="Confirm Delete Client" onConfirm={async () => deleteClient(selectedClient!.id)} string={selectedClient.name} title="Delete Client" /> )} { router.push(`/${orgId}/settings/clients/create`); }} /> ); }