import * as React from "react"; import { ColumnDef } from "@tanstack/react-table"; import { Eye, MoreVertical, SquarePen, Trash2 } from "lucide-react"; import { cn } from "@/lib/utils"; import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, DropdownMenuItem, } from "@/components/ui/dropdown-menu"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { format } from "date-fns"; import { Link } from "@/components/navigation"; import { useTranslations } from "next-intl"; const useTableColumns = () => { const t = useTranslations("Table"); // Panggil di dalam hook const columns: ColumnDef[] = [ { accessorKey: "no", header: t("no"), cell: ({ row }) => {row.getValue("no")}, }, { accessorKey: "title", header: t("question"), cell: ({ row }) => ( {row.getValue("title")} ), }, { accessorKey: "commentFromUserName", header: t("sender"), cell: ({ row }) => ( {row.getValue("commentFromUserName")} ), }, { accessorKey: "type", header: t("type"), cell: ({ row }) => { const type = row.original.type; // Akses properti category return {type?.name || "N/A"}; }, }, { accessorKey: "createdAt", header: t("time"), cell: ({ row }) => { const createdAt = row.getValue("createdAt") as | string | number | undefined; const formattedDate = createdAt && !isNaN(new Date(createdAt).getTime()) ? format(new Date(createdAt), "dd-MM-yyyy HH:mm:ss") : "-"; return {formattedDate}; }, }, { accessorKey: "isActive", header: "Status", cell: ({ row }) => { const isActive = row.getValue("isActive") as boolean; // Ambil nilai isActive const status = isActive ? "Open" : "Closed"; // Tentukan teks berdasarkan isActive const statusStyles = isActive ? "bg-green-100 text-green-600" // Gaya untuk "Open" : "bg-red-100 text-red-600"; // Gaya untuk "Closed" return ( {status} ); }, }, { id: "actions", accessorKey: "action", header: t("action"), enableHiding: false, cell: ({ row }) => { return ( View ); }, }, ]; return columns; }; export default useTableColumns;