Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/Components/ui/Table'; import { Badge } from '@/Components/ui/Badge'; import { Button } from '@/Components/ui/Button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/Components/ui/DropdownMenu'; import { MoreHorizontal, Edit, Trash2 } from 'lucide-react'; import { format } from 'date-fns'; interface User { id: number; name: string; email: string; role: { id: number; name: string; slug: string; }; created_at: string; updated_at: string; } interface UserTableProps { users: User[]; onEdit: (user: User) => void; onDelete: (user: User) => void; } export function UserTable({ users, onEdit, onDelete }: UserTableProps) { const getRoleBadgeVariant = (roleSlug: string) => { switch (roleSlug) { case 'admin': return 'destructive'; case 'user': return 'secondary'; default: return 'outline'; } }; return ( <Table> <TableHeader> <TableRow> <TableHead>Name</TableHead> <TableHead>Email</TableHead> <TableHead>Role</TableHead> <TableHead>Created</TableHead> <TableHead>Last Updated</TableHead> <TableHead className="w-[70px]">Actions</TableHead> </TableRow> </TableHeader> <TableBody> {users.length === 0 ? ( <TableRow> <TableCell colSpan={6} className="text-center py-8 text-muted-foreground"> No users found </TableCell> </TableRow> ) : ( users.map((user) => ( <TableRow key={user.id}> <TableCell className="font-medium">{user.name}</TableCell> <TableCell>{user.email}</TableCell> <TableCell> <Badge variant={getRoleBadgeVariant(user.role.slug)}> {user.role.name} </Badge> </TableCell> <TableCell className="text-muted-foreground"> {format(new Date(user.created_at), 'MMM d, yyyy')} </TableCell> <TableCell className="text-muted-foreground"> {format(new Date(user.updated_at), 'MMM d, yyyy')} </TableCell> <TableCell> <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 onClick={() => onEdit(user)}> <Edit className="mr-2 h-4 w-4" /> Edit </DropdownMenuItem> <DropdownMenuItem onClick={() => onDelete(user)} className="text-destructive" > <Trash2 className="mr-2 h-4 w-4" /> Delete </DropdownMenuItem> </DropdownMenuContent> </DropdownMenu> </TableCell> </TableRow> )) )} </TableBody> </Table> ); } |