diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index af44e73..0a10c68 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -24,10 +24,10 @@ }, "sidebar": { "dashboard": "داشبورد", - "passenger-office": "اداره مسافر", - "machinary-office": "ماشین آلات", + "passenger-office-chief": "اداره مسافر", + "machinary-expert": "ماشین آلات", "passenger-boss": "رئیس مسافر ", - "transportation-assistance": "معاونت حمل و نقل", + "transportation-assistant": "معاونت حمل و نقل", "province-manager": "مدیر کل استانی", "change-password": "تغییر رمز عبور", "edit-profile": "ویرایش پروفایل" @@ -43,6 +43,10 @@ "typography_routing_previuos_page": "صفحه قبل...", "typography_routing_dashbaord_page": "داشبورد..." }, + "Permission": { + "typography_you_dont_have_access": "شما دسترسی لازم برای مشاهده این صفحه را ندارید!", + "button_back_dashboard": "بازگشت به صفحه اصلی" + }, "LoginPage": { "text_field_user_name": "نام کاربری", "text_field_enter_your_username": "نام کاربری خود را وارد کنید", diff --git a/src/core/data/sidebarMenu.jsx b/src/core/data/sidebarMenu.jsx index 345db25..667c688 100644 --- a/src/core/data/sidebarMenu.jsx +++ b/src/core/data/sidebarMenu.jsx @@ -16,18 +16,18 @@ const sidebarMenu = [ role: "all", }, { - key: "sidebar.passenger-office", + key: "sidebar.passenger-office-chief", secondary: "secondary.passenger-office", type: "page", - route: "/dashboard/passenger-office", + route: "/dashboard/passenger-office-chief", icon: , selected: false, role: "passenger_office_chief", }, { - key: "sidebar.machinary-office", + key: "sidebar.machinary-expert", type: "page", - route: "/dashboard/machinary-office", + route: "/dashboard/machinary-expert", icon: , selected: false, role: "machinery_expert", @@ -42,9 +42,9 @@ const sidebarMenu = [ role: "passenger_office_chief", }, { - key: "sidebar.transportation-assistance", + key: "sidebar.transportation-assistant", type: "page", - route: "/dashboard/transportation-assistance", + route: "/dashboard/transportation-assistant", icon: , selected: false, role: "transportation_assistant", diff --git a/src/middlewares/RolePermission.jsx b/src/middlewares/RolePermission.jsx new file mode 100644 index 0000000..2cf2baa --- /dev/null +++ b/src/middlewares/RolePermission.jsx @@ -0,0 +1,43 @@ +import { NextLinkComposed } from "@/core/components/LinkRouting"; +import Message from "@/core/components/Messages"; +import useUser from "@/lib/app/hooks/useUser"; +import { Button, Typography } from "@mui/material"; +import { useTranslations } from "next-intl"; + +const RolePermission = ({ children, requiredPermissions }) => { + const { user } = useUser(); + const t = useTranslations(); + + const hasPermission = requiredPermissions.some((permission) => + user?.role?.includes(permission) + ); + + if (!hasPermission) { + return ( + + {t("Permission.typography_you_dont_have_access")} + + } + actions={ + <> + + + } + /> + ); + } + + return <>{children}; +}; + +export default RolePermission; diff --git a/src/pages/dashboard/machinary-office/index.jsx b/src/pages/dashboard/machinary-expert/index.jsx similarity index 66% rename from src/pages/dashboard/machinary-office/index.jsx rename to src/pages/dashboard/machinary-expert/index.jsx index 0bb3553..ed7b514 100644 --- a/src/pages/dashboard/machinary-office/index.jsx +++ b/src/pages/dashboard/machinary-expert/index.jsx @@ -1,13 +1,16 @@ import DashboardMachinaryOfficeComponent from "@/components/dashboard/machinary-office"; import TitlePage from "@/core/components/TitlePage"; +import RolePermission from "@/middlewares/RolePermission"; import WithAuthMiddleware from "@/middlewares/WithAuth"; import { parse } from "next-useragent"; - +const requiredPermissions = ["machinery_expert"]; export default function PassengerOffice() { return ( - - + + + + ); } diff --git a/src/pages/dashboard/passenger-boss/index.jsx b/src/pages/dashboard/passenger-boss/index.jsx index ea0566a..8a261f3 100644 --- a/src/pages/dashboard/passenger-boss/index.jsx +++ b/src/pages/dashboard/passenger-boss/index.jsx @@ -1,13 +1,16 @@ import DashboardPassengerBossComponent from "@/components/dashboard/passenger-boss"; import TitlePage from "@/core/components/TitlePage"; +import RolePermission from "@/middlewares/RolePermission"; import WithAuthMiddleware from "@/middlewares/WithAuth"; import { parse } from "next-useragent"; - +const requiredPermissions = ["passenger_office_chief"]; export default function PassengerBoss() { return ( - - + + + + ); } diff --git a/src/pages/dashboard/passenger-office/index.jsx b/src/pages/dashboard/passenger-office-chief/index.jsx similarity index 65% rename from src/pages/dashboard/passenger-office/index.jsx rename to src/pages/dashboard/passenger-office-chief/index.jsx index 36e2a95..2402f75 100644 --- a/src/pages/dashboard/passenger-office/index.jsx +++ b/src/pages/dashboard/passenger-office-chief/index.jsx @@ -1,13 +1,16 @@ import DashboardPassengerOfficeComponent from "@/components/dashboard/passenger-office"; import TitlePage from "@/core/components/TitlePage"; +import RolePermission from "@/middlewares/RolePermission"; import WithAuthMiddleware from "@/middlewares/WithAuth"; import { parse } from "next-useragent"; - +const requiredPermissions = ["passenger_office_chief"]; export default function PassengerOffice() { return ( - - + + + + ); } diff --git a/src/pages/dashboard/province-manager/index.jsx b/src/pages/dashboard/province-manager/index.jsx index 7fbc181..808a5d4 100644 --- a/src/pages/dashboard/province-manager/index.jsx +++ b/src/pages/dashboard/province-manager/index.jsx @@ -1,13 +1,16 @@ import DashboardProvinceManagerComponent from "@/components/dashboard/province-manager"; import TitlePage from "@/core/components/TitlePage"; +import RolePermission from "@/middlewares/RolePermission"; import WithAuthMiddleware from "@/middlewares/WithAuth"; import { parse } from "next-useragent"; - +const requiredPermissions = ["province_manager"]; export default function PassengerOffice() { return ( - - + + + + ); } diff --git a/src/pages/dashboard/transportation-assistance/index.jsx b/src/pages/dashboard/transportation-assistant/index.jsx similarity index 65% rename from src/pages/dashboard/transportation-assistance/index.jsx rename to src/pages/dashboard/transportation-assistant/index.jsx index ef9a661..47297f6 100644 --- a/src/pages/dashboard/transportation-assistance/index.jsx +++ b/src/pages/dashboard/transportation-assistant/index.jsx @@ -1,13 +1,16 @@ import DashboardTransportationAssistanceComponent from "@/components/dashboard/transportation-assistance"; import TitlePage from "@/core/components/TitlePage"; +import RolePermission from "@/middlewares/RolePermission"; import WithAuthMiddleware from "@/middlewares/WithAuth"; import { parse } from "next-useragent"; - +const requiredPermissions = ["transportation_assistant"]; export default function TransportationAssistance() { return ( - - + + + + ); }