"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { DataTable } from "@/components/common/data-table"; import { Input } from "@/components/ui/input"; import { Badge } from "@/components/ui/badge"; import { useOrganizations, useDeleteOrganization, } from "@/hooks/use-master-data"; import { ColumnDef } from "@tanstack/react-table"; import { Pencil, Trash, Plus, Search, MoreHorizontal } from "lucide-react"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Organization } from "@/types/organization"; import { OrganizationDialog } from "@/components/admin/organization-dialog"; // Organization role types for display const ORGANIZATION_ROLES = [ { value: "1", label: "Owner" }, { value: "2", label: "Designer" }, { value: "3", label: "Consultant" }, { value: "4", label: "Contractor" }, { value: "5", label: "Third Party" }, ] as const; export default function OrganizationsPage() { const [search, setSearch] = useState(""); const { data: organizations, isLoading } = useOrganizations({ search: search || undefined, }); const deleteOrg = useDeleteOrganization(); const [dialogOpen, setDialogOpen] = useState(false); const [selectedOrganization, setSelectedOrganization] = useState(null); const columns: ColumnDef[] = [ { accessorKey: "organizationCode", header: "Code", cell: ({ row }) => ( {row.original.organizationCode} ), }, { accessorKey: "organizationName", header: "Name" }, { accessorKey: "roleId", header: "Role", cell: ({ row }) => { const roleId = row.getValue("roleId") as number; const role = ORGANIZATION_ROLES.find( (r) => r.value === roleId?.toString() ); return role ? role.label : "-"; }, }, { accessorKey: "isActive", header: "Status", cell: ({ row }) => ( {row.original.isActive ? "Active" : "Inactive"} ), }, { accessorKey: "createdAt", header: "Created At", cell: ({ row }) => { if (!row.original.createdAt) return "-"; return new Date(row.original.createdAt).toLocaleDateString("en-GB"); }, }, { id: "actions", header: "Actions", cell: ({ row }) => { const org = row.original; return ( { setSelectedOrganization(org); setDialogOpen(true); }} > Edit { if (confirm(`Delete organization ${org.organizationCode}?`)) { deleteOrg.mutate(org.id); } }} > Delete ); }, }, ]; return (

Organizations

Manage project organizations system-wide

setSearch(e.target.value)} className="pl-8 bg-background" />
{isLoading ? (
Loading organizations...
) : ( )}
); }