import * as React from "react"; import { ColumnDef } from "@tanstack/react-table"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; 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 { formatDateToIndonesian } from "@/utils/globals"; import { Link, useRouter } from "@/i18n/routing"; import { useToast } from "@/components/ui/use-toast"; import { deleteUserById } from "@/service/service/management-user/management-user"; const columns: ColumnDef[] = [ { accessorKey: "no", header: "No", cell: ({ row }) => {row.getValue("no")}, }, { accessorKey: "fullname", header: "Nama", cell: ({ row }) => ( {row.getValue("fullname")} ), }, { accessorKey: "username", header: "Username", cell: ({ row }) => ( {row.getValue("username")} ), }, { accessorKey: "phoneNumber", header: "No. HP", cell: ({ row }) => {row.getValue("phoneNumber")}, }, { accessorKey: "email", header: "Email", cell: ({ row }) => ( {row.getValue("email")} ), }, { accessorKey: "userLevelGroup", header: "Level Group", cell: ({ row }) => ( {row.getValue("userLevelGroup") || "-"} ), }, // { // accessorKey: "statusId", // header: "Status ID", // cell: ({ row }) => ( // {row.getValue("statusId")} // ), // }, { accessorKey: "createdAt", header: "Tanggal Unggah", cell: ({ row }) => ( {formatDateToIndonesian(row.getValue("createdAt"))} ), }, { accessorKey: "isActive", header: "Status", cell: ({ row }) => ( {row.getValue("isActive") ? "Aktif" : "Belum Aktif"} ), }, { id: "actions", accessorKey: "action", header: "Actions", enableHiding: false, cell: ({ row }) => { const { toast } = useToast(); const MySwal = withReactContent(Swal); const router = useRouter(); const doDelete = async (id: number) => { try { const response = await deleteUserById(id); if (response?.error) { toast({ title: response?.message || "Gagal menghapus user", variant: "destructive", }); return; } toast({ title: "User berhasil dihapus", variant: "default", }); router.push("?dataChange=true"); } catch (error) { toast({ title: "Terjadi kesalahan saat menghapus user", variant: "destructive", }); } }; const handleDelete = (id: number) => { MySwal.fire({ title: "Apakah anda ingin menghapus data user?", showCancelButton: true, confirmButtonColor: "#dc3545", confirmButtonText: "Iya", cancelButtonText: "Tidak", }).then((result) => { if (result.isConfirmed) { doDelete(id); } }); }; return ( Detail Edit { handleDelete(row.original.id); }} > Hapus ); }, }, ]; export default columns;