import type { ColumnDef } from '@tanstack/react-table'; import { format } from 'date-fns'; import { Eye, Pencil, Trash2 } from 'lucide-react'; import { RowActions } from '@/components/row-actions'; import { Badge } from '@/components/ui/badge'; import type { Announcement } from '@/types/announcement'; import { AnnouncementTargetRoleLabels } from '@/types/announcement'; export type { Announcement } from '@/types/announcement'; type CreateColumnsParams = { handleView: (announcement: Announcement) => void; handleEdit: (announcement: Announcement) => void; handleDeleteClick: (announcement: Announcement) => void; canUpdate: boolean; canDelete: boolean; showTargetRoles: boolean; }; export function createAnnouncementColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleView, handleEdit, handleDeleteClick, canUpdate, canDelete, showTargetRoles, } = params; const columns: ColumnDef[] = [ { accessorKey: 'title', header: () => Judul, cell: ({ row }) => ( {row.original.title} ), }, ]; if (showTargetRoles) { columns.push({ accessorKey: 'target_roles', header: () => Ditujukan Untuk, cell: ({ row }) => (
{row.original.target_roles.map((role) => ( {AnnouncementTargetRoleLabels[role]} ))}
), }); } columns.push( { accessorKey: 'creator.profile.full_name', header: () => Dibuat Oleh, cell: ({ row }) => row.original.creator?.profile?.full_name ?? '-', }, { accessorKey: 'created_at', header: () => Tanggal, cell: ({ row }) => format(new Date(row.original.created_at), 'd MMM yyyy, HH:mm'), }, ); columns.push({ id: 'actions', header: () => Aksi, meta: { className: 'w-[100px] text-center', headerClassName: 'w-[100px] text-center', }, cell: ({ row }) => ( , onClick: () => handleView(row.original), }, { label: 'Edit', icon: , show: canUpdate, onClick: () => handleEdit(row.original), }, { label: 'Hapus', icon: ( ), show: canDelete, onClick: () => handleDeleteClick(row.original), }, ]} /> ), }); return columns; }