connected with dashboard api
This commit is contained in:
75
src/features/dashboard/api/dashboardApi.ts
Normal file
75
src/features/dashboard/api/dashboardApi.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import apiClient from "@/lib/api/client";
|
||||
|
||||
// ─── Types (Backend & UI) ─────────────────────────────────────────────────────
|
||||
|
||||
export interface StatItem {
|
||||
count: number;
|
||||
changePercent: number | null;
|
||||
}
|
||||
|
||||
export interface DashboardStats {
|
||||
loanOrders: StatItem;
|
||||
activeCards: StatItem;
|
||||
activeCustomers: StatItem;
|
||||
onlinePayments: StatItem;
|
||||
}
|
||||
|
||||
export interface TrendPoint {
|
||||
month: number;
|
||||
loans: number;
|
||||
cards: number;
|
||||
}
|
||||
|
||||
export interface DashboardTrend {
|
||||
year: number;
|
||||
points: TrendPoint[];
|
||||
}
|
||||
|
||||
export interface LoanStatusItem {
|
||||
status: string;
|
||||
count: number;
|
||||
percent: number;
|
||||
}
|
||||
|
||||
export interface WeeklyOrderItem {
|
||||
date: string;
|
||||
weekday: number;
|
||||
loans: number;
|
||||
cards: number;
|
||||
}
|
||||
|
||||
export interface RecentActivityItem {
|
||||
id: number;
|
||||
uniqueId: string;
|
||||
customerName: string;
|
||||
amount: string;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface DashboardOverviewData {
|
||||
stats: DashboardStats;
|
||||
trend: DashboardTrend;
|
||||
loanStatus: LoanStatusItem[];
|
||||
weeklyOrders: WeeklyOrderItem[];
|
||||
recentActivity: RecentActivityItem[];
|
||||
}
|
||||
|
||||
export interface DashboardOverviewParams {
|
||||
year?: number | string;
|
||||
recent_limit?: number;
|
||||
}
|
||||
|
||||
// ─── API Functions ─────────────────────────────────────────────────────────────
|
||||
|
||||
export async function getDashboardOverview(params: DashboardOverviewParams = {}, signal?: AbortSignal): Promise<DashboardOverviewData> {
|
||||
const currentYear = new Date().getFullYear();
|
||||
const { data } = await apiClient.get<DashboardOverviewData>("/dashboard/overview", {
|
||||
params: {
|
||||
year: params.year ?? currentYear,
|
||||
recent_limit: params.recent_limit ?? 10,
|
||||
},
|
||||
signal,
|
||||
});
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user