From 3540ef596b12162e182e07d17f4679ce0af8a41e Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Tue, 18 Nov 2025 23:06:42 +0100 Subject: [PATCH] Enforce integer-only values for rent amount field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add .int() validation to rentAmount in FormSchema - Remove decimal formatting (was dividing by 100) - Change min value from 0 to 1 - Add right text alignment for better numeric display - Add localization for integer validation error message đŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/lib/actions/locationActions.ts | 2 +- app/ui/LocationEditForm.tsx | 6 +++--- messages/en.json | 1 + messages/hr.json | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index 3c1e0d1..ae36b81 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -42,7 +42,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({ billFwdStrategy: z.enum(["when-payed", "when-attached"]).optional().nullable(), rentDueNotification: z.boolean().optional().nullable(), rentDueDay: z.coerce.number().min(1).max(31).optional().nullable(), - rentAmount: z.coerce.number().positive(t("rent-amount-positive")).optional().nullable(), + rentAmount: z.coerce.number().int(t("rent-amount-integer")).positive(t("rent-amount-positive")).optional().nullable(), addToSubsequentMonths: z.boolean().optional().nullable(), updateScope: z.enum(["current", "subsequent", "all"]).optional().nullable(), }) diff --git a/app/ui/LocationEditForm.tsx b/app/ui/LocationEditForm.tsx index 38d4a99..10d645a 100644 --- a/app/ui/LocationEditForm.tsx +++ b/app/ui/LocationEditForm.tsx @@ -209,11 +209,11 @@ export const LocationEditForm: FC = ({ location, yearMont id="rentAmount" name="rentAmount" type="number" + min="1" step="0.01" - min="0" placeholder={t("rent-amount-placeholder")} - className="input input-bordered w-full placeholder:text-gray-600" - defaultValue={location?.rentAmount ? (location.rentAmount / 100).toFixed(2) : ""} + className="input input-bordered w-full placeholder:text-gray-600 text-right" + defaultValue={location?.rentAmount ?? ""} />
{state.errors?.rentAmount && diff --git a/messages/en.json b/messages/en.json index bdd9f5d..6e71016 100644 --- a/messages/en.json +++ b/messages/en.json @@ -164,6 +164,7 @@ "tenant-email-required": "tenant email is missing", "tenant-email-invalid": "email address is invalid", "rent-amount-required": "rent amount is required when rent notification is enabled", + "rent-amount-integer": "rent amount must be a whole number (no decimal places)", "rent-amount-positive": "rent amount must be a positive number", "validation-failed": "Validation failed. Please check the form and try again." } diff --git a/messages/hr.json b/messages/hr.json index f7b01db..e809bf1 100644 --- a/messages/hr.json +++ b/messages/hr.json @@ -163,6 +163,7 @@ "tenant-email-required": "nedostaje email podstanara", "tenant-email-invalid": "email adresa nije ispravna", "rent-amount-required": "iznos najamnine je obavezan kada je uključena obavijest o najamnini", + "rent-amount-integer": "iznos najamnine mora biti cijeli broj (bez decimalnih mjesta)", "rent-amount-positive": "iznos najamnine mora biti pozitivan broj", "validation-failed": "Validacija nije uspjela. Molimo provjerite formu i pokuơajte ponovno." }