Files
family_budget/frontend/src/components/SummaryCards.tsx
2026-03-02 00:33:09 +03:00

60 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { AnalyticsSummaryResponse } from '@family-budget/shared';
import { formatAmount } from '../utils/format';
interface Props {
summary: AnalyticsSummaryResponse;
}
export function SummaryCards({ summary }: Props) {
return (
<div className="summary-cards">
<div className="summary-card summary-card-income">
<div className="summary-label">Доходы</div>
<div className="summary-value">
{formatAmount(summary.totalIncome)}
</div>
</div>
<div className="summary-card summary-card-expense">
<div className="summary-label">Расходы</div>
<div className="summary-value">
{formatAmount(summary.totalExpense)}
</div>
</div>
<div
className={`summary-card ${summary.net >= 0 ? 'summary-card-positive' : 'summary-card-negative'}`}
>
<div className="summary-label">Баланс</div>
<div className="summary-value">
{formatAmount(summary.net)}
</div>
</div>
{summary.topCategories.length > 0 && (
<div className="summary-card summary-card-top">
<div className="summary-label">Топ расходов</div>
<div className="summary-top-list">
{summary.topCategories.map((cat) => (
<div
key={cat.categoryId}
className="top-category-item"
>
<span className="top-category-name">
{cat.categoryName}
</span>
<span className="top-category-amount">
{formatAmount(cat.amount)}
</span>
<span className="top-category-share">
{(cat.share * 100).toFixed(0)}%
</span>
</div>
))}
</div>
</div>
)}
</div>
);
}