'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'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog'; import { Skeleton } from '@/components/ui/skeleton'; // 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); // Stats for Delete Dialog const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); const [orgToDelete, setOrgToDelete] = useState(null); const handleDeleteClick = (org: Organization) => { setOrgToDelete(org); setDeleteDialogOpen(true); }; const confirmDelete = () => { if (orgToDelete) { deleteOrg.mutate(orgToDelete.uuid, { onSuccess: () => { setDeleteDialogOpen(false); setOrgToDelete(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 handleDeleteClick(org)}> Delete ); }, }, ]; return (

Organizations

Manage project organizations system-wide

setSearch(e.target.value)} className="pl-8 bg-background" />
{isLoading ? (
{[1, 2, 3, 4, 5].map((i) => (
))}
) : ( )} Are you absolutely sure? This action cannot be undone. This will permanently delete the organization {orgToDelete?.organizationName} and remove it from the system. Cancel {deleteOrg.isPending ? 'Deleting...' : 'Delete Organization'}
); }