From 1ea425931a69f90255a6f7337d66756fc1df3006 Mon Sep 17 00:00:00 2001 From: Yogini Aishwaryaa P T S Date: Sat, 4 Apr 2026 23:14:21 +0530 Subject: [PATCH] fix: dashboard error --- src/pages/Dashboard.jsx | 78 ++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 39 deletions(-) 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
Loading dashboard...
; const STATS = [ - { label: 'Weekly Income', val: `₹${profile.weeklyIncome.toLocaleString('en-IN')}`, sub: 'Latest recorded income', icon: TrendingUp, color: '#f1f5f9' }, - { label: 'Policy Status', val: 'Active', sub: `User: ${profile.userId}`, icon: ShieldCheck, iconColor: '#22c55e', color: '#22c55e' }, - { label: 'Premium Rate', val: `${profile.premiumRate}%`, sub: 'Standard α rate', icon: Zap, iconColor: '#3b82f6', color: '#3b82f6' }, - { label: 'Bonus Streak', val: `${profile.bonusStreak} wks`, sub: `Projected: ₹${profile.projectedBonus}`, icon: Clock, iconColor: '#f59e0b', color: '#f59e0b' }, + { label: 'Weekly Income', val: `₹${profile.weeklyIncome.toLocaleString('en-IN')}`, sub: 'Latest recorded income', icon: TrendingUp, color: '#f1f5f9' }, + { label: 'Policy Status', val: 'Active', sub: `User: ${profile.userId}`, icon: ShieldCheck, iconColor: '#22c55e', color: '#22c55e' }, + { label: 'Premium Rate', val: `${profile.premiumRate}%`, sub: 'Standard α rate', icon: Zap, iconColor: '#3b82f6', color: '#3b82f6' }, + { label: 'Bonus Streak', val: `${profile.bonusStreak} wks`, sub: `Projected: ₹${profile.projectedBonus}`, icon: Clock, iconColor: '#f59e0b', color: '#f59e0b' }, ]; return ( @@ -78,19 +78,19 @@ export default function Dashboard() {
- +
Income Snapshot D_s = 0.75
- +

₹{profile.weeklyIncome.toLocaleString('en-IN')}

- + 12% above weekly average