import type { ColumnDef } from '@tanstack/react-table'; import { format } from 'date-fns'; import { ClipboardList, Paperclip, Pencil, Trash2 } from 'lucide-react'; import { RowActions } from '@/components/row-actions'; import { index as submissionsIndex } from '@/routes/admin/academic-classes/assignments/submissions'; import type { Assignment } from '@/types/assignment'; export type { Assignment } from '@/types/assignment'; type CreateColumnsParams = { handleEdit: (assignment: Assignment) => void; handleDeleteClick: (assignment: Assignment) => void; canUpdate: boolean; canDelete: boolean; canViewSubmissions: boolean; }; export function createAssignmentColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick, canUpdate, canDelete, canViewSubmissions, } = params; return [ { accessorKey: 'title', header: () => Judul, cell: ({ row }) => ( {row.getValue('title') as string} ), }, { accessorKey: 'course_class.course.name', header: () => Kelas, cell: ({ row }) => { const courseClass = row.original.course_class; if (!courseClass) { return '-'; } return `${courseClass.course?.code ?? ''} ${courseClass.course?.name ?? ''}`; }, }, { accessorKey: 'deadline', header: () => Batas Waktu, cell: ({ row }) => { const deadline = row.getValue('deadline') as string; return format(new Date(deadline), 'd MMM yyyy, HH:mm'); }, }, { accessorKey: 'attachment_name', header: () => Lampiran, cell: ({ row }) => { const assignment = row.original; if (!assignment.attachment_url) { return -; } return ( {assignment.attachment_name} ); }, }, { accessorKey: 'submissions_count', header: () => ( Pengumpulan ), meta: { className: 'w-[120px] text-center', headerClassName: 'w-[120px] text-center', }, cell: ({ row }) => (
{row.original.submissions_count}
), }, { id: 'actions', header: () => Aksi, meta: { className: 'w-[130px] text-center', headerClassName: 'w-[130px] text-center', }, cell: ({ row }) => { const assignment = row.original; return ( , show: canViewSubmissions, href: submissionsIndex.url(assignment.id), }, { label: 'Edit', icon: , show: canUpdate, onClick: () => handleEdit(assignment), }, { label: 'Hapus', icon: ( ), show: canDelete, onClick: () => handleDeleteClick(assignment), }, ]} /> ); }, }, ]; }