From 4ba584183902bd6a1b1e8aae4588d286ab1f914c Mon Sep 17 00:00:00 2001 From: renato97 Date: Thu, 29 Jan 2026 01:00:21 +0000 Subject: [PATCH] feat: add consumption tracking for services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhanced services module with comprehensive consumption tracking: - Add usage field to ServiceBill interface (optional number) - Add unit field to ServiceBill interface (kW, m³, or empty for internet) - Updated AddServiceModal with consumption input field - Auto-detect unit based on service type (electricity=kW, gas/water=m³, internet=none) - Responsive grid layout for amount and consumption inputs - Display consumption and unit in history list - Show price per unit in history (amount/usage) - Improved date display with responsive layout 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- app/services/page.tsx | 21 ++++++++- components/modals/AddServiceModal.tsx | 66 +++++++++++++++++++++------ lib/types.ts | 2 + 3 files changed, 72 insertions(+), 17 deletions(-) diff --git a/app/services/page.tsx b/app/services/page.tsx index aeff381..5fe0792 100644 --- a/app/services/page.tsx +++ b/app/services/page.tsx @@ -105,12 +105,29 @@ export default function ServicesPage() {

{service?.label || bill.type}

-

{new Date(bill.date).toLocaleDateString('es-AR', { dateStyle: 'long' })}

+
+

{new Date(bill.date).toLocaleDateString('es-AR', { dateStyle: 'long' })}

+ {bill.usage && ( + <> + +

+ Consumo: {bill.usage} {bill.unit} +

+ + )} +

{formatCurrency(bill.amount)}

-

{bill.period}

+
+

{bill.period}

+ {bill.usage && bill.amount && ( +

+ {formatCurrency(bill.amount / bill.usage)} / {bill.unit} +

+ )} +
) diff --git a/components/modals/AddServiceModal.tsx b/components/modals/AddServiceModal.tsx index 0aef630..d3e9b2d 100644 --- a/components/modals/AddServiceModal.tsx +++ b/components/modals/AddServiceModal.tsx @@ -22,11 +22,24 @@ export function AddServiceModal({ isOpen, onClose }: AddServiceModalProps) { const [type, setType] = useState('electricity') const [amount, setAmount] = useState('') + const [usage, setUsage] = useState('') const [period, setPeriod] = useState(new Date().toISOString().slice(0, 7)) // YYYY-MM const [date, setDate] = useState(new Date().toISOString().split('T')[0]) if (!isOpen) return null + const getUnit = (serviceType: string) => { + switch (serviceType) { + case 'electricity': return 'kW' + case 'gas': return 'm³' + case 'water': return 'm³' + default: return '' + } + } + + const unit = getUnit(type) + const showUsage = type !== 'internet' + const handleSubmit = (e: React.FormEvent) => { e.preventDefault() @@ -35,6 +48,8 @@ export function AddServiceModal({ isOpen, onClose }: AddServiceModalProps) { addServiceBill({ type: type as any, amount: parseFloat(amount), + usage: usage ? parseFloat(usage) : undefined, + unit: unit || undefined, date: new Date(date).toISOString(), period: period, notes: '' @@ -42,6 +57,7 @@ export function AddServiceModal({ isOpen, onClose }: AddServiceModalProps) { // Reset setAmount('') + setUsage('') onClose() } @@ -81,22 +97,42 @@ export function AddServiceModal({ isOpen, onClose }: AddServiceModalProps) { })} - {/* Amount */} -
- -
- $ - setAmount(e.target.value)} - className="w-full pl-8 pr-4 py-3 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-cyan-500/50 focus:border-cyan-500 text-white text-lg font-mono outline-none" - required - autoFocus - /> +
+ {/* Amount */} +
+ +
+ $ + setAmount(e.target.value)} + className="w-full pl-8 pr-4 py-3 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-cyan-500/50 focus:border-cyan-500 text-white text-lg font-mono outline-none" + required + autoFocus + /> +
+ + {/* Usage */} + {showUsage && ( +
+ +
+ setUsage(e.target.value)} + className="w-full px-4 py-3 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-cyan-500/50 focus:border-cyan-500 text-white text-lg font-mono outline-none" + /> + {unit} +
+
+ )}
diff --git a/lib/types.ts b/lib/types.ts index b369283..3da0ad8 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -66,6 +66,8 @@ export interface ServiceBill { id: string type: 'electricity' | 'water' | 'gas' | 'internet' amount: number + usage?: number + unit?: string date: string period: string // YYYY-MM isPaid: boolean