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 { Link } from "@/components/navigation"; import { useTranslations } from "next-intl"; import withReactContent from "sweetalert2-react-content"; import Swal from "sweetalert2"; import { error } from "@/config/swal"; import { deleteSchedule } from "@/service/service/schedule/schedule"; const useTableColumns = (props: { selectedTypeSchedule: string }) => { 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("title", { defaultValue: "Title" }), cell: ({ row }: { row: { getValue: (key: string) => string } }) => { const title: string = row.getValue("title"); return ( {title.length > 50 ? `${title.slice(0, 30)}...` : title} ); }, }, { accessorKey: "startDate", header: t("start-date", { defaultValue: "Start Date" }), cell: ({ row }) => ( {row.getValue("startDate")} ), }, { accessorKey: "endDate", header: t("end-date", { defaultValue: "End Date" }), cell: ({ row }) => ( {row.getValue("endDate")} ), }, { accessorKey: "time", header: t("time", { defaultValue: "Time" }), cell: ({ row }: { row: { original: any } }) => { console.log("Row Original Data:", row.original); const { startTime, endTime } = row.original; return ( {startTime || "N/A"} - {endTime || "N/A"} ); }, }, { accessorKey: "address", header: t("address", { defaultValue: "Address" }), cell: ({ row }: { row: { getValue: (key: string) => string } }) => { const address: string = row.getValue("address"); return ( {address.length > 50 ? `${address.slice(0, 40)}...` : address} ); }, }, { accessorKey: "statusName", header: "Status", cell: ({ row }) => { const statusColors: Record = { diterima: "bg-green-100 text-green-600", "menunggu review": "bg-orange-100 text-orange-600", }; // Mengambil `statusName` dari data API const status = row.getValue("statusName") as string; const statusName = status?.toLocaleLowerCase(); // Ubah ke huruf kecil // Gunakan `statusName` untuk pencocokan const statusStyles = statusColors[statusName] || "bg-gray-100 text-gray-600"; return ( {status} {/* Tetap tampilkan nilai asli */} ); }, }, { accessorKey: "speaker", header: t("speaker", { defaultValue: "Speaker" }), cell: ({ row }: { row: { original: any } }) => { console.log("Row Original Data:", row.original); const { speakerTitle, speakerName } = row.original; return ( {speakerTitle || ""} {speakerName || ""} ); }, }, { accessorKey: "uploaderName", header: t("source", { defaultValue: "Source" }), cell: ({ row }) => ( {row.getValue("uploaderName")} ), }, { id: "actions", accessorKey: "action", header: t("action", { defaultValue: "Action" }), enableHiding: false, cell: ({ row }) => { const MySwal = withReactContent(Swal); async function doDelete(id: any) { // loading(); const response = await deleteSchedule(id); if (response?.error) { error(response.message); return false; } success(); } function success() { MySwal.fire({ title: "Sukses", icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: "OK", }).then((result) => { if (result.isConfirmed) { window.location.reload(); } }); } return ( Detail Edit doDelete(row.original.id)} className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" > Delete ); }, }, ]; return columns; }; export default useTableColumns;