From be02fb7b0e2b3a227b3a4485087a72e0be183dc1 Mon Sep 17 00:00:00 2001 From: hanif salafi Date: Tue, 20 Jan 2026 10:35:33 +0700 Subject: [PATCH] feat: update all approval --- components/table/agent-table.tsx | 83 ++++++++++++++++++++++------ components/table/article-table.tsx | 82 +++++++++++++++++++++------ components/table/galery.tsx | 74 ++++++++++++++++++++----- components/table/product-table.tsx | 83 ++++++++++++++++++++++------ components/table/promotion-table.tsx | 83 ++++++++++++++++++++++------ service/agent.ts | 14 +++++ service/banner.ts | 14 +++++ service/galery.ts | 14 +++++ service/product.ts | 14 +++++ service/promotion.ts | 14 +++++ 10 files changed, 393 insertions(+), 82 deletions(-) diff --git a/components/table/agent-table.tsx b/components/table/agent-table.tsx index c4bb375..775c069 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, CheckCheck } from "lucide-react"; +import { Eye, CheckCheck, X } from "lucide-react"; import AgentDetailDialog from "../dialog/agent-dialog"; -import { deleteAgent, getAgentData, approveAgent } from "@/service/agent"; +import { deleteAgent, getAgentData, approveAgent, rejectAgent } from "@/service/agent"; const columns = [ { name: "No", uid: "no" }, @@ -94,12 +94,12 @@ export default function AgentTable() { startDate: null, endDate: null, }); - const [userLevelId, setUserLevelId] = useState(null); + const [userRoleId, setUserRoleId] = useState(null); - // 🔹 Ambil userlevelId dari cookies + // 🔹 Ambil userRoleId dari cookies useEffect(() => { - const ulne = Cookies.get("ulne"); // contoh: "3" - setUserLevelId(ulne ?? null); + const urie = Cookies.get("urie"); // userRoleId dari cookies + setUserRoleId(urie ?? null); }, []); useEffect(() => { @@ -202,6 +202,40 @@ export default function AgentTable() { initState(); // refresh table }; + const handleRejectAgent = async (id: number) => { + const MySwal = withReactContent(Swal); + const { value: message } = await MySwal.fire({ + title: "Tolak Agent", + input: "textarea", + inputLabel: "Alasan penolakan (opsional)", + inputPlaceholder: "Masukkan alasan penolakan...", + inputAttributes: { + "aria-label": "Masukkan alasan penolakan", + }, + showCancelButton: true, + confirmButtonText: "Tolak", + cancelButtonText: "Batal", + confirmButtonColor: "#dc2626", + }); + + if (message === undefined) { + return; // User cancelled + } + + loading(); + const res = await rejectAgent(id, message || undefined); + + if (res?.error) { + error(res.message || "Gagal menolak agent"); + close(); + return; + } + + close(); + success("Agent berhasil ditolak"); + initState(); // refresh table + }; + const copyUrlArticle = async (id: number, slug: string) => { const url = `${window.location.protocol}//${window.location.host}` + @@ -416,6 +450,10 @@ export default function AgentTable() { Disetujui + ) : item.status_id === 3 ? ( + + Ditolak + ) : ( {item.status_id || "Tidak Diketahui"} @@ -458,17 +496,28 @@ export default function AgentTable() { - {/* Tombol Approve - hanya untuk admin dan status pending */} - {userLevelId === "1" && item.status_id === 1 && ( - + {/* Tombol Approve & Reject - hanya untuk admin dan status pending */} + {userRoleId === "1" && item.status_id === 1 && ( + <> + + + )} {/* Tombol Hapus */} - {userLevelId !== "3" && ( + {userRoleId !== "3" && ( + {userRoleId === "1" && item.status_id === 1 && ( + <> + + + )} - {/* Tombol Approve - hanya untuk admin dan status pending */} - {userLevelId === "1" && item.status_id === 1 && ( - + {/* Tombol Approve & Reject - hanya untuk admin dan status pending */} + {userRoleId === "1" && item.status_id === 1 && ( + <> + + + )} - {userLevelId !== "3" && ( + {userRoleId !== "3" && ( + {userRoleId === "1" && item.status_id === 1 && ( + <> + + + )} {/* Tombol Edit */} - {/* Tombol Approve - hanya untuk admin dan status pending */} - {userLevelId === "1" && item.status_id === 1 && ( - + {/* Tombol Approve & Reject - hanya untuk admin dan status pending */} + {userRoleId === "1" && item.status_id === 1 && ( + <> + + + )} {/* Tombol Hapus */}