From 4be52214a24a05e185c22d97be2f304a432c5500 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 25 Apr 2026 18:51:47 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/components/cases/expenses-tab.tsx | 48 ++++++++++++++++++++------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/components/cases/expenses-tab.tsx b/src/components/cases/expenses-tab.tsx index 7cec103..faa6d9b 100644 --- a/src/components/cases/expenses-tab.tsx +++ b/src/components/cases/expenses-tab.tsx @@ -37,7 +37,8 @@ export function CaseExpensesTab({ caseId }: { caseId: string }) { const [form, setForm] = useState({ expense_date: new Date().toISOString().slice(0, 10), description: "", - amount: "", + quantity: "1", + unit_price: "", billable: true, }); const [receipt, setReceipt] = useState(null); @@ -102,8 +103,11 @@ export function CaseExpensesTab({ caseId }: { caseId: string }) { const submit = async (e: React.FormEvent) => { e.preventDefault(); - const amount = parseFloat(form.amount); - if (isNaN(amount) || amount < 0) { toast.error("Invalid amount"); return; } + const quantity = parseFloat(form.quantity); + const unit_price = parseFloat(form.unit_price); + if (isNaN(quantity) || quantity <= 0) { toast.error("Quantity must be greater than 0"); return; } + if (isNaN(unit_price) || unit_price < 0) { toast.error("Invalid unit price"); return; } + const amount = +(quantity * unit_price).toFixed(2); if (!form.description.trim()) { toast.error("Description required"); return; } setSubmitting(true); let receipt_storage_path: string | null = null; @@ -120,6 +124,8 @@ export function CaseExpensesTab({ caseId }: { caseId: string }) { expense_date: form.expense_date, description: form.description.trim(), amount, + quantity, + unit_price, billable: form.billable, receipt_storage_path, }); @@ -129,7 +135,7 @@ export function CaseExpensesTab({ caseId }: { caseId: string }) { toast.success("Expense added"); setShowForm(false); setReceipt(null); - setForm({ ...form, amount: "", description: "" }); + setForm({ ...form, quantity: "1", unit_price: "", description: "" }); if (fileRef.current) fileRef.current.value = ""; load(); } @@ -189,7 +195,8 @@ export function CaseExpensesTab({ caseId }: { caseId: string }) { if (fee) { setForm((f) => ({ ...f, - amount: String(fee.amount), + unit_price: String(fee.amount), + quantity: f.quantity || "1", billable: fee.billable, description: fee.description || fee.name, })); @@ -206,30 +213,43 @@ export function CaseExpensesTab({ caseId }: { caseId: string }) { /> )} -
+
setForm({ ...form, expense_date: e.target.value })} required />
- - setForm({ ...form, amount: e.target.value })} required /> + + setForm({ ...form, quantity: e.target.value })} required /> +
+
+ + setForm({ ...form, unit_price: e.target.value })} required /> +
+
+ +
setForm({ ...form, description: e.target.value })} required maxLength={500} />
-
+
-
+
setReceipt(e.target.files?.[0] ?? null)} />
-
+