diff --git a/src/Pages/Menu.tsx b/src/Pages/Menu.tsx index 9bacb51..c16f758 100644 --- a/src/Pages/Menu.tsx +++ b/src/Pages/Menu.tsx @@ -6,14 +6,24 @@ import { motion, AnimatePresence } from "framer-motion"; import { ChevronDownIcon, GlobeAsiaAustraliaIcon, + MapPinIcon, } from "@heroicons/react/24/outline"; import { getInspectionMenuItems } from "../config/menuItems"; +const ADMIN_PROVINCES = [ + { value: "hamedan", label: "همدان" }, + { value: "markazi", label: "مرکزی" }, +] as const; + export const Menu = () => { - const { profile } = useUserProfileStore(); + const { profile, updateProfile } = useUserProfileStore(); const navigate = useNavigate(); const menuItems = getInspectionMenuItems(profile?.permissions || []); const [openIndex, setOpenIndex] = useState(null); + const hasAdmin = + Array.isArray(profile?.permissions) && + profile.permissions.includes("admin"); + const currentProvince = profile?.province || "hamedan"; const toggleSubmenu = (index: number) => { setOpenIndex((prev) => (prev === index ? null : index)); @@ -27,7 +37,7 @@ export const Menu = () => { منو -
+
+ {hasAdmin && ( +
+
+ + استان +
+
+ {ADMIN_PROVINCES.map(({ value, label }) => ( + + ))} +
+
+ )}
diff --git a/src/context/zustand-store/userStore.ts b/src/context/zustand-store/userStore.ts index 2fd31ec..d636460 100644 --- a/src/context/zustand-store/userStore.ts +++ b/src/context/zustand-store/userStore.ts @@ -5,12 +5,13 @@ import { useDashboardTabStore } from "./dashboardTabStore"; interface UseUserProfileStore { profile?: Record | null; setUserProfile: (profile: Record) => void; + updateProfile: (updates: Partial>) => void; clearProfile: () => void; } const arePermissionsEqual = ( permissions1?: string[], - permissions2?: string[] + permissions2?: string[], ): boolean => { if (!permissions1 && !permissions2) return true; if (!permissions1 || !permissions2) return false; @@ -24,7 +25,7 @@ const arePermissionsEqual = ( const areProfilesEqual = ( currentProfile: Record | null | undefined, - newProfile: Record + newProfile: Record, ): boolean => { if (!currentProfile) return false; @@ -35,10 +36,10 @@ const areProfilesEqual = ( } const currentKeys = Object.keys(currentProfile).filter( - (key) => key !== "permissions" + (key) => key !== "permissions", ); const newKeys = Object.keys(newProfile).filter( - (key) => key !== "permissions" + (key) => key !== "permissions", ); if (currentKeys.length !== newKeys.length) return false; @@ -72,10 +73,15 @@ export const useUserProfileStore = create()( console.log("profile", profile); } }, + updateProfile: (updates) => { + const currentProfile = get().profile; + if (!currentProfile) return; + set({ profile: { ...currentProfile, ...updates } }); + }, clearProfile: () => set({ profile: null }), }), - { name: "userprofile" } - ) + { name: "userprofile" }, + ), ); interface UseUserStore { @@ -97,6 +103,6 @@ export const useUserStore = create()( }), { name: "user", - } - ) + }, + ), ); diff --git a/src/screen/SideBar.tsx b/src/screen/SideBar.tsx index d2a214a..9c61e34 100644 --- a/src/screen/SideBar.tsx +++ b/src/screen/SideBar.tsx @@ -15,8 +15,14 @@ import { MagnifyingGlassIcon, BuildingOfficeIcon, GlobeAsiaAustraliaIcon, + MapPinIcon, } from "@heroicons/react/24/outline"; +const ADMIN_PROVINCES = [ + { value: "hamedan", label: "همدان" }, + { value: "markazi", label: "مرکزی" }, +] as const; + const containerVariants = { hidden: {}, visible: { transition: { staggerChildren: 0.03 } }, @@ -66,8 +72,12 @@ const sidebarVariants = { export const SideBar = () => { const isMobile = checkIsMobile(); - const { profile } = useUserProfileStore(); + const { profile, updateProfile } = useUserProfileStore(); const menuItems = getInspectionMenuItems(profile?.permissions || []); + const hasAdmin = + Array.isArray(profile?.permissions) && + profile.permissions.includes("admin"); + const currentProvince = profile?.province || "hamedan"; const [search, setSearch] = useState(""); const { isSideBarOpen, toggleSideBar } = useSideBarStore(); @@ -201,6 +211,30 @@ export const SideBar = () => { مشاهده نقشه )} + {isSideBarOpen && hasAdmin && ( +
+
+ + استان +
+
+ {ADMIN_PROVINCES.map(({ value, label }) => ( + + ))} +
+
+ )}
)}