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:
AmirReza Jamali
2026-05-20 13:01:36 +03:30
parent d7a3db07ab
commit f080d51e63
14 changed files with 310 additions and 313 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ import axios from "axios";
const api = axios.create({
baseURL: "/api/proxy/",
timeout: 10000,
timeout: 60000,
headers: {
"Content-Type": "application/json",
},
+9
View File
@@ -76,4 +76,13 @@ export const API_ENDPOINTS = {
BASE: (id?: string) => (id ? `inquiries/${id}` : "inquiries"),
STATUS: (id: string) => `inquiries/${id}/status`,
},
DASHBOARD: {
SUMMARY: "dashboard/summary",
TREND: "dashboard/trend",
COUNTRIES: "dashboard/countries",
NOTICE_TYPES: "dashboard/notice-types",
CLOSING_SOON: "dashboard/closing-soon",
RECENT: "dashboard/recent",
},
} as const;
+74
View File
@@ -0,0 +1,74 @@
import api from "../axios";
import { API_ENDPOINTS } from "../endpoints";
import {
ApiResponse,
TDashboardClosingSoon,
TDashboardCountries,
TDashboardNoticeTypes,
TDashboardSummary,
TDashboardTrend,
} from "../types";
export const dashboardService = {
summary: async (params?: {
closing_window?: number;
}): Promise<ApiResponse<TDashboardSummary>> => {
try {
return (await api.get(API_ENDPOINTS.DASHBOARD.SUMMARY, { params })).data;
} catch (error) {
console.error("ERROR caught in Dashboard Service => summary:", error);
throw error;
}
},
trend: async (params?: {
days?: number;
metric?: "created" | "published" | "awarded";
}): Promise<ApiResponse<TDashboardTrend>> => {
try {
return (await api.get(API_ENDPOINTS.DASHBOARD.TREND, { params })).data;
} catch (error) {
console.error("ERROR caught in Dashboard Service => trend:", error);
throw error;
}
},
countries: async (params?: {
limit?: number;
}): Promise<ApiResponse<TDashboardCountries>> => {
try {
return (await api.get(API_ENDPOINTS.DASHBOARD.COUNTRIES, { params })).data;
} catch (error) {
console.error("ERROR caught in Dashboard Service => countries:", error);
throw error;
}
},
noticeTypes: async (): Promise<ApiResponse<TDashboardNoticeTypes>> => {
try {
return (await api.get(API_ENDPOINTS.DASHBOARD.NOTICE_TYPES)).data;
} catch (error) {
console.error(
"ERROR caught in Dashboard Service => notice-types:",
error,
);
throw error;
}
},
closingSoon: async (params?: {
limit?: number;
window?: number;
}): Promise<ApiResponse<TDashboardClosingSoon>> => {
try {
return (await api.get(API_ENDPOINTS.DASHBOARD.CLOSING_SOON, { params }))
.data;
} catch (error) {
console.error(
"ERROR caught in Dashboard Service => closing-soon:",
error,
);
throw error;
}
},
};
+1
View File
@@ -1,4 +1,5 @@
export * from "./companies-service";
export * from "./dashboard-service";
export * from "./inquiries-service";
export * from "./profile-service";
export * from "./tenders-service";
+59
View File
@@ -0,0 +1,59 @@
export type TDashboardSummary = {
total_tenders: number;
active_tenders: number;
awarded_tenders: number;
expired_tenders: number;
cancelled_tenders: number;
closing_soon: number;
total_estimated_value: number;
value_currency: string;
generated_at: number;
};
export type TDashboardTrendPoint = {
date: string;
count: number;
};
export type TDashboardTrend = {
metric: "created" | "published" | "awarded";
days: number;
series: TDashboardTrendPoint[];
};
export type TDashboardCountryItem = {
country_code: string;
count: number;
};
export type TDashboardCountries = {
total: number;
items: TDashboardCountryItem[];
other_count: number;
};
export type TDashboardNoticeTypeItem = {
type: string;
count: number;
};
export type TDashboardNoticeTypes = {
total: number;
items: TDashboardNoticeTypeItem[];
};
export type TDashboardClosingSoonItem = {
id: string;
title: string;
country_code: string;
buyer_name?: string;
submission_deadline: number;
tender_deadline?: number;
status: string;
estimated_value?: number;
currency?: string;
};
export type TDashboardClosingSoon = {
items: TDashboardClosingSoonItem[];
};
+1
View File
@@ -10,3 +10,4 @@ export * from "./TInquiries";
export * from "./TCms";
export * from "./Feedback";
export * from "./Tenders";
export * from "./Dashboard";