Add rent amount field to location form

- Add rentAmount field to BillingLocation interface (stored in cents)
- Implement Zod validation with conditional requirement when rent notification is enabled
- Add rent amount input field to LocationEditForm with decimal display
- Update all database operations to persist rentAmount
- Add localization strings for both English and Croatian
- Fix missing notes field in insertOne/insertMany operations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Knee Cola
2025-11-18 13:06:29 +01:00
parent be5d5074fe
commit bfa9afdb45
5 changed files with 61 additions and 8 deletions

View File

@@ -22,6 +22,7 @@ export type State = {
billFwdStrategy?: string[]; billFwdStrategy?: string[];
rentDueNotification?: string[]; rentDueNotification?: string[];
rentDueDay?: string[]; rentDueDay?: string[];
rentAmount?: string[];
}; };
message?:string | null; message?:string | null;
}; };
@@ -41,6 +42,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
billFwdStrategy: z.enum(["when-payed", "when-attached"]).optional().nullable(), billFwdStrategy: z.enum(["when-payed", "when-attached"]).optional().nullable(),
rentDueNotification: z.boolean().optional().nullable(), rentDueNotification: z.boolean().optional().nullable(),
rentDueDay: z.coerce.number().min(1).max(31).optional().nullable(), rentDueDay: z.coerce.number().min(1).max(31).optional().nullable(),
rentAmount: z.coerce.number().positive(t("rent-amount-positive")).optional().nullable(),
addToSubsequentMonths: z.boolean().optional().nullable(), addToSubsequentMonths: z.boolean().optional().nullable(),
updateScope: z.enum(["current", "subsequent", "all"]).optional().nullable(), updateScope: z.enum(["current", "subsequent", "all"]).optional().nullable(),
}) })
@@ -73,6 +75,15 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
}, { }, {
message: t("tenant-email-required"), message: t("tenant-email-required"),
path: ["tenantEmail"], path: ["tenantEmail"],
})
.refine((data) => {
if (data.rentDueNotification) {
return !!data.rentAmount && data.rentAmount > 0;
}
return true;
}, {
message: t("rent-amount-required"),
path: ["rentAmount"],
}); });
/** /**
@@ -98,6 +109,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
billFwdStrategy: formData.get('billFwdStrategy') as "when-payed" | "when-attached" | undefined, billFwdStrategy: formData.get('billFwdStrategy') as "when-payed" | "when-attached" | undefined,
rentDueNotification: formData.get('rentDueNotification') === 'on', rentDueNotification: formData.get('rentDueNotification') === 'on',
rentDueDay: formData.get('rentDueDay') || null, rentDueDay: formData.get('rentDueDay') || null,
rentAmount: formData.get('rentAmount') || null,
addToSubsequentMonths: formData.get('addToSubsequentMonths') === 'on', addToSubsequentMonths: formData.get('addToSubsequentMonths') === 'on',
updateScope: formData.get('updateScope') as "current" | "subsequent" | "all" | undefined, updateScope: formData.get('updateScope') as "current" | "subsequent" | "all" | undefined,
}); });
@@ -120,6 +132,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
billFwdStrategy, billFwdStrategy,
rentDueNotification, rentDueNotification,
rentDueDay, rentDueDay,
rentAmount,
addToSubsequentMonths, addToSubsequentMonths,
updateScope, updateScope,
} = validatedFields.data; } = validatedFields.data;
@@ -160,6 +173,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
billFwdStrategy: billFwdStrategy || "when-payed", billFwdStrategy: billFwdStrategy || "when-payed",
rentDueNotification: rentDueNotification || false, rentDueNotification: rentDueNotification || false,
rentDueDay: rentDueDay || null, rentDueDay: rentDueDay || null,
rentAmount: rentAmount || null,
} }
} }
); );
@@ -188,6 +202,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
billFwdStrategy: billFwdStrategy || "when-payed", billFwdStrategy: billFwdStrategy || "when-payed",
rentDueNotification: rentDueNotification || false, rentDueNotification: rentDueNotification || false,
rentDueDay: rentDueDay || null, rentDueDay: rentDueDay || null,
rentAmount: rentAmount || null,
} }
} }
); );
@@ -209,6 +224,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
billFwdStrategy: billFwdStrategy || "when-payed", billFwdStrategy: billFwdStrategy || "when-payed",
rentDueNotification: rentDueNotification || false, rentDueNotification: rentDueNotification || false,
rentDueDay: rentDueDay || null, rentDueDay: rentDueDay || null,
rentAmount: rentAmount || null,
} }
} }
); );
@@ -220,6 +236,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
userId, userId,
userEmail, userEmail,
name: locationName, name: locationName,
notes: null,
generateTenantCode: generateTenantCode || false, generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null, tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null, tenantLastName: tenantLastName || null,
@@ -228,6 +245,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
billFwdStrategy: billFwdStrategy || "when-payed", billFwdStrategy: billFwdStrategy || "when-payed",
rentDueNotification: rentDueNotification || false, rentDueNotification: rentDueNotification || false,
rentDueDay: rentDueDay || null, rentDueDay: rentDueDay || null,
rentAmount: rentAmount || null,
yearMonth: yearMonth, yearMonth: yearMonth,
bills: [], bills: [],
}); });
@@ -291,6 +309,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
userId, userId,
userEmail, userEmail,
name: locationName, name: locationName,
notes: null,
generateTenantCode: generateTenantCode || false, generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null, tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null, tenantLastName: tenantLastName || null,
@@ -299,6 +318,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
billFwdStrategy: billFwdStrategy || "when-payed", billFwdStrategy: billFwdStrategy || "when-payed",
rentDueNotification: rentDueNotification || false, rentDueNotification: rentDueNotification || false,
rentDueDay: rentDueDay || null, rentDueDay: rentDueDay || null,
rentAmount: rentAmount || null,
yearMonth: { year: monthData.year, month: monthData.month }, yearMonth: { year: monthData.year, month: monthData.month },
bills: [], bills: [],
}); });

View File

@@ -61,6 +61,8 @@ export interface BillingLocation {
rentDueNotification?: boolean | null; rentDueNotification?: boolean | null;
/** (optional) day of month when rent is due (1-31) */ /** (optional) day of month when rent is due (1-31) */
rentDueDay?: number | null; rentDueDay?: number | null;
/** (optional) monthly rent amount in cents */
rentAmount?: number | null;
}; };
export enum BilledTo { export enum BilledTo {

View File

@@ -194,6 +194,7 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
</fieldset> </fieldset>
{rentDueNotification && ( {rentDueNotification && (
<>
<fieldset className="fieldset mt-2 p-2"> <fieldset className="fieldset mt-2 p-2">
<legend className="fieldset-legend">{t("rent-due-day-label")}</legend> <legend className="fieldset-legend">{t("rent-due-day-label")}</legend>
<select defaultValue={location?.rentDueDay ?? 1} className="select input-bordered w-full" name="rentDueDay"> <select defaultValue={location?.rentDueDay ?? 1} className="select input-bordered w-full" name="rentDueDay">
@@ -202,6 +203,28 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
))} ))}
</select> </select>
</fieldset> </fieldset>
<fieldset className="fieldset mt-2 p-2">
<legend className="fieldset-legend">{t("rent-amount-label")}</legend>
<input
id="rentAmount"
name="rentAmount"
type="number"
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) : ""}
/>
<div id="rentAmount-error" aria-live="polite" aria-atomic="true">
{state.errors?.rentAmount &&
state.errors.rentAmount.map((error: string) => (
<p className="mt-2 text-sm text-red-500" key={error}>
{error}
</p>
))}
</div>
</fieldset>
</>
)} )}
</fieldset> </fieldset>

