import * as React from "react"; import { ColumnDef } from "@tanstack/react-table"; import { CheckSquare2, 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 { formatDateToIndonesian } from "@/utils/globals"; import { Link } from "@/i18n/routing"; import { closeTicket, deleteTicket, } from "@/service/communication/communication"; import withReactContent from "sweetalert2-react-content"; import { error } from "@/lib/swal"; import Swal from "sweetalert2"; const columns: ColumnDef[] = [ { accessorKey: "no", header: "No", cell: ({ row }) => {row.getValue("no")}, }, { accessorKey: "referenceNumber", header: "Ticket Number", cell: ({ row }) => {row.getValue("referenceNumber")}, }, { accessorKey: "title", header: "Title", cell: ({ row }) => ( {row.getValue("title")} ), }, { accessorKey: "commentFromUserName", header: "Sender", cell: ({ row }) => ( {row.getValue("commentFromUserName")} ), }, { accessorKey: "type", header: "Channel", cell: ({ row }) => { const type = row.getValue("type") as { name: string }; return {type?.name}; }, }, { accessorKey: "createdBy", header: "Operator", cell: ({ row }) => { const createdBy = row.getValue("createdBy") as { fullname: string }; return {createdBy?.fullname}; }, }, { accessorKey: "createdAt", header: "Tanggal Unggah ", cell: ({ row }) => ( {formatDateToIndonesian(row.getValue("createdAt"))} ), }, { accessorKey: "status", header: "Status", cell: ({ row }) => { const statusColors: Record = { open: "bg-primary/20 text-primary", close: "bg-success/20 text-success", }; const status = row.getValue("status") as { id: number; name: string }; const statusName = status?.name?.toLocaleLowerCase(); console.log(statusName); const statusStyles = statusColors[statusName] || "default"; if (statusName) { return ( {statusName}{" "} ); } }, }, { id: "actions", accessorKey: "action", header: "Actions", enableHiding: false, cell: ({ row }) => { const MySwal = withReactContent(Swal); async function doDelete(id: any) { const response = await deleteTicket(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(); } }); } const handleDelete = (id: any) => { MySwal.fire({ title: "Hapus Data", text: "", icon: "warning", showCancelButton: true, cancelButtonColor: "#3085d6", confirmButtonColor: "#d33", confirmButtonText: "Hapus", }).then((result) => { if (result.isConfirmed) { doDelete(id); } }); }; async function doClose(id: any) { const response = await closeTicket(id); if (response?.error) { error(response.message); return false; } success(); } const handleClose = (id: any) => { MySwal.fire({ title: "Ubah status menjadi close?", text: "", icon: "warning", showCancelButton: true, cancelButtonColor: "#3085d6", confirmButtonColor: "#d33", confirmButtonText: "Iya", }).then((result) => { if (result.isConfirmed) { doClose(id); } }); }; return ( View Edit handleClose(row.original.id)} className="p-2 border-b text-green-600 bg-green-200 focus:bg-green-400 focus:text-destructive-foreground rounded-none" > Close handleDelete(row.original.id)} className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" > Delete ); }, }, ]; export default columns;