"use client"; import { ColumnDef } from "@tanstack/react-table"; import { ResourcesDataTable } from "./ResourcesDataTable"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@app/components/ui/dropdown-menu"; import { Button } from "@app/components/ui/button"; import { ArrowRight, ArrowUpDown, MoreHorizontal } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import api from "@app/api"; import CreateResourceForm from "./CreateResourceForm"; import { useState } from "react"; import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog"; import { set } from "zod"; import { formatAxiosError } from "@app/lib/utils"; import { useToast } from "@app/hooks/useToast"; export type ResourceRow = { id: number; name: string; orgId: string; domain: string; site: string; }; type ResourcesTableProps = { resources: ResourceRow[]; orgId: string; }; export default function SitesTable({ resources, orgId }: ResourcesTableProps) { const router = useRouter(); const { toast } = useToast(); const [isCreateModalOpen, setIsCreateModalOpen] = useState(false); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [selectedResource, setSelectedResource] = useState(); const deleteResource = (resourceId: number) => { api.delete(`/resource/${resourceId}`) .catch((e) => { console.error("Error deleting resource", e); toast({ variant: "destructive", title: "Error deleting resource", description: formatAxiosError(e, "Error deleting resource"), }); }) .then(() => { router.refresh(); setIsDeleteModalOpen(false); }); }; const columns: ColumnDef[] = [ { accessorKey: "name", header: ({ column }) => { return ( ); }, }, { accessorKey: "site", header: ({ column }) => { return ( ); }, }, { accessorKey: "domain", header: "Domain", }, { id: "actions", cell: ({ row }) => { const router = useRouter(); const resourceRow = row.original; return ( <>
View settings
); }, }, ]; return ( <> {selectedResource && ( { setIsDeleteModalOpen(val); setSelectedResource(null); }} dialog={

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

Once removed, the resource will no longer be accessible. All targets attached to the resource will be removed.

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

} buttonText="Confirm Delete Resource" onConfirm={async () => deleteResource(selectedResource!.id)} string={selectedResource.name} title="Delete Resource" /> )} { setIsCreateModalOpen(true); }} /> ); }