From 09adc8bdd0cd02c410e669801185bb04a7a8eb56 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Tue, 21 Jul 2026 10:26:50 +0330 Subject: [PATCH] permission fix --- src/helpers/permissions.ts | 1 + src/pages/home/components/ItemDashboard.tsx | 57 ++++++++++----------- src/shared/SideBar.tsx | 12 ++++- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/helpers/permissions.ts b/src/helpers/permissions.ts index 9e5d30c..a51905b 100644 --- a/src/helpers/permissions.ts +++ b/src/helpers/permissions.ts @@ -159,6 +159,7 @@ export const CONTENT_PERMISSION_RESOURCES = ["blogs", "learnings", "advertisemen export const FINANCIAL_PERMISSION_RESOURCES = ["payments", "invoices", "transactions", "discounts", "bank_accounts"] as const; export const SUPPORT_PERMISSION_RESOURCES = ["support_plan", "tickets"] as const; export const TASK_MANAGER_PERMISSION_RESOURCES = ["workspace", "project", "task", "task_phase"] as const; +export const USERS_SIDEBAR_PERMISSION_RESOURCES = ["admins", ...TASK_MANAGER_PERMISSION_RESOURCES] as const; export const PRODUCT_PERMISSION_RESOURCES = ["dmenu", "dkala", "dpage", "dmail"] as const; type PermissionEntry = { name: string }; diff --git a/src/pages/home/components/ItemDashboard.tsx b/src/pages/home/components/ItemDashboard.tsx index dd2f811..8c8b395 100644 --- a/src/pages/home/components/ItemDashboard.tsx +++ b/src/pages/home/components/ItemDashboard.tsx @@ -1,37 +1,32 @@ -import { FC, ReactNode } from 'react' -import { Link } from 'react-router-dom' +import { FC, ReactNode } from "react"; type Props = { - title: string - icon: ReactNode, - color: string, - count: number, - description: string, - to?: string -} + title: string; + icon: ReactNode; + color: string; + count: number; + description: string; + to?: string; +}; const ItemDashboard: FC = (props: Props) => { + return ( +
+
{props.icon}
+
{props.title}
- return ( - -
- {props.icon} -
-
- {props.title} -
+
+
+
+
{props.count}
+
{props.description}
+
+
+
+ ); +}; -
-
-
-
{props.count}
-
- {props.description} -
-
-
- - ) -} - -export default ItemDashboard \ No newline at end of file +export default ItemDashboard; diff --git a/src/shared/SideBar.tsx b/src/shared/SideBar.tsx index 1237910..52cf0f2 100644 --- a/src/shared/SideBar.tsx +++ b/src/shared/SideBar.tsx @@ -26,6 +26,8 @@ import { hasPermission, PRODUCT_PERMISSION_RESOURCES, SUPPORT_PERMISSION_RESOURCES, + TASK_MANAGER_PERMISSION_RESOURCES, + USERS_SIDEBAR_PERMISSION_RESOURCES, } from "../helpers/permissions"; import { clx } from "../helpers/utils"; import { useGetProfile } from "../pages/profile/hooks/useProfileData"; @@ -65,6 +67,12 @@ const SideBar: FC = () => { return Pages.dashboard; })(); + const usersDefaultLink = (() => { + if (hasPermission(permissions, "admins")) return Pages.users.list; + if (hasAnyPermission(permissions, TASK_MANAGER_PERMISSION_RESOURCES)) return Pages.taskmanager.workspaceList; + return Pages.users.list; + })(); + useEffect(() => { const groupName = getSubMenuNameFromPath(location.pathname); @@ -197,9 +205,9 @@ const SideBar: FC = () => { } title={t("sidebar.users")} isActive={isGroupActive("users")} - link={Pages.users.list} + link={usersDefaultLink} name="users" - activeName="admins" + activeNames={USERS_SIDEBAR_PERMISSION_RESOURCES} />