From d5e4803b042609231217522fd5c746a9d8d1fc7c Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Fri, 26 Jun 2026 16:00:53 +0330 Subject: [PATCH] up --- src/pages/dashboard/hooks/useDashboardData.ts | 9 ++++ .../dashboard/service/DashboardService.ts | 14 ++++++ src/shared/Sidebar.tsx | 49 +++++++++++-------- src/shared/SidebarItem.tsx | 11 +++-- 4 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 src/pages/dashboard/hooks/useDashboardData.ts create mode 100644 src/pages/dashboard/service/DashboardService.ts diff --git a/src/pages/dashboard/hooks/useDashboardData.ts b/src/pages/dashboard/hooks/useDashboardData.ts new file mode 100644 index 0000000..b3d3793 --- /dev/null +++ b/src/pages/dashboard/hooks/useDashboardData.ts @@ -0,0 +1,9 @@ +import { useQuery } from '@tanstack/react-query'; +import * as api from '../service/DashboardService'; + +export const useGetDashboardCounts = () => { + return useQuery({ + queryKey: ['dashboard-counts'], + queryFn: () => api.getDashboardCounts(), + }); +}; diff --git a/src/pages/dashboard/service/DashboardService.ts b/src/pages/dashboard/service/DashboardService.ts new file mode 100644 index 0000000..a004552 --- /dev/null +++ b/src/pages/dashboard/service/DashboardService.ts @@ -0,0 +1,14 @@ +import axios from '@/config/axios'; +import type { BaseResponse } from '@/shared/types/Types'; + +export type DashboardCountsType = { + requestsCount: number; + invoicesCount: number; + ordersCount: number; + paymentsCount: number; +}; + +export const getDashboardCounts = async (): Promise> => { + const { data } = await axios.get>('/admin/dashboard/counts'); + return data; +}; diff --git a/src/shared/Sidebar.tsx b/src/shared/Sidebar.tsx index f83512f..c9a0a2c 100644 --- a/src/shared/Sidebar.tsx +++ b/src/shared/Sidebar.tsx @@ -23,11 +23,14 @@ import { Paths } from '../config/Paths'; import { useSharedStore } from './store/useSharedStore'; import { clx } from '../helpers/utils'; import { t } from '../locale'; +import { useGetDashboardCounts } from '@/pages/dashboard/hooks/useDashboardData'; const SideBar: FC = () => { const { openSidebar, setOpenSidebar } = useSharedStore(); const location = useLocation(); + const { data: dashboardCounts } = useGetDashboardCounts(); + const counts = dashboardCounts?.data; const isActive = (name: string) => { return location.pathname.includes(name); @@ -68,19 +71,12 @@ const SideBar: FC = () => { /> } - title={'محصولات'} - isActive={isActive('product')} - link={Paths.product.list} - activeName='manage_products' - /> - - } - title={'درخواست ها'} - isActive={isActive('requests')} - link={Paths.requests.list} - activeName='view_requests' + icon={} + title={'سفارشات'} + isActive={isActive('order')} + link={Paths.order.list} + activeName={['view_orders', 'view_assigned_orders']} + badge={counts?.ordersCount} /> { isActive={isActive('/invoice')} link={Paths.perfomaInvoice.list} activeName='view_invoices' + badge={counts?.invoicesCount} + /> + + } + title={'درخواست ها'} + isActive={isActive('requests')} + link={Paths.requests.list} + activeName='view_requests' + badge={counts?.requestsCount} /> { isActive={isActive('/payments')} link={Paths.payments.list} activeName='manage_payments' + badge={counts?.paymentsCount} /> - } - title={'سفارشات'} - isActive={isActive('order')} - link={Paths.order.list} - activeName={['view_orders', 'view_assigned_orders']} - /> + @@ -140,6 +141,14 @@ const SideBar: FC = () => { link={Paths.role.list} activeName='manage_roles' /> + + } + title={'محصولات'} + isActive={isActive('product')} + link={Paths.product.list} + activeName='manage_products' + />
{t('sidebar.other')}
diff --git a/src/shared/SidebarItem.tsx b/src/shared/SidebarItem.tsx index f685c68..ca2ec1e 100644 --- a/src/shared/SidebarItem.tsx +++ b/src/shared/SidebarItem.tsx @@ -15,7 +15,8 @@ type Props = { link: string, isLogout?: boolean, isWithoutLine?: boolean, - activeName?: string | string[] + activeName?: string | string[], + badge?: number, } const SideBarItem: FC = (props: Props) => { @@ -40,7 +41,7 @@ const SideBarItem: FC = (props: Props) => { return (
@@ -49,7 +50,11 @@ const SideBarItem: FC = (props: Props) => { {props.title}
- + {props.badge != null && props.badge > 0 && ( + + {props.badge > 99 ? '99+' : props.badge} + + )} ) }