import React, { useState, useEffect } from 'react'; import axios from 'axios'; import './Statistics.css'; const Statistics = () => { const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { fetchStatistics(); }, []); const fetchStatistics = async () => { setLoading(true); try { const response = await axios.get('/api/v1/stats/summary'); setStats(response.data); setError(null); } catch (err) { setError('Ошибка загрузки статистики'); console.error(err); } finally { setLoading(false); } }; if (loading) return
Загрузка...
; if (error) return
{error}
; if (!stats) return
Нет данных
; return (

Статистика

{/* Общая статистика */}

Всего карточек

{stats.total_cases || 0}
{/* По полу */}

По полу

Мужской: {stats.by_gender?.male || 0}
Женский: {stats.by_gender?.female || 0}
{/* По возрасту */}

По возрасту

{stats.by_age && Object.entries(stats.by_age).map(([range, count]) => (
{range}: {count}
))}
{/* По психотипам */}

По психотипам

{stats.by_psychotype && Object.entries(stats.by_psychotype).map(([type, count]) => (
{type}: {count}
))}
{/* По диагнозам */}

По диагнозам

{stats.by_diagnosis && Object.entries(stats.by_diagnosis).map(([diagnosis, count]) => (
{diagnosis}: {count}
))}
); }; export default Statistics;