import { DataTableColumnHeader } from '@/components/data-table-column-header'; import { Button } from '@/components/ui/button'; import { Switch } from '@/components/ui/switch'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; import { UserInfo } from '@/components/user-info'; import { usePermission } from '@/hooks/use-permission'; import userRoutes from '@/routes/user'; import type { User } from '@/types'; import { Link } from '@inertiajs/react'; import type { ColumnDef } from '@tanstack/react-table'; import { KeyRound, Pencil, Trash2 } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { formatCurrency, formatDate } from '@/lib/formatters'; interface ColumnProps { onResetPassword: (user: User) => void; onDelete: (user: User) => void; onToggleStatus: (user: User) => void; } export const getColumns = ({ onResetPassword, onDelete, onToggleStatus }: ColumnProps): ColumnDef[] => [ { accessorKey: "name", header: ({ column }) => ( ), meta: { title: "Nama dan Alamat Surel" }, cell: ({ row }) => { const user = row.original; return (
); } }, { accessorKey: "username", header: ({ column }) => ( ), meta: { title: "Nama Pengguna" }, }, { accessorFn: (row) => row.roles?.map(role => role.name).join(', '), id: "roles", header: ({ column }) => ( ), meta: { title: "Peran" }, cell: ({ row }) => { const roles = row.original.roles; return (
{roles?.map((role) => ( {role.name} ))}
); } }, { accessorFn: (row) => row.profile?.nik, id: "nik", header: ({ column }) => ( ), meta: { title: "NIK" }, }, { accessorFn: (row) => row.profile?.full_name, id: "full_name", header: ({ column }) => ( ), meta: { title: "Nama Lengkap" }, }, { accessorFn: (row) => row.profile?.phone_number, id: "phone_number", header: ({ column }) => ( ), meta: { title: "Nomor Telepon" }, }, { accessorFn: (row) => row.profile?.address, id: "address", header: ({ column }) => ( ), meta: { title: "Alamat" }, cell: ({ row }) => (
{row.original.profile?.address || '-'}
) }, { accessorFn: (row) => `${row.profile?.birth_place}, ${row.profile?.birth_date}`, id: "birth_info", header: ({ column }) => ( ), meta: { title: "Tempat, Tgl Lahir" }, cell: ({ row }) => { const profile = row.original.profile; if (!profile?.birth_place && !profile?.birth_date) return '-'; return ( {profile.birth_place || '-'}, {formatDate(profile.birth_date)} ); } }, { accessorFn: (row) => row.profile?.base_salary, id: "base_salary", header: ({ column }) => ( ), meta: { title: "Gaji Pokok" }, cell: ({ row }) => formatCurrency(row.original.profile?.base_salary || 0) }, { accessorKey: "is_active", header: "Status", meta: { title: "Status" }, cell: ({ row }) => { const user = row.original; const { hasPermission } = usePermission(); return ( onToggleStatus(user)} disabled={!hasPermission('ToggleStatus:User')} /> ); } }, { id: "actions", header: "Aksi", cell: ({ row }) => { const user = row.original; const { hasPermission } = usePermission(); return (
{hasPermission('ResetPassword:User') && (

Reset Kata Sandi

)} {hasPermission('Edit:User') && (

Ubah

)} {hasPermission('Delete:User') && (

Hapus

)}
); }, meta: { title: "Aksi" }, }, ];