diff --git a/src/pages/Dashboard.jsx b/src/pages/Dashboard.jsx index 5e3fbb6..aac8078 100644 --- a/src/pages/Dashboard.jsx +++ b/src/pages/Dashboard.jsx @@ -1,60 +1,60 @@ import React, { useState, useEffect } from 'react'; import { Badge, Card, SectionTitle, InfoRow, ProgressBar } from '../components/ui'; -import { - TrendingUp, - Clock, - CheckCircle2, - AlertTriangle, - CircleDollarSign, - MapPin, - Zap, - ShieldCheck +import { + TrendingUp, + Clock, + CheckCircle2, + AlertTriangle, + CircleDollarSign, + MapPin, + Zap, + ShieldCheck } from 'lucide-react'; import { getUser, getIncome, getClaims, getBonuses } from '../api'; export default function Dashboard() { const [profile, setProfile] = useState(null); const [loading, setLoading] = useState(true); - + useEffect(() => { const activeUser = localStorage.getItem('USER_ID') || 'u1'; Promise.all([ - getUser(activeUser).catch(() => ({ name: 'Aarav', zone: 'kochi' })), + getUser(activeUser).catch(() => ({ name: 'Arjun Kumar', zone: 'indiranagar' })), getIncome(activeUser).catch(() => ([{ income: 4800 }])), getClaims(activeUser).catch(() => ([])), getBonuses(activeUser).catch(() => ([])) ]).then(([userData, incomeData, claimsData, bonusesData]) => { - const latestIncome = incomeData && incomeData.length > 0 ? incomeData[0].income : 0; - const lastClaim = claimsData && claimsData.length > 0 ? claimsData[0] : { status: 'NONE', date: 'N/A', amount: 0 }; - const latestBonus = bonusesData && bonusesData.length > 0 ? bonusesData[0] : null; - - setProfile({ - name: userData.name || userData.user_id || 'User', - zone: (userData.zone || 'Unknown').toUpperCase(), - userId: userData.user_id || activeUser, - weeklyIncome: latestIncome, - premiumRate: 3.5, - premiumDue: Math.round(latestIncome * 0.035), - premiumDueDate: 'Next Sunday', - lastClaim: { - status: lastClaim.status || 'NONE', - date: lastClaim.timestamp ? new Date(lastClaim.timestamp).toLocaleDateString() : 'N/A', - amount: lastClaim.amount || 0 - }, - bonusStreak: latestBonus ? latestBonus.weeks_no_claims : 0, - projectedBonus: latestBonus ? latestBonus.projected_bonus : 0, - }); - setLoading(false); + const latestIncome = incomeData && incomeData.length > 0 ? incomeData[0].income : 0; + const lastClaim = claimsData && claimsData.length > 0 ? claimsData[0] : { status: 'NONE', date: 'N/A', amount: 0 }; + const latestBonus = bonusesData && bonusesData.length > 0 ? bonusesData[0] : null; + + setProfile({ + name: userData.name || userData.user_id || 'User', + zone: (userData.zone || 'Unknown').toUpperCase(), + userId: userData.user_id || activeUser, + weeklyIncome: latestIncome, + premiumRate: 3.5, + premiumDue: Math.round(latestIncome * 0.035), + premiumDueDate: 'Next Sunday', + lastClaim: { + status: lastClaim.status || 'NONE', + date: lastClaim.timestamp ? new Date(lastClaim.timestamp).toLocaleDateString() : 'N/A', + amount: lastClaim.amount || 0 + }, + bonusStreak: latestBonus ? latestBonus.weeks_no_claims : 0, + projectedBonus: latestBonus ? latestBonus.projected_bonus : 0, + }); + setLoading(false); }); }, []); if (loading || !profile) return
₹{profile.weeklyIncome.toLocaleString('en-IN')}
-