import type { ColumnDef } from '@tanstack/react-table'; import { router } from '@inertiajs/react'; import { ArrowUpDown, KeyRound, Pencil, Trash2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Switch } from '@/components/ui/switch'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from '@/components/ui/tooltip'; export type Employee = { id: number; email: string; username: string; is_active: boolean; user_profile: { full_name: string; phone_number: string | null; } | null; employee: { join_date: string; employment_status: string; base_salary: number; } | null; }; function getEmploymentStatusLabel(status: string): string { const labels: Record = { full_time: 'Full Time', part_time: 'Part Time', contract: 'Kontrak', internship: 'Magang', resigned: 'Keluar', }; return labels[status] ?? status; } function formatCurrency(amount: number): string { return new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', minimumFractionDigits: 0, }).format(amount); } type CreateColumnsParams = { handleEdit: (employee: Employee) => void; handleDeleteClick: (employee: Employee) => void; handleResetPassword: (employee: Employee) => void; toggleActiveUrl: (id: number) => string; }; export function createEmployeeColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick, handleResetPassword, toggleActiveUrl } = params; return [ { id: 'no', header: () => No, cell: ({ row }) => ( {row.index + 1} ), meta: { className: 'w-[50px] text-center', headerClassName: 'w-[50px] text-center', }, }, { accessorKey: 'user_profile.full_name', id: 'full_name', header: ({ column }) => ( ), cell: ({ row }) => { const employee = row.original; return (
{employee.user_profile?.full_name ?? '-'} {employee.email}
); }, }, { accessorKey: 'username', header: ({ column }) => ( ), cell: ({ row }) => ( {row.getValue('username') as string} ), }, { accessorKey: 'user_profile.phone_number', id: 'phone_number', header: () => No. HP, cell: ({ row }) => { const employee = row.original; return {employee.user_profile?.phone_number ?? '-'}; }, }, { accessorKey: 'employee.employment_status', id: 'employment_status', header: ({ column }) => ( ), cell: ({ row }) => { const employee = row.original; return ( {getEmploymentStatusLabel(employee.employee?.employment_status ?? '')} ); }, }, { accessorKey: 'is_active', header: () => Aktif, meta: { className: 'w-[80px] text-center', headerClassName: 'w-[80px] text-center', }, cell: ({ row }) => { const employee = row.original; return (
{ router.post(toggleActiveUrl(employee.id), {}, { preserveScroll: true, }); }} />
); }, }, { id: 'actions', header: () => Aksi, meta: { className: 'w-[120px] text-center', headerClassName: 'w-[120px] text-center', }, cell: ({ row }) => { const employee = row.original; return (
Edit Reset Kata Sandi Hapus
); }, }, ]; }