'use client'; import { useMemo } from 'react'; import type { ColumnDef } from '@tanstack/react-table'; import { Badge } from '@/components/ui/badge'; import type { AdministrationUser } from '@/types'; function formatDate(value?: string | null) { if (!value) return '-'; return new Intl.DateTimeFormat('en-IN', { day: '2-digit', month: 'short', year: 'numeric', }).format(new Date(value)); } export function useUserColumns(): ColumnDef[] { return useMemo(() => { return [ { accessorKey: 'first_name', header: 'Name', cell: ({ row }) => ( {[row.original.first_name, row.original.last_name].filter(Boolean).join(' ') || row.original.username} ), }, { accessorKey: 'email', header: 'Email', }, { accessorKey: 'phone_number', header: 'Phone', cell: ({ row }) => row.original.phone_number || '-', }, { accessorKey: 'roles', header: 'Roles', enableSorting: false, cell: ({ row }) => (
{row.original.roles?.length ? ( row.original.roles.map((role) => ( {role.display_name || role.name} )) ) : ( - )}
), }, { accessorKey: 'created_at', header: 'Created', cell: ({ row }) => formatDate(row.original.created_at), }, { accessorKey: 'effective_status', header: 'Status', cell: ({ row }) => ( {row.original.effective_status} ), }, ]; }, []); }