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", { defaultValue: "No" }), cell: ({ row }) => {row.getValue("no")}, }, { accessorKey: "title", header: t("question", { defaultValue: "Question" }), cell: ({ row }) => ( {row.getValue("title")} ), }, { accessorKey: "createdBy", header: t("sender", { defaultValue: "Sender" }), cell: ({ row }) => { const createdBy = row.original.createdBy; // Akses properti category return ( {createdBy?.fullname || "N/A"} ); }, }, { accessorKey: "sendTo", header: t("sendto", { defaultValue: "Sendto" }), cell: ({ row }) => { const sendTo = row.original.sendTo; // Akses properti category return {sendTo?.fullname || "N/A"}; }, }, { accessorKey: "createdAt", header: t("time", { defaultValue: "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}; }, }, { id: "actions", accessorKey: "action", header: t("action", { defaultValue: "Action" }), enableHiding: false, cell: ({ row }) => { return ( View Edit Delete ); }, }, ]; return columns; }; export default useTableColumns;