feat(dashboard): integrate new dashboard queries and refactor closing soon component
- Replaced TTenderDetails with TDashboardClosingSoonItem in the ClosingSoonCard component for better type accuracy. - Removed the fake-data.ts file as it is no longer needed with the new dashboard queries. - Introduced new hooks for fetching dashboard data, including summary, trend, countries, notice types, and closing soon items. - Updated useDashboardData to utilize the new dashboard queries, enhancing data retrieval and management. - Enhanced the API service layer with new endpoints for dashboard functionalities, improving overall architecture.
This commit is contained in:
@@ -15,3 +15,4 @@ export * from "./useTenders";
|
||||
export * from "./useUsersQueries";
|
||||
export * from "./useAdminListQuery";
|
||||
export * from "./useSelectSearchQuery";
|
||||
export * from "./useDashboardQueries";
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { API_ENDPOINTS, dashboardService } from "@/lib/api";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMemo } from "react";
|
||||
|
||||
export const useDashboardSummaryQuery = (params?: {
|
||||
closing_window?: number;
|
||||
}) => {
|
||||
const queryKey = useMemo(
|
||||
() => [API_ENDPOINTS.DASHBOARD.SUMMARY, params],
|
||||
[params],
|
||||
);
|
||||
return useQuery({
|
||||
queryKey,
|
||||
queryFn: () => dashboardService.summary(params),
|
||||
});
|
||||
};
|
||||
|
||||
export const useDashboardTrendQuery = (params?: {
|
||||
days?: number;
|
||||
metric?: "created" | "published" | "awarded";
|
||||
}) => {
|
||||
const queryKey = useMemo(
|
||||
() => [API_ENDPOINTS.DASHBOARD.TREND, params],
|
||||
[params],
|
||||
);
|
||||
return useQuery({
|
||||
queryKey,
|
||||
queryFn: () => dashboardService.trend(params),
|
||||
});
|
||||
};
|
||||
|
||||
export const useDashboardCountriesQuery = (params?: { limit?: number }) => {
|
||||
const queryKey = useMemo(
|
||||
() => [API_ENDPOINTS.DASHBOARD.COUNTRIES, params],
|
||||
[params],
|
||||
);
|
||||
return useQuery({
|
||||
queryKey,
|
||||
queryFn: () => dashboardService.countries(params),
|
||||
});
|
||||
};
|
||||
|
||||
export const useDashboardNoticeTypesQuery = () => {
|
||||
return useQuery({
|
||||
queryKey: [API_ENDPOINTS.DASHBOARD.NOTICE_TYPES],
|
||||
queryFn: () => dashboardService.noticeTypes(),
|
||||
});
|
||||
};
|
||||
|
||||
export const useDashboardClosingSoonQuery = (params?: {
|
||||
limit?: number;
|
||||
window?: number;
|
||||
}) => {
|
||||
const queryKey = useMemo(
|
||||
() => [API_ENDPOINTS.DASHBOARD.CLOSING_SOON, params],
|
||||
[params],
|
||||
);
|
||||
return useQuery({
|
||||
queryKey,
|
||||
queryFn: () => dashboardService.closingSoon(params),
|
||||
});
|
||||
};
|
||||
@@ -48,7 +48,10 @@ export const useTranslateTenderMutation = () => {
|
||||
},
|
||||
});
|
||||
};
|
||||
export const useGetTenderDocumentsQuery = (id: string) => {
|
||||
export const useGetTenderDocumentsQuery = (
|
||||
id: string,
|
||||
options?: { enabled?: boolean },
|
||||
) => {
|
||||
const queryKey = useMemo(
|
||||
() => [API_ENDPOINTS.TENDERS.DOCUMENTS(id)],
|
||||
[id],
|
||||
@@ -56,5 +59,6 @@ export const useGetTenderDocumentsQuery = (id: string) => {
|
||||
return useQuery({
|
||||
queryKey,
|
||||
queryFn: () => tendersService.getDocuments(id),
|
||||
enabled: options?.enabled ?? true,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user