import React from 'react';
import { useQuery } from '@tanstack/react-query';
import { api } from '../lib/api';
import type { ApiResponse } from '../lib/api';
import { formatRial } from '../lib/utils';
import PageHeader from '../components/ui/PageHeader';
interface MonthlyEntry {
month: string;
paid: number;
count: number;
}
interface FinancialSummary {
total_paid: number;
total_pending: number;
total_refunded: number;
count_paid: number;
monthly_chart: MonthlyEntry[];
}
function KpiCard({ label, value, color }: { label: string; value: string; color: string }) {
return (
);
}
const BAR_MAX_HEIGHT = 120;
export default function MyFinancialPage() {
const { data, isLoading } = useQuery>({
queryKey: ['my-financial-summary'],
queryFn: () => api.get('/api/v1/my/financial-summary'),
});
const summary = data?.data;
const maxPaid = summary?.monthly_chart?.reduce((m, e) => Math.max(m, e.paid), 1) ?? 1;
return (
{isLoading ? (
در حال بارگذاری...
) : (
<>
نمودار ۶ ماه اخیر
{summary?.monthly_chart?.length ? (
{summary.monthly_chart.map((entry) => {
const barH = Math.max(4, Math.round((entry.paid / maxPaid) * BAR_MAX_HEIGHT));
return (
{formatRial(entry.paid)}
{entry.month}
);
})}
) : (
دادهای برای نمایش وجود ندارد
)}
>
)}
);
}