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 { Link } from "@/components/navigation"; import { useToast } from "@/components/ui/use-toast"; import withReactContent from "sweetalert2-react-content"; import Swal from "sweetalert2"; import { useRouter } from "next/navigation"; import { deleteUser } from "@/service/management-user/management-user"; import { stringify } from "querystring"; const getColumns = ({ onRefresh }: { onRefresh: () => void }): ColumnDef[] => [ { accessorKey: "no", header: "No", cell: ({ row }) => {row.getValue("no")}, }, { accessorKey: "fullname", header: "Nama", cell: ({ row }) => {row.getValue("fullname")}, }, { accessorKey: "address", header: "Wilayah", cell: () => MABES, }, { accessorKey: "userRolePlacements", header: "Posisi", cell: ({ row }) => { const placements = row.original.userRolePlacements || []; const placement = placements.find( (p: any) => p.roleId === 11 || p.roleId === 12 ); let posisi = "-"; if (placement) { posisi = placement.roleId === 11 ? "Koorkurator" : "Kurator"; } return {posisi}; }, }, { accessorKey: "role.name", header: "Bidang Keahlian", cell: ({ row }) => ( {row.original.userProfilesAdditional?.userCompetency?.name ?? "-"} ), }, { accessorKey: "userExperienceId", header: "Pengalaman", cell: ({ row }) => { const experienceId = row.original.userProfilesAdditional?.userExperienceId; const experienceMap: Record = { 1: "Akademisi", 2: "Praktisi", 3: "Akademisi + Praktisi", }; return {experienceMap[experienceId] ?? "-"}; }, }, { id: "actions", header: "Actions", cell: ({ row }) => { const { toast } = useToast(); const MySwal = withReactContent(Swal); const doDelete = async (id: number) => { Swal.fire({ title: "Menghapus user...", text: "Mohon tunggu", allowOutsideClick: false, didOpen: () => Swal.showLoading(), }); const response = await deleteUser(id); Swal.close(); if (response?.error) { toast({ title: stringify(response?.message), variant: "destructive", }); return; } toast({ title: "Berhasil menghapus user" }); // ⬅️ INI YANG PENTING → REFRESH TABLE TANPA RELOAD onRefresh(); }; const handleDelete = (id: number) => { MySwal.fire({ title: "Hapus user ini?", showCancelButton: true, confirmButtonColor: "#dc3545", confirmButtonText: "Iya", cancelButtonText: "Tidak", }).then((res) => { if (res.isConfirmed) doDelete(id); }); }; return ( View Edit handleDelete(row.original.userKeycloakId)} className="text-red-600 cursor-pointer hover:bg-red-300" > Delete ); }, }, ]; export default getColumns;