import type { ColumnDef } from '@tanstack/react-table'; import { format } from 'date-fns'; import { Pencil, Trash2 } from 'lucide-react'; import { RowActions } from '@/components/row-actions'; import { Badge } from '@/components/ui/badge'; import type { Feedback, FeedbackStatusValue } from '@/types/feedback'; import { FeedbackStatusLabels, FeedbackTypeLabels } from '@/types/feedback'; export type { Feedback } from '@/types/feedback'; type CreateColumnsParams = { handleEdit: (feedback: Feedback) => void; handleDeleteClick: (feedback: Feedback) => void; }; function stripHtml(html: string): string { return html .replace(/<[^>]+>/g, ' ') .replace(/\s+/g, ' ') .trim(); } function statusBadgeVariant( status: FeedbackStatusValue, ): 'outline' | 'secondary' | 'default' { if (status === 'resolved') { return 'default'; } if (status === 'in_review') { return 'secondary'; } return 'outline'; } export function createFeedbackColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick } = params; return [ { accessorKey: 'subject', header: () => Subjek, cell: ({ row }) => { const feedback = row.original; return (

{feedback.subject}

{stripHtml(feedback.message)}

); }, }, { 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 }) => (
{FeedbackStatusLabels[row.original.status]}
), }, { 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: () => handleEdit(row.original), }, { label: 'Hapus', icon: ( ), onClick: () => handleDeleteClick(row.original), }, ]} /> ), }, ]; }