import { RowActions } from '@/components/row-actions'; import type { ColumnDef } from '@tanstack/react-table'; import { Key, Pencil, Trash2 } from 'lucide-react'; export type Administrator = { id: number; username: string; email: string; profile: { full_name: string; phone_number: string; gender: string } | null; roles: { id: number; name: string }[]; }; type CreateColumnsParams = { handleEdit: (admin: Administrator) => void; handleDeleteClick: (admin: Administrator) => void; handleResetPassword: (admin: Administrator) => void; }; export function createAdministratorColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick, handleResetPassword } = params; return [ { accessorKey: 'profile.full_name', header: () => Nama Lengkap, cell: ({ row }) => row.original.profile?.full_name ?? '-', }, { id: 'account', header: () => Akun, cell: ({ row }) => (
{row.original.username} {row.original.email}
), }, { id: 'role', header: () => Role, cell: ({ row }) => row.original.roles?.[0]?.name ?? '-', }, { accessorKey: 'profile.phone_number', header: () => Nomor Telepon, cell: ({ row }) => row.original.profile?.phone_number ?? '-', }, { accessorKey: 'profile.gender', header: () => Jenis Kelamin, cell: ({ row }) => { const gender = row.original.profile?.gender; return gender === 'male' ? 'Laki-laki' : gender === 'female' ? 'Perempuan' : '-'; }, }, { id: 'actions', header: () => Aksi, meta: { className: 'w-[100px] text-center', headerClassName: 'w-[100px] text-center', }, cell: ({ row }) => { const admin = row.original; return ( , onClick: () => handleEdit(admin), }, { label: 'Reset Kata Sandi', icon: , onClick: () => handleResetPassword(admin), }, { label: 'Hapus', icon: , onClick: () => handleDeleteClick(admin), }, ]} /> ); }, }, ]; }