diff --git a/example.env.local b/example.env.local
index 43f706c..3cf2def 100644
--- a/example.env.local
+++ b/example.env.local
@@ -10,6 +10,8 @@ NEXT_PUBLIC_BASE_URL = "https://crm.witel.ir"
NEXT_PUBLIC_SERVER_SOCKET_URL = "wss://crmws.witel.ir"
NEXT_PUBLIC_POWERED_BY_URL = "https://witel.ir"
-NEXT_HAS_NOTIFICATION = "false"
+#["NEXT_PUBLIC_HAS_WIDGET" , "NEXT_PUBLIC_HAS_NOTIFICATION"]
+NEXT_PUBLIC_HAS_VALUE=["NEXT_PUBLIC_HAS_WIDGET"]
+
+NODE_ENV = "development"
-NODE_ENV = "development"
\ No newline at end of file
diff --git a/src/layouts/DashboardLayout.jsx b/src/layouts/DashboardLayout.jsx
index 3c62a77..72344d6 100644
--- a/src/layouts/DashboardLayout.jsx
+++ b/src/layouts/DashboardLayout.jsx
@@ -1,12 +1,15 @@
-import CallWidget from "src/components/layouts/Dashboard/CallWidget";
import Dashboard from "src/components/layouts/Dashboard";
+import AppPermission from "@/middlewares/AppPermission";
+import CallWidget from "@/components/layouts/Dashboard/CallWidget";
const DashboardLayout = (props) => {
-
+ const permissions = ["NEXT_PUBLIC_HAS_WIDGET"];
return (
<>
-
+
+
+
>
);
};
diff --git a/src/lib/app/hooks/useNotification.jsx b/src/lib/app/hooks/useNotification.jsx
index 6453ee8..6e80bca 100644
--- a/src/lib/app/hooks/useNotification.jsx
+++ b/src/lib/app/hooks/useNotification.jsx
@@ -1,7 +1,9 @@
import useSWR from 'swr'
import {GET_SIDEBAR_NOTIFICATION} from "@/core/data/apiRoutes";
import useRequest from "@/lib/app/hooks/useRequest";
-const isNotificationEnabled = process.env.NEXT_HAS_NOTIFICATION === "true";
+const GLOBAL_HAS_VALUE = process.env.NEXT_PUBLIC_HAS_VALUE;
+const hasPermissionsValue = GLOBAL_HAS_VALUE ? JSON.parse(GLOBAL_HAS_VALUE) : [];
+const isNotificationEnabled = hasPermissionsValue.includes("NEXT_PUBLIC_HAS_NOTIFICATION");
const useNotification = () => {
diff --git a/src/middlewares/AppPermission.jsx b/src/middlewares/AppPermission.jsx
new file mode 100644
index 0000000..8f93bd3
--- /dev/null
+++ b/src/middlewares/AppPermission.jsx
@@ -0,0 +1,8 @@
+const GLOBAL_HAS_VALUE = process.env.NEXT_PUBLIC_HAS_VALUE;
+const hasPermissionsValue = GLOBAL_HAS_VALUE ? JSON.parse(GLOBAL_HAS_VALUE) : [];
+
+const AppPermission = ({ children , permissions }) => {
+ return permissions.some(permission => hasPermissionsValue.includes(permission)) ? <>{children}> : null;
+};
+
+export default AppPermission;
diff --git a/src/middlewares/__test__/AppPermission.test.js b/src/middlewares/__test__/AppPermission.test.js
new file mode 100644
index 0000000..82377ba
--- /dev/null
+++ b/src/middlewares/__test__/AppPermission.test.js
@@ -0,0 +1,26 @@
+import {render, screen, waitFor} from '@testing-library/react';
+import MockAppWithProviders from "../../../mocks/AppWithProvider";
+import AppPermission from "@/middlewares/AppPermission";
+
+describe('AppPermission From middlewares', () => {
+ describe('Behavior', () => {
+ it('show related child if permission exist', async () => {
+
+ const requiredPermissions = ["NEXT_PUBLIC_HAS_WIDGET"];
+ render({'children'});
+
+ await waitFor(()=>{
+ expect(screen.queryByText('children')).toBeInTheDocument();
+ })
+ });
+ it('do not show related child if permission does not exist', async () => {
+
+ const requiredPermissions = ["MISSING_PERMISSION"];
+ render();
+
+ await waitFor(() => {
+ expect(screen.queryByText('children')).not.toBeInTheDocument();
+ });
+ });
+ });
+});