changed dashboard
This commit is contained in:
213
src/features/dashboard/api/analyticsApi.ts
Normal file
213
src/features/dashboard/api/analyticsApi.ts
Normal file
@@ -0,0 +1,213 @@
|
||||
import apiClient from "@/lib/api/client";
|
||||
|
||||
// ─── Shared ───────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface AnalyticsParams {
|
||||
/** YYYY-MM-DD, inclusive */
|
||||
from: string;
|
||||
/** YYYY-MM-DD, inclusive */
|
||||
to: string;
|
||||
}
|
||||
|
||||
export interface CountItem {
|
||||
key: string;
|
||||
count: number;
|
||||
percent: number;
|
||||
}
|
||||
|
||||
/** Localized name stored as JSON on the backend, e.g. { tm, ru, en }. */
|
||||
export type LocalizedName = Partial<Record<"tm" | "ru" | "en", string>>;
|
||||
|
||||
export type OrderType = "loan" | "loan_paid_off_letter" | "card" | "card_pin" | "card_rekwizit" | "visa_master";
|
||||
|
||||
// ─── /finance ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface PaymentTotals {
|
||||
count: number;
|
||||
amountTmt: number;
|
||||
bankFeeTmt: number;
|
||||
gbusFeeTmt: number;
|
||||
tvebFeeTmt: number;
|
||||
totalTmt: number;
|
||||
avgTotalTmt: number;
|
||||
}
|
||||
|
||||
export interface FinanceMonth {
|
||||
month: string; // YYYY-MM
|
||||
count: number;
|
||||
totalTmt: number;
|
||||
bankFeeTmt: number;
|
||||
}
|
||||
|
||||
export interface LoanRequested {
|
||||
count: number;
|
||||
totalTmt: number;
|
||||
avgTmt: number;
|
||||
unparsed: number;
|
||||
}
|
||||
|
||||
export interface FinanceData {
|
||||
payments: PaymentTotals;
|
||||
gateway: CountItem[];
|
||||
gatewaySuccessRate: number | null;
|
||||
monthly: FinanceMonth[];
|
||||
loanRequested: LoanRequested;
|
||||
}
|
||||
|
||||
// ─── /backlog ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface BacklogItem {
|
||||
type: OrderType;
|
||||
open: number;
|
||||
under1Day: number;
|
||||
from1To3Days: number;
|
||||
over3Days: number;
|
||||
oldestOpenAt: string | null;
|
||||
oldestOpenDays: number | null;
|
||||
finished: number;
|
||||
avgProcessHours: number | null;
|
||||
}
|
||||
|
||||
export interface VisaMasterTiming {
|
||||
orders: number;
|
||||
avgMinutes: number | null;
|
||||
p90Minutes: number | null;
|
||||
maxMinutes: number | null;
|
||||
}
|
||||
|
||||
export interface BacklogData {
|
||||
items: BacklogItem[];
|
||||
visaMasterTiming: VisaMasterTiming;
|
||||
}
|
||||
|
||||
// ─── /branches ────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface BranchStat {
|
||||
branchId: number;
|
||||
name: LocalizedName;
|
||||
region: string;
|
||||
orders: Partial<Record<OrderType, number>>;
|
||||
total: number;
|
||||
open: number;
|
||||
approved: number;
|
||||
rejected: number;
|
||||
approvalRate: number | null;
|
||||
avgProcessHours: number | null;
|
||||
}
|
||||
|
||||
export interface BranchesData {
|
||||
branches: BranchStat[];
|
||||
regions: CountItem[];
|
||||
}
|
||||
|
||||
// ─── /products ────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface NamedCount {
|
||||
id: number;
|
||||
name: LocalizedName;
|
||||
count: number;
|
||||
percent: number;
|
||||
}
|
||||
|
||||
export interface ProductsData {
|
||||
loanSources: CountItem[];
|
||||
loanTypes: NamedCount[];
|
||||
cardTypes: NamedCount[];
|
||||
cardOrderPay: CountItem[];
|
||||
}
|
||||
|
||||
// ─── /customers ───────────────────────────────────────────────────────────────
|
||||
|
||||
export interface ApprovalCount {
|
||||
key: string;
|
||||
count: number;
|
||||
percent: number;
|
||||
approved: number;
|
||||
rejected: number;
|
||||
/** Not decided yet (new / in review). */
|
||||
open: number;
|
||||
approvalRate: number | null;
|
||||
}
|
||||
|
||||
export interface CustomersData {
|
||||
total: number;
|
||||
approved: number;
|
||||
rejected: number;
|
||||
open: number;
|
||||
approvalRate: number | null;
|
||||
ageGroups: ApprovalCount[];
|
||||
education: ApprovalCount[];
|
||||
marriageStatus: ApprovalCount[];
|
||||
guarantors: ApprovalCount[];
|
||||
}
|
||||
|
||||
// ─── /system ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface RegistrationFunnel {
|
||||
started: number;
|
||||
completed: number;
|
||||
abandoned: number;
|
||||
waitingCode: number;
|
||||
wrongCodeTries: number;
|
||||
conversionPct: number | null;
|
||||
}
|
||||
|
||||
export interface OperatorActivity {
|
||||
userId: number;
|
||||
name: string;
|
||||
actions: number;
|
||||
errors: number;
|
||||
lastSeen: string | null;
|
||||
}
|
||||
|
||||
export interface ModuleError {
|
||||
module: string;
|
||||
requests: number;
|
||||
errors: number;
|
||||
errorRate: number;
|
||||
}
|
||||
|
||||
/** weekday: Monday=1 .. Sunday=7; hour 0..23 (Asia/Ashgabat). */
|
||||
export interface HeatmapCell {
|
||||
weekday: number;
|
||||
hour: number;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface CardBalanceStats {
|
||||
statuses: CountItem[];
|
||||
failureRate: number | null;
|
||||
expiringIn30d: number;
|
||||
}
|
||||
|
||||
export interface SystemData {
|
||||
registration: RegistrationFunnel | null;
|
||||
operators: OperatorActivity[];
|
||||
moduleErrors: ModuleError[];
|
||||
peakHours: HeatmapCell[];
|
||||
cardBalances: CardBalanceStats | null;
|
||||
}
|
||||
|
||||
// ─── API Functions ────────────────────────────────────────────────────────────
|
||||
|
||||
const BASE = "/dashboard/analytics";
|
||||
|
||||
async function getAnalytics<T>(path: string, params: AnalyticsParams, signal?: AbortSignal): Promise<T> {
|
||||
const { data } = await apiClient.get<T>(`${BASE}/${path}`, { params, signal });
|
||||
return data;
|
||||
}
|
||||
|
||||
export const getAnalyticsFinance = (params: AnalyticsParams, signal?: AbortSignal) => getAnalytics<FinanceData>("finance", params, signal);
|
||||
|
||||
export const getAnalyticsBacklog = (params: AnalyticsParams, signal?: AbortSignal) => getAnalytics<BacklogData>("backlog", params, signal);
|
||||
|
||||
export const getAnalyticsBranches = (params: AnalyticsParams, signal?: AbortSignal) =>
|
||||
getAnalytics<BranchesData>("branches", params, signal);
|
||||
|
||||
export const getAnalyticsProducts = (params: AnalyticsParams, signal?: AbortSignal) =>
|
||||
getAnalytics<ProductsData>("products", params, signal);
|
||||
|
||||
export const getAnalyticsCustomers = (params: AnalyticsParams, signal?: AbortSignal) =>
|
||||
getAnalytics<CustomersData>("customers", params, signal);
|
||||
|
||||
export const getAnalyticsSystem = (params: AnalyticsParams, signal?: AbortSignal) => getAnalytics<SystemData>("system", params, signal);
|
||||
Reference in New Issue
Block a user