diff --git a/app/(admin)/admin/agent/page.tsx b/app/(admin)/admin/agent/page.tsx index 64fe6e6..d795940 100644 --- a/app/(admin)/admin/agent/page.tsx +++ b/app/(admin)/admin/agent/page.tsx @@ -16,15 +16,15 @@ import { useRouter } from "next/navigation"; export default function AgentPage() { const [openDialog, setOpenDialog] = useState(false); - const [userLevelId, setUserLevelId] = useState(null); + const [userRoleId, setUserRoleId] = useState(null); const router = useRouter(); const MySwal = withReactContent(Swal); // 🔹 Ambil userlevelId dari cookies useEffect(() => { - const ulne = Cookies.get("ulne"); // contoh: "3" - setUserLevelId(ulne ?? null); + const urie = Cookies.get("urie"); // contoh: "3" + setUserRoleId(urie ?? null); }, []); const handleSubmitBanner = (data: any) => { @@ -41,7 +41,7 @@ export default function AgentPage() {
- {userLevelId !== "1" && ( + {userRoleId !== "1" && (
- {userLevelId !== "1" && ( + {userRoleId !== "1" && (
- {userLevelId !== "1" && ( + {userRoleId !== "1" && (
- {userLevelId !== "1" && ( + {userRoleId !== "1" && (
- {userLevelId !== "1" && ( + {userRoleId !== "1" && (
- {openViewDialog && userLevelId !== "2" && ( + {userRoleId !== "2" && data && (
{data.status_id === 1 ? ( <> @@ -232,15 +272,15 @@ export function DialogDetailGaleri({ open, onClose, data }: any) { - {userLevelId === "1" && ( + {userRoleId === "1" && ( @@ -319,7 +359,7 @@ export default function PromoDetailDialog({ )} {openApproverHistory && (
setOpenApproverHistory(false)} >
{ @@ -128,25 +135,39 @@ export default function DetailAgentForm(props: { isDetail: boolean }) { setOpenApproverHistory(true); }; - // const handleRejectProduct = async (id: number) => { - // loading(); + 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", + }); - // const payload = { - // status_id: 3, // ✅ number - // }; + if (message === undefined) { + return; // User cancelled + } - // const res = await updateAgent(payload, id); + loading(); + const res = await rejectAgent(id, message || undefined); - // if (res?.error) { - // error(res.message || "Gagal menolak product"); - // close(); - // return; - // } + if (res?.error) { + error(res.message || "Gagal menolak agent"); + close(); + return; + } - // close(); - // success("Product berhasil ditolak"); - // fetchData(); - // }; + close(); + success("Agent berhasil ditolak"); + fetchData(); // refresh table + }; const handleApproveAgent = async (id: number) => { loading(); @@ -298,7 +319,7 @@ export default function DetailAgentForm(props: { isDetail: boolean }) { diff --git a/components/form/product/detail-product-form.tsx b/components/form/product/detail-product-form.tsx index 363cf76..ffc36d0 100644 --- a/components/form/product/detail-product-form.tsx +++ b/components/form/product/detail-product-form.tsx @@ -33,9 +33,12 @@ import Cookies from "js-cookie"; import { approveProduct, getProductDataById, + rejectProduct, updateProduct, } from "@/service/product"; import { convertDateFormat } from "@/utils/global"; +import withReactContent from "sweetalert2-react-content"; +import Swal from "sweetalert2"; const ViewEditor = dynamic( () => { @@ -302,13 +305,27 @@ export default function DetailProductForm(props: { isDetail: boolean }) { } const handleRejectProduct = async (id: number) => { + const MySwal = withReactContent(Swal); + const { value: message } = await MySwal.fire({ + title: "Tolak Product", + 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 payload = { - status_id: 3, // ✅ number - }; - - const res = await updateProduct(payload, id); + const res = await rejectProduct(id, message || undefined); if (res?.error) { error(res.message || "Gagal menolak product"); @@ -318,7 +335,7 @@ export default function DetailProductForm(props: { isDetail: boolean }) { close(); success("Product berhasil ditolak"); - initState(); + initState(); // refresh table }; const handleApproveProduct = async (id: number) => { diff --git a/components/landing-page/retracting-sidedar.tsx b/components/landing-page/retracting-sidedar.tsx index 6221c4e..a879af2 100644 --- a/components/landing-page/retracting-sidedar.tsx +++ b/components/landing-page/retracting-sidedar.tsx @@ -6,12 +6,15 @@ import Image from "next/image"; import { Icon } from "@iconify/react"; import Link from "next/link"; import DashboardContainer from "../main/dashboard/dashboard-container"; -import { usePathname } from "next/navigation"; +import { usePathname, useRouter } from "next/navigation"; import { motion, AnimatePresence } from "framer-motion"; import { useTheme } from "../layout/theme-context"; import Option from "./option"; import { LogOut } from "lucide-react"; +import withReactContent from "sweetalert2-react-content"; +import Swal from "sweetalert2"; +import Cookies from "js-cookie"; interface RetractingSidebarProps { sidebarData: boolean; @@ -87,6 +90,7 @@ const sidebarSections = [ ), link: "/admin/costumer-service", }, + { title: "Manajemen User", icon: () => , @@ -206,6 +210,18 @@ const SidebarContent = ({ pathname: string; updateSidebarData: (newData: boolean) => void; }) => { + const roleLabel: Record = { + 1: "Admin", + 2: "Operator", + }; + + const [userRoleId, setUserRoleId] = useState(null); + + useEffect(() => { + const urie = Cookies.get("urie"); + setUserRoleId(urie ? Number(urie) : null); + }, []); + const { theme, toggleTheme } = useTheme(); return (
@@ -228,7 +244,10 @@ const SidebarContent = ({ className="flex flex-row" >

- JAECOO Admin + JAECOO{" "} + + {userRoleId != null ? roleLabel[userRoleId] : ""} +

{/* Admin Panel */} @@ -540,7 +559,7 @@ const Sidebar = () => {
-

admin-mabes

+ {/*

admin-mabes

*/}

Logout

diff --git a/components/table/agent-table.tsx b/components/table/agent-table.tsx index 1e2a62d..f7d52ff 100644 --- a/components/table/agent-table.tsx +++ b/components/table/agent-table.tsx @@ -47,9 +47,14 @@ 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 +99,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 +207,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}` + @@ -452,7 +491,7 @@ export default function AgentTable() { {/* Tombol Edit */} - {userLevelId !== "1" && ( + {userRoleId !== "1" && ( - {userLevelId !== "1" && ( + {userRoleId !== "1" && ( + {/* {userRoleId === "1" && item.status_id === 1 && ( + <> + + + )} */} - {userLevelId === "1" && ( + {userRoleId === "1" && ( - {userLevelId !== "1" && ( + {userRoleId !== "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 !== "1" && ( + {userRoleId !== "1" && ( - )} */} + {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 */}