From 2adc602792beae1d6fc624844fb1e4c41b14045e Mon Sep 17 00:00:00 2001 From: Riccardo Fano Date: Thu, 25 Jan 2024 09:17:49 +0100 Subject: [PATCH] Debt doesn't make the total go negative --- components/MoneyForm.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/MoneyForm.tsx b/components/MoneyForm.tsx index 3fcfce5..245fbc8 100644 --- a/components/MoneyForm.tsx +++ b/components/MoneyForm.tsx @@ -28,7 +28,11 @@ function MoneyForm() { const intDonations = toNumber(donations) if (allValidNumbers([intTotal, intDebt, intDonations])) { - setMoney((intTotal - intDebt + intDonations).toString()) + let total = intTotal - intDebt + if (total < 0) { + total = 0 + } + setMoney((total + intDonations).toString()) } }, [mode, patrimonyValues, setMoney])