import React, { useState, useEffect, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { dashboardService } from '../../services/api'; import useFormatters from '../../hooks/useFormatters'; const UpcomingWidget = () => { const { t } = useTranslation(); const { currency } = useFormatters(); const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const loadData = useCallback(async () => { setLoading(true); try { const result = await dashboardService.getUpcoming(7); setData(result); } catch (error) { console.error('Error loading upcoming:', error); } finally { setLoading(false); } }, []); useEffect(() => { loadData(); }, [loadData]); const getDaysLabel = (daysUntil) => { if (daysUntil === 0) return t('dashboard.today'); if (daysUntil === 1) return t('dashboard.tomorrow'); return `${daysUntil} ${t('dashboard.daysAhead')}`; }; const getTypeIcon = (item) => { if (item.type === 'recurring') { return 'bi-arrow-repeat'; } if (item.is_transfer) { return 'bi-arrow-left-right'; } return item.transaction_type === 'credit' ? 'bi-arrow-down-circle' : 'bi-arrow-up-circle'; }; const getTypeColor = (item) => { if (item.type === 'recurring') return '#f59e0b'; if (item.is_transfer) return '#8b5cf6'; return item.transaction_type === 'credit' ? '#10b981' : '#ef4444'; }; return (
{t('dashboard.noUpcomingTransactions')}