import type { User } from '@admin/types/auth' import type { ColumnDef } from '@tanstack/react-table' import { SortIndicator } from '@admin/components/shared/sort-indicator' import { Avatar, AvatarFallback } from '@admin/components/ui/avatar' import { Badge } from '@admin/components/ui/badge' import { Button } from '@admin/components/ui/button' import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@admin/components/ui/dropdown-menu' import { UserRole } from '@admin/types/auth' import { getUserInitials } from '@admin/utils/user/get-user-initials' import { Edit, MoreHorizontal, ShieldCheck } from 'lucide-react' import { ChangePasswordDialog } from './change-password-dialog' import { DeleteUserDialog } from './delete-user-dialog' import { EditRoleDialog } from './edit-role-dialog' export const columns: ColumnDef[] = [ { accessorKey: 'email', header: ({ column }) => { const sortDirection = column.getIsSorted() return ( ) }, cell: ({ row }) => { const email = row.getValue('email') as string const name = row.original.name return (
{getUserInitials(name || email)}
{name || 'N/A'}
{email}
) } }, { accessorKey: 'emailVerified', header: 'Status', cell: ({ row }) => { const verified = row.getValue('emailVerified') as boolean return ( {verified ? ( Verified ) : ( Unverified )} ) } }, { accessorKey: 'role', header: 'Role', cell: ({ row, table }) => { const role = row.getValue('role') as string const currentUser = table.options.meta?.currentUser const isCurrentUser = currentUser?.email === row.original.email if (isCurrentUser) { return ( {role} (you) ) } return ( {role} ) } }, { accessorKey: 'createdAt', header: ({ column }) => { const sortDirection = column.getIsSorted() return ( ) }, cell: ({ row }) => { const date = new Date(row.getValue('createdAt')) return (
{date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })}
) } }, { id: 'actions', size: 80, enableResizing: false, meta: { width: '80px' }, cell: ({ row, table }) => { const currentUser = table.options.meta?.currentUser const isCurrentUser = currentUser?.id === row.original.id || currentUser?.email === row.original.email const canChangePassword = isCurrentUser || currentUser?.role === UserRole.ADMIN if (!isCurrentUser && !currentUser) return null return (
}> Open menu {!isCurrentUser ? ( ) : null} {canChangePassword ? ( ) : null}
) } } ]