diff --git a/app/component/DetailProfile.js b/app/component/DetailProfile.js index 3254186..5089c35 100644 --- a/app/component/DetailProfile.js +++ b/app/component/DetailProfile.js @@ -1,20 +1,37 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import ProfilePA from "@/components/icons/ProfilePA"; import LogoutP from "@/components/icons/LogoutP"; import CardDA from "@/components/icons/CardDA"; import { Button, Popover } from "@mui/material"; import Link from "next/link"; import ModalLogout from "./ModalLogout"; +import Cookies from "js-cookie"; function DetailProfile({ anchorEl, setAnchorEl }) { const [modal, setModal] = useState(false); + const [hasRepresentationRole, setHasRepresentationRole] = useState(false); + const handleClose = () => setAnchorEl(null); const closeModal = () => setModal(false); const openModal = () => setModal(true); + useEffect(() => { + const userInfo = Cookies.get("userInfo"); + if (userInfo) { + try { + const parsedUserInfo = JSON.parse(userInfo); + const roles = parsedUserInfo?.roles || {}; + const hasRole = Object.values(roles).includes("representation"); + setHasRepresentationRole(hasRole); + } catch (error) { + console.error("Error parsing userInfo:", error); + } + } + }, []); + const open = Boolean(anchorEl); const id = open ? "simple-popover" : undefined; - + return ( <> @@ -57,6 +74,18 @@ function DetailProfile({ anchorEl, setAnchorEl }) { تراکنش های من + {hasRepresentationRole && ( + + + + )}