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 { StatusBadge } from '@/components/status-badge'; import { Badge } from '@/components/ui/badge'; import type { Feedback } from '@/types/feedback'; import { FeedbackTypeLabels } from '@/types/feedback'; export type { Feedback } from '@/types/feedback'; type StatusOption = { value: string; label: string }; type CreateColumnsParams = { handleView: (feedback: Feedback) => void; handleEdit: (feedback: Feedback) => void; handleDeleteClick: (feedback: Feedback) => void; handleStatusChange: (feedback: Feedback, status: string) => void; statuses: StatusOption[]; canUpdateStatus: boolean; canUpdate: boolean; canDelete: boolean; }; export const FeedbackStatusVariants: Record< string, 'default' | 'secondary' | 'destructive' | 'outline' > = { submitted: 'outline', in_review: 'secondary', resolved: 'default', }; export function createFeedbackColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleView, handleEdit, handleDeleteClick, handleStatusChange, statuses, canUpdateStatus, canUpdate, canDelete, } = params; return [ { accessorKey: 'subject', header: () => Subjek, }, { accessorKey: 'type', header: () => Jenis, meta: { className: 'w-[110px] text-center', headerClassName: 'w-[110px] text-center', }, cell: ({ row }) => (
{FeedbackTypeLabels[row.original.type]}
), }, { accessorKey: 'status', header: () => Status, meta: { className: 'w-[130px] text-center', headerClassName: 'w-[130px] text-center', }, cell: ({ row }) => (
handleStatusChange(row.original, status) } disabled={!canUpdateStatus} />
), }, { accessorKey: 'user.profile.full_name', header: () => Dibuat Oleh, cell: ({ row }) => row.original.user?.profile?.full_name ?? '-', }, { accessorKey: 'handler.profile.full_name', header: () => Ditindaklanjuti Oleh, cell: ({ row }) => row.original.handler?.profile?.full_name ?? '-', }, { accessorKey: 'created_at', header: () => Dikirim, cell: ({ row }) => format(new Date(row.original.created_at), 'd MMM yyyy, HH:mm'), }, { 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), }, ]} /> ), }, ]; }