2024-10-19 15:49:16 -04:00
|
|
|
"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 { ArrowUpDown, MoreHorizontal } from "lucide-react";
|
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/navigation";
|
2024-10-19 22:39:46 -04:00
|
|
|
import api from "@app/api";
|
2024-10-19 15:49:16 -04:00
|
|
|
|
|
|
|
export type ResourceRow = {
|
2024-10-26 12:15:03 -04:00
|
|
|
id: number;
|
2024-10-19 15:49:16 -04:00
|
|
|
name: string;
|
|
|
|
orgId: string;
|
2024-10-19 17:01:23 -04:00
|
|
|
domain: string;
|
|
|
|
site: string;
|
2024-10-19 15:49:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
export const columns: ColumnDef<ResourceRow>[] = [
|
|
|
|
{
|
|
|
|
accessorKey: "name",
|
|
|
|
header: ({ column }) => {
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
variant="ghost"
|
|
|
|
onClick={() =>
|
|
|
|
column.toggleSorting(column.getIsSorted() === "asc")
|
|
|
|
}
|
|
|
|
>
|
|
|
|
Name
|
|
|
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2024-10-19 17:01:23 -04:00
|
|
|
{
|
|
|
|
accessorKey: "site",
|
|
|
|
header: ({ column }) => {
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
variant="ghost"
|
|
|
|
onClick={() =>
|
|
|
|
column.toggleSorting(column.getIsSorted() === "asc")
|
|
|
|
}
|
|
|
|
>
|
|
|
|
Site
|
|
|
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
accessorKey: "domain",
|
|
|
|
header: "Domain",
|
|
|
|
},
|
2024-10-19 15:49:16 -04:00
|
|
|
{
|
|
|
|
id: "actions",
|
|
|
|
cell: ({ row }) => {
|
2024-10-19 22:39:46 -04:00
|
|
|
const router = useRouter();
|
|
|
|
|
2024-10-19 15:49:16 -04:00
|
|
|
const resourceRow = row.original;
|
|
|
|
|
2024-10-26 12:15:03 -04:00
|
|
|
const deleteResource = (resourceId: number) => {
|
2024-10-19 22:39:46 -04:00
|
|
|
api.delete(`/resource/${resourceId}`)
|
|
|
|
.catch((e) => {
|
|
|
|
console.error("Error deleting resource", e);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
router.refresh();
|
|
|
|
});
|
2024-11-02 15:44:48 -04:00
|
|
|
};
|
2024-10-19 22:39:46 -04:00
|
|
|
|
2024-10-19 15:49:16 -04:00
|
|
|
return (
|
|
|
|
<DropdownMenu>
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
<Button variant="ghost" className="h-8 w-8 p-0">
|
|
|
|
<span className="sr-only">Open menu</span>
|
|
|
|
<MoreHorizontal className="h-4 w-4" />
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent align="end">
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<Link
|
2024-11-02 15:44:48 -04:00
|
|
|
href={`/${resourceRow.orgId}/settings/resources/${resourceRow.id}`}
|
2024-10-19 15:49:16 -04:00
|
|
|
>
|
|
|
|
View settings
|
|
|
|
</Link>
|
|
|
|
</DropdownMenuItem>
|
2024-10-19 22:39:46 -04:00
|
|
|
<DropdownMenuItem>
|
2024-11-02 15:44:48 -04:00
|
|
|
<button
|
|
|
|
onClick={() => deleteResource(resourceRow.id)}
|
|
|
|
className="text-red-600 hover:text-red-800 hover:underline cursor-pointer"
|
|
|
|
>
|
|
|
|
Delete
|
|
|
|
</button>
|
2024-10-19 22:39:46 -04:00
|
|
|
</DropdownMenuItem>
|
2024-10-19 15:49:16 -04:00
|
|
|
</DropdownMenuContent>
|
|
|
|
</DropdownMenu>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
type ResourcesTableProps = {
|
|
|
|
resources: ResourceRow[];
|
|
|
|
orgId: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function SitesTable({ resources, orgId }: ResourcesTableProps) {
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ResourcesDataTable
|
|
|
|
columns={columns}
|
|
|
|
data={resources}
|
|
|
|
addResource={() => {
|
2024-11-02 15:44:48 -04:00
|
|
|
router.push(`/${orgId}/settings/resources/create`);
|
2024-10-19 15:49:16 -04:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|