View File

@@ -142,6 +142,8 @@
"auto-rent-notification-info": "This option enables automatic sending of monthly rent bill to the tenant via email on the specified day of the month.", "auto-rent-notification-info": "This option enables automatic sending of monthly rent bill to the tenant via email on the specified day of the month.",
"auto-rent-notification-toggle-label": "send rent notification", "auto-rent-notification-toggle-label": "send rent notification",
"rent-due-day-label": "Day of month when rent is due", "rent-due-day-label": "Day of month when rent is due",
"rent-amount-label": "Monthly rent amount",
"rent-amount-placeholder": "Enter rent amount",
"tenant-email-legend": "TENANT EMAIL", "tenant-email-legend": "TENANT EMAIL",
"tenant-email-placeholder": "Enter tenant's email", "tenant-email-placeholder": "Enter tenant's email",
"warning-missing-tenant-names": "Warning: Tenant first and last name are missing. The 2D barcode will not be displayed to the tenant when they open the shared link until both fields are filled in.", "warning-missing-tenant-names": "Warning: Tenant first and last name are missing. The 2D barcode will not be displayed to the tenant when they open the shared link until both fields are filled in.",
@@ -161,6 +163,8 @@
"tenant-last-name-required": "tenant last name is missing", "tenant-last-name-required": "tenant last name is missing",
"tenant-email-required": "tenant email is missing", "tenant-email-required": "tenant email is missing",
"tenant-email-invalid": "email address is invalid", "tenant-email-invalid": "email address is invalid",
"rent-amount-required": "rent amount is required when rent notification is enabled",
"rent-amount-positive": "rent amount must be a positive number",
"validation-failed": "Validation failed. Please check the form and try again." "validation-failed": "Validation failed. Please check the form and try again."
} }
}, },

View File

@@ -141,6 +141,8 @@
"auto-rent-notification-info": "Ova opcija omogućuje automatsko slanje mjesečnog računa za najamninu podstanaru putem emaila na zadani dan u mjesecu.", "auto-rent-notification-info": "Ova opcija omogućuje automatsko slanje mjesečnog računa za najamninu podstanaru putem emaila na zadani dan u mjesecu.",
"auto-rent-notification-toggle-label": "pošalji obavijest o najamnini", "auto-rent-notification-toggle-label": "pošalji obavijest o najamnini",
"rent-due-day-label": "Dan u mjesecu kada dospijeva najamnina", "rent-due-day-label": "Dan u mjesecu kada dospijeva najamnina",
"rent-amount-label": "Iznos najamnine",
"rent-amount-placeholder": "Unesite iznos najamnine",
"tenant-email-legend": "EMAIL PODSTANARA", "tenant-email-legend": "EMAIL PODSTANARA",
"tenant-email-placeholder": "Unesite email podstanara", "tenant-email-placeholder": "Unesite email podstanara",
"warning-missing-tenant-names": "Upozorenje: Ime i prezime podstanara nedostaju. 2D barkod neće biti prikazan podstanaru kada otvori podijeljenu poveznicu dok oba polja ne budu popunjena.", "warning-missing-tenant-names": "Upozorenje: Ime i prezime podstanara nedostaju. 2D barkod neće biti prikazan podstanaru kada otvori podijeljenu poveznicu dok oba polja ne budu popunjena.",
@@ -160,6 +162,8 @@
"tenant-last-name-required": "nedostaje prezime podstanara", "tenant-last-name-required": "nedostaje prezime podstanara",
"tenant-email-required": "nedostaje email podstanara", "tenant-email-required": "nedostaje email podstanara",
"tenant-email-invalid": "email adresa nije ispravna", "tenant-email-invalid": "email adresa nije ispravna",
"rent-amount-required": "iznos najamnine je obavezan kada je uključena obavijest o najamnini",
"rent-amount-positive": "iznos najamnine mora biti pozitivan broj",
"validation-failed": "Validacija nije uspjela. Molimo provjerite formu i pokušajte ponovno." "validation-failed": "Validacija nije uspjela. Molimo provjerite formu i pokušajte ponovno."
} }
}, },