22import { Card , CardContent , CardHeader , CardTitle } from "@/components/ui/card" ;
33import { Apple , Pill , Wrench , Construction , Package } from "lucide-react" ;
44import { Expense } from "@/pages/Index" ;
5+ import { formatCurrency } from "@/utils/format" ;
56
67interface ExpenseSummaryProps {
78 expenses : Expense [ ] ;
@@ -14,18 +15,16 @@ export function ExpenseSummary({ expenses }: ExpenseSummaryProps) {
1415 . reduce ( ( total , expense ) => total + expense . amount , 0 ) ;
1516 } ;
1617
17- const formatCurrency = ( amount : number ) => {
18- return new Intl . NumberFormat ( 'en-US' , {
19- style : 'currency' ,
20- currency : 'USD'
21- } ) . format ( amount ) ;
18+ // Use centralized formatting utility
19+ const formatAmountAsCurrency = ( amount : number ) => {
20+ return formatCurrency ( amount ) ;
2221 } ;
2322
2423 const totalExpenses = expenses . reduce ( ( total , expense ) => total + expense . amount , 0 ) ;
2524 const foodTotal = calculateCategoryTotal ( 'food' ) ;
2625 const medicineTotal = calculateCategoryTotal ( 'medicine' ) ;
2726 const toolsTotal = calculateCategoryTotal ( 'tools' ) ;
28- const fenceTotal = calculateCategoryTotal ( 'fence ' ) ;
27+ const otherTotal = calculateCategoryTotal ( 'other ' ) ;
2928
3029 return (
3130 < >
@@ -35,7 +34,7 @@ export function ExpenseSummary({ expenses }: ExpenseSummaryProps) {
3534 < Package className = "h-4 w-4 text-gray-500" />
3635 </ CardHeader >
3736 < CardContent >
38- < div className = "text-2xl font-bold" > { formatCurrency ( totalExpenses ) } </ div >
37+ < div className = "text-2xl font-bold" > { formatAmountAsCurrency ( totalExpenses ) } </ div >
3938 < p className = "text-xs text-muted-foreground" > All time expenses</ p >
4039 </ CardContent >
4140 </ Card >
@@ -46,7 +45,7 @@ export function ExpenseSummary({ expenses }: ExpenseSummaryProps) {
4645 < Apple className = "h-4 w-4 text-green-500" />
4746 </ CardHeader >
4847 < CardContent >
49- < div className = "text-2xl font-bold" > { formatCurrency ( foodTotal ) } </ div >
48+ < div className = "text-2xl font-bold" > { formatAmountAsCurrency ( foodTotal ) } </ div >
5049 < p className = "text-xs text-muted-foreground" >
5150 { ( ( foodTotal / totalExpenses ) * 100 || 0 ) . toFixed ( 1 ) } % of total
5251 </ p >
@@ -59,7 +58,7 @@ export function ExpenseSummary({ expenses }: ExpenseSummaryProps) {
5958 < Pill className = "h-4 w-4 text-blue-500" />
6059 </ CardHeader >
6160 < CardContent >
62- < div className = "text-2xl font-bold" > { formatCurrency ( medicineTotal ) } </ div >
61+ < div className = "text-2xl font-bold" > { formatAmountAsCurrency ( medicineTotal ) } </ div >
6362 < p className = "text-xs text-muted-foreground" >
6463 { ( ( medicineTotal / totalExpenses ) * 100 || 0 ) . toFixed ( 1 ) } % of total
6564 </ p >
@@ -72,9 +71,9 @@ export function ExpenseSummary({ expenses }: ExpenseSummaryProps) {
7271 < Wrench className = "h-4 w-4 text-orange-500" />
7372 </ CardHeader >
7473 < CardContent >
75- < div className = "text-2xl font-bold" > { formatCurrency ( toolsTotal + fenceTotal ) } </ div >
74+ < div className = "text-2xl font-bold" > { formatAmountAsCurrency ( toolsTotal + otherTotal ) } </ div >
7675 < p className = "text-xs text-muted-foreground" >
77- { ( ( ( toolsTotal + fenceTotal ) / totalExpenses ) * 100 || 0 ) . toFixed ( 1 ) } % of total
76+ { ( ( ( toolsTotal + otherTotal ) / totalExpenses ) * 100 || 0 ) . toFixed ( 1 ) } % of total
7877 </ p >
7978 </ CardContent >
8079 </ Card >
0 commit comments