"use client"; import { ColumnDef } from "@tanstack/react-table"; import { Eye, MoreVertical, MoveDownRight, SquarePen, Trash2, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { format } from "date-fns"; import { Link } from "@/components/navigation"; import { useTranslations } from "next-intl"; import withReactContent from "sweetalert2-react-content"; import Swal from "sweetalert2"; import { useState } from "react"; const useTableColumns = () => { const t = useTranslations("Table"); const MySwal = withReactContent(Swal); const columns: ColumnDef[] = [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!val)} aria-label="Pilih semua pada halaman ini" /> ), cell: ({ row }) => ( row.toggleSelected(!!val)} aria-label="Pilih baris" /> ), enableSorting: false, enableHiding: false, }, { accessorKey: "no", header: t("no", { defaultValue: "No" }), cell: ({ row }) => (

{row.getValue("no")}

), }, { accessorKey: "contentTitle", header: t("title", { defaultValue: "Title" }), cell: ({ row }: { row: { getValue: (key: string) => string } }) => { const title: string = row.getValue("contentTitle"); return ( {title.length > 50 ? `${title.slice(0, 30)}...` : title} ); }, }, { accessorKey: "contentTag", header: t("tag", { defaultValue: "Tag" }), cell: ({ row }) => ( {row.getValue("contentTag")} ), }, { accessorKey: "contentType", header: t("type-content", { defaultValue: "Type Content" }), cell: ({ row }) => ( {row.getValue("contentType")} ), }, { accessorKey: "contentCreatedGroupBy", header: t("source", { defaultValue: "Source" }), cell: ({ row }) => ( {row.getValue("contentCreatedGroupBy")} ), }, { accessorKey: "isPublish", header: "Status", cell: ({ row }) => { const isPublish = row.getValue("isPublish"); return (
); }, }, { accessorKey: "contentCreatedDate", header: t("upload-date", { defaultValue: "Upload Date" }), cell: ({ row }) => { const createdAt = row.getValue("contentCreatedDate") 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: "Actions", enableHiding: false, cell: ({ row }) => { const isDisabled = row.original.isPublish; const [open, setOpen] = useState(false); const handleClick = (e: React.MouseEvent) => { if (e.ctrlKey) { console.log("Ctrl + Click detected"); } // Paksa buka menu meskipun ctrl ditekan setOpen(true); }; return ( Pindah Ke Mediahub ); }, }, ]; return columns; }; export default useTableColumns;