diff --git a/components/table/agent-table.tsx b/components/table/agent-table.tsx index 8bd000b..c4bb375 100644 --- a/components/table/agent-table.tsx +++ b/components/table/agent-table.tsx @@ -47,9 +47,9 @@ import { } from "@/components/ui/table"; import CustomPagination from "../layout/custom-pagination"; import { EditBannerDialog } from "../form/banner-edit-dialog"; -import { Eye } from "lucide-react"; +import { Eye, CheckCheck } from "lucide-react"; import AgentDetailDialog from "../dialog/agent-dialog"; -import { deleteAgent, getAgentData } from "@/service/agent"; +import { deleteAgent, getAgentData, approveAgent } from "@/service/agent"; const columns = [ { name: "No", uid: "no" }, @@ -94,6 +94,13 @@ export default function AgentTable() { startDate: null, endDate: null, }); + const [userLevelId, setUserLevelId] = useState(null); + + // 🔹 Ambil userlevelId dari cookies + useEffect(() => { + const ulne = Cookies.get("ulne"); // contoh: "3" + setUserLevelId(ulne ?? null); + }, []); useEffect(() => { initState(); @@ -180,6 +187,21 @@ export default function AgentTable() { setOpenPreview(true); }; + const handleApproveAgent = async (id: number) => { + loading(); + const res = await approveAgent(id); + + if (res?.error) { + error(res.message || "Gagal menyetujui agent"); + close(); + return; + } + + close(); + success("Agent berhasil disetujui"); + initState(); // refresh table + }; + const copyUrlArticle = async (id: number, slug: string) => { const url = `${window.location.protocol}//${window.location.host}` + @@ -386,9 +408,19 @@ export default function AgentTable() { {/* STATUS */} - - Menunggu - + {item.status_id === 1 ? ( + + Menunggu + + ) : item.status_id === 2 ? ( + + Disetujui + + ) : ( + + {item.status_id || "Tidak Diketahui"} + + )} {/* AKSI */} @@ -426,6 +458,18 @@ export default function AgentTable() { + {/* Tombol Approve - hanya untuk admin dan status pending */} + {userLevelId === "1" && item.status_id === 1 && ( + + )} {/* Tombol Hapus */} )} + {userLevelId === "1" && item.status_id === 1 && ( + + )} + {/* Tombol Approve - hanya untuk admin dan status pending */} + {userLevelId === "1" && item.status_id === 1 && ( + + )} + )} + {userLevelId === "1" && item.status_id === 1 && ( + + )} {/* Tombol Edit */} + {/* Tombol Approve - hanya untuk admin dan status pending */} + {userLevelId === "1" && item.status_id === 1 && ( + + )} {/* Tombol Hapus */}