From 0081650ba62b9646b5deff208a54f63542f32003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=AD=D8=B3=DB=8C=D9=86=20=D9=85=D8=B9=D8=B5=D9=88=D9=85?= =?UTF-8?q?=DB=8C=20=D9=BE=D9=88=D8=B1?= Date: Thu, 7 Dec 2023 21:15:58 +0330 Subject: [PATCH] role add dashboard , permision in navigation , user login --- .env | 12 +- components/NavBar/NavBAr.jsx | 302 +++++++++++++++++---------------- package.json | 2 +- plugins/HasPermission/page.jsx | 8 + src/app/home/page.jsx | 11 +- src/app/layout.jsx | 2 +- 6 files changed, 182 insertions(+), 155 deletions(-) create mode 100644 plugins/HasPermission/page.jsx diff --git a/.env b/.env index fd43833..8e19167 100644 --- a/.env +++ b/.env @@ -1,15 +1,15 @@ NODE_ENV="development" -# NEXT_PUBLIC_SERVER_URL=http://192.168.88.12:32769 -# NEXT_PUBLIC_PUBLIC_URL=http://192.168.88.12:32769 -# NEXT_PUBLIC_API_URL=http://192.168.88.12:32769/api +NEXT_PUBLIC_SERVER_URL=http://192.168.88.12:32769 +NEXT_PUBLIC_PUBLIC_URL=http://192.168.88.12:32769 +NEXT_PUBLIC_API_URL=http://192.168.88.12:32769/api # SECURE_LOCAL_STORAGE_HASH_KEY=f1da2b2c7a4c446934267fea631102ec389b5b99 # NEXT_PUBLIC_API_URL_IMAGE=https://192.168.88.12:49154/Files/ReportImages # NEXT_PUBLIC_API_URL_BackUp=https://192.168.88.12:49154/Files/BackUps -NEXT_PUBLIC_SERVER_URL=https://j3884z97-32769.euw.devtunnels.ms -NEXT_PUBLIC_PUBLIC_URL=https://j3884z97-32769.euw.devtunnels.ms -NEXT_PUBLIC_API_URL=https://j3884z97-32769.euw.devtunnels.ms/api +# NEXT_PUBLIC_SERVER_URL=https://j3884z97-32769.euw.devtunnels.ms +# NEXT_PUBLIC_PUBLIC_URL=https://j3884z97-32769.euw.devtunnels.ms +# NEXT_PUBLIC_API_URL=https://j3884z97-32769.euw.devtunnels.ms/api diff --git a/components/NavBar/NavBAr.jsx b/components/NavBar/NavBAr.jsx index c3607c1..203e453 100644 --- a/components/NavBar/NavBAr.jsx +++ b/components/NavBar/NavBAr.jsx @@ -6,10 +6,12 @@ import { usePathname } from "next/navigation"; import Image from "next/image"; import logo from "@img/logo.png"; import AppContext from "@ctx/AppContext"; +import { HasPermission } from "plugins/HasPermission/page"; const NavBAr = (props) => { const usePath = usePathname(); const CTX = useContext(AppContext); + const permissions = CTX.state.profile?.permissions; const openBigPlus = () => { setTimeout(() => { @@ -24,103 +26,107 @@ const NavBAr = (props) => { */}
- - <> - {usePath.includes("/home") ? ( -
- - - -
- ) : ( -
- - - -
- )} - - + {HasPermission("ViewDashboard") && ( + + <> + {usePath.includes("/home") ? ( +
+ + + +
+ ) : ( +
+ + + +
+ )} + + + )} + {HasPermission("ViewShiftPlans") && ( + + <> + {usePath.includes("/shifts") ? ( +
+ + + + +
+ ) : ( +
+ + + + +
+ )} + + + )} - - <> - {usePath.includes("/shifts") ? ( -
- - - - -
- ) : ( -
- - - - -
- )} - -
{ @@ -144,59 +150,63 @@ const NavBAr = (props) => {
- - <> - {usePath.includes("/employees") ? ( -
- - - -
- ) : ( -
- - - -
- )} - - + {HasPermission("ViewComplexSettings") && ( + + <> + {usePath.includes("/employees") ? ( +
+ + + +
+ ) : ( +
+ + + +
+ )} + + + )} - - <> - {usePath.includes("/tasks") ? ( -
-
- + {HasPermission("ViewActivities") && ( + + <> + {usePath.includes("/tasks") ? ( +
+
+ +
-
- ) : ( -
-
- + ) : ( +
+
+ +
-
- )} - - + )} + + + )}
); diff --git a/package.json b/package.json index 4bd8fe6..85ac34b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "brizco", - "version": "0.1.5", + "version": "0.1.6", "private": true, "scripts": { "dev": "next dev", diff --git a/plugins/HasPermission/page.jsx b/plugins/HasPermission/page.jsx new file mode 100644 index 0000000..9b61c2a --- /dev/null +++ b/plugins/HasPermission/page.jsx @@ -0,0 +1,8 @@ +import AppContext from "@ctx/AppContext"; +import React, { useContext } from "react"; + +export const HasPermission = (permission) => { + const CTX = useContext(AppContext); + const permissions = CTX.state.profile?.permissions; + return permissions?.includes(permission); +}; diff --git a/src/app/home/page.jsx b/src/app/home/page.jsx index 9c286dc..71a9905 100644 --- a/src/app/home/page.jsx +++ b/src/app/home/page.jsx @@ -13,6 +13,7 @@ import React, { useContext, useEffect } from "react"; import { Chart as ChartJS, ArcElement, Tooltip, Legend } from "chart.js"; import { Doughnut, Pie } from "react-chartjs-2"; import BottomSheetChangeRole from "plugins/BottomSheet/BottomSheetChangeRole"; +import { HasPermission } from "plugins/HasPermission/page"; ChartJS.register(ArcElement, Tooltip, Legend); @@ -63,7 +64,15 @@ const Home = (props) => { } }, []); - console.log(profile); + // useEffect(() => { + // if (!HasPermission("ViewDashboard")) { + // // You can customize the redirect path as needed + // router.replace("/activity"); + // return null; // Prevent rendering the rest of the component + + // console.log(HasPermission("ViewDashboard")); + // } + // }, [profile]); return (
diff --git a/src/app/layout.jsx b/src/app/layout.jsx index eff2955..301a52b 100644 --- a/src/app/layout.jsx +++ b/src/app/layout.jsx @@ -179,7 +179,7 @@ export default function RootLayout({ children }) { if (data.user.signUpStatus == 1) { setStepLogin(2); - } else if (data.user.signUpStatus == 2) { + } else if (data.user.signUpStatus == 2 || data.user.signUpStatus == 3) { setProfile(data); toast.success(` ${data.user.firstName} جان خوش اومدی `, { position: "bottom-right",