"use client"; import React, { Dispatch, SetStateAction, useState, useEffect } from "react"; 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 { useTheme } from "../layout/theme-context"; import { AnimatePresence, motion } from "framer-motion"; import Option from "./option"; interface RetractingSidebarProps { sidebarData: boolean; updateSidebarData: (newData: boolean) => void; } const getSidebarByRole = (role: string) => { if (role === "Admin") { return [ { title: "Dashboard", items: [ { title: "Dashboard", icon: () => ( ), link: "/admin/dashboard", }, ], }, ]; } if (role === "Approver" || role === "Kontributor") { return [ { title: "Dashboard", items: [ { title: "Dashboard", icon: () => ( ), link: "/admin/dashboard", }, ], }, { title: "Content Management", items: [ { title: "Articles", icon: () => , link: "/admin/article", }, ], }, ]; } // fallback kalau role tidak dikenal return []; }; export const RetractingSidebar = ({ sidebarData, updateSidebarData, }: RetractingSidebarProps) => { const pathname = usePathname(); const [mounted, setMounted] = useState(false); useEffect(() => { setMounted(true); }, []); if (!mounted) { return null; } return ( <> {/* DESKTOP SIDEBAR */} {/* Desktop Toggle Button - appears when sidebar is collapsed */} {!sidebarData && ( updateSidebarData(true)} > )} {/* Mobile Toggle Button */} {!sidebarData && ( updateSidebarData(true)} > )} {/* MOBILE SIDEBAR */} {sidebarData && ( {/* updateSidebarData(false)} className="mb-4 self-end text-zinc-500"> ✕ */} )} > ); }; const SidebarContent = ({ open, pathname, updateSidebarData, }: { open: boolean; pathname: string; updateSidebarData: (newData: boolean) => void; }) => { const { theme, toggleTheme } = useTheme(); const [username, setUsername] = useState("Guest"); const [roleName, setRoleName] = useState(""); useEffect(() => { const getCookie = (name: string) => { const match = document.cookie.match( new RegExp("(^| )" + name + "=([^;]+)"), ); return match ? decodeURIComponent(match[2]) : null; }; const cookieUsername = getCookie("username"); const cookieRole = getCookie("roleName"); // pastikan nama cookie sesuai if (cookieUsername) { setUsername(cookieUsername); } if (cookieRole) { setRoleName(cookieRole); } }, []); const sidebarSections = getSidebarByRole(roleName); return ( {/* SCROLLABLE TOP SECTION */} {/* HEADER SECTION */} {/* Logo and Toggle */} {open && ( Arah Negeri Admin Panel )} {open && ( updateSidebarData(false)} > )} {/* Navigation Sections */} {sidebarSections.map((section, sectionIndex) => ( {open && ( {section.title} )} {section.items.map((item, itemIndex) => ( ))} ))} {/* FIXED BOTTOM SECTION */} {/* Divider */} {/* */} {/* Theme Toggle */} {theme === "dark" ? ( ) : ( )} {open && ( {theme === "dark" ? "Light Mode" : "Dark Mode"} )} {/* Settings */} ( )} title="Settings" active={pathname === "/settings"} open={open} /> {/* User Profile */} A {open && ( {username} Sign out )} {/* Expand Button for Collapsed State */} {/* {!open && ( updateSidebarData(true)} className="w-full p-3 rounded-xl bg-gradient-to-r from-blue-500 to-purple-500 hover:from-blue-600 hover:to-purple-600 text-white shadow-lg transition-all duration-200 hover:shadow-xl group" > )} */} ); };
{username}
Sign out