Add tenantStreet and tenantTown fields to LocationEditForm

- Added tenantStreet and tenantTown optional fields to BillingLocation interface
- Updated LocationEditForm to include new input fields with 27 character max length
- Both fields are mandatory when 2D code generation is enabled
- Updated all database operations (insert and update) to persist new fields
- Added Croatian and English translations for labels and validation messages
- Updated form state tracking to include new tenant address fields

🤖 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-22 15:33:00 +01:00
parent 3cf880a661
commit ec39eda51f
5 changed files with 103 additions and 1 deletions

View File

@@ -17,6 +17,8 @@ export type State = {
generateTenantCode?: string[];
tenantFirstName?: string[];
tenantLastName?: string[];
tenantStreet?: string[];
tenantTown?: string[];
autoBillFwd?: string[];
tenantEmail?: string[];
billFwdStrategy?: string[];
@@ -37,6 +39,8 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
generateTenantCode: z.boolean().optional().nullable(),
tenantFirstName: z.string().optional().nullable(),
tenantLastName: z.string().optional().nullable(),
tenantStreet: z.string().max(27).optional().nullable(),
tenantTown: z.string().max(27).optional().nullable(),
autoBillFwd: z.boolean().optional().nullable(),
tenantEmail: z.string().email(t("tenant-email-invalid")).optional().or(z.literal("")).nullable(),
billFwdStrategy: z.enum(["when-payed", "when-attached"]).optional().nullable(),
@@ -67,6 +71,24 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
message: t("tenant-last-name-required"),
path: ["tenantLastName"],
})
.refine((data) => {
if (data.generateTenantCode) {
return !!data.tenantStreet && data.tenantStreet.trim().length > 0;
}
return true;
}, {
message: t("tenant-street-required"),
path: ["tenantStreet"],
})
.refine((data) => {
if (data.generateTenantCode) {
return !!data.tenantTown && data.tenantTown.trim().length > 0;
}
return true;
}, {
message: t("tenant-town-required"),
path: ["tenantTown"],
})
.refine((data) => {
if (data.autoBillFwd || data.rentDueNotification) {
return !!data.tenantEmail && data.tenantEmail.trim().length > 0;
@@ -104,6 +126,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
generateTenantCode: formData.get('generateTenantCode') === 'on',
tenantFirstName: formData.get('tenantFirstName') || null,
tenantLastName: formData.get('tenantLastName') || null,
tenantStreet: formData.get('tenantStreet') || null,
tenantTown: formData.get('tenantTown') || null,
autoBillFwd: formData.get('autoBillFwd') === 'on',
tenantEmail: formData.get('tenantEmail') || null,
billFwdStrategy: formData.get('billFwdStrategy') as "when-payed" | "when-attached" | undefined,
@@ -127,6 +151,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
generateTenantCode,
tenantFirstName,
tenantLastName,
tenantStreet,
tenantTown,
autoBillFwd,
tenantEmail,
billFwdStrategy,
@@ -168,6 +194,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null,
tenantStreet: tenantStreet || null,
tenantTown: tenantTown || null,
autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null,
billFwdStrategy: billFwdStrategy || "when-payed",
@@ -197,6 +225,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null,
tenantStreet: tenantStreet || null,
tenantTown: tenantTown || null,
autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null,
billFwdStrategy: billFwdStrategy || "when-payed",
@@ -219,6 +249,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null,
tenantStreet: tenantStreet || null,
tenantTown: tenantTown || null,
autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null,
billFwdStrategy: billFwdStrategy || "when-payed",
@@ -240,6 +272,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null,
tenantStreet: tenantStreet || null,
tenantTown: tenantTown || null,
autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null,
billFwdStrategy: billFwdStrategy || "when-payed",
@@ -313,6 +347,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null,
tenantStreet: tenantStreet || null,
tenantTown: tenantTown || null,
autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null,
billFwdStrategy: billFwdStrategy || "when-payed",

View File

@@ -55,6 +55,10 @@ export interface BillingLocation {
tenantFirstName?: string | null;
/** (optional) tenant last name */
tenantLastName?: string | null;
/** (optional) tenant street */
tenantStreet?: string | null;
/** (optional) tenant town */
tenantTown?: string | null;
/** (optional) whether to automatically notify tenant */
autoBillFwd?: boolean | null;
/** (optional) tenant email */

View File

@@ -47,6 +47,8 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
const [tenantFields, setTenantFields] = useState({
tenantFirstName: location?.tenantFirstName ?? "",
tenantLastName: location?.tenantLastName ?? "",
tenantStreet: location?.tenantStreet ?? "",
tenantTown: location?.tenantTown ?? "",
tenantEmail: location?.tenantEmail ?? "",
});
@@ -121,7 +123,7 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
</div>
</div>
<div className="form-control w-full mb-4">
<div className="form-control w-full">
<label className="label">
<span className="label-text">{t("tenant-last-name-label")}</span>
</label>
@@ -143,6 +145,54 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
))}
</div>
</div>
<div className="form-control w-full">
<label className="label">
<span className="label-text">{t("tenant-street-label")}</span>
</label>
<input
id="tenantStreet"
name="tenantStreet"
type="text"
maxLength={27}
placeholder={t("tenant-street-placeholder")}
className="input input-bordered w-full placeholder:text-gray-600"
defaultValue={location?.tenantStreet ?? ""}
onChange={(e) => handleTenantFieldChange("tenantStreet", e.target.value)}
/>
<div id="tenantStreet-error" aria-live="polite" aria-atomic="true">
{state.errors?.tenantStreet &&
state.errors.tenantStreet.map((error: string) => (
<p className="mt-2 text-sm text-red-500" key={error}>
{error}
</p>
))}
</div>
</div>
<div className="form-control w-full mb-4">
<label className="label">
<span className="label-text">{t("tenant-town-label")}</span>
</label>
<input
id="tenantTown"
name="tenantTown"
type="text"
maxLength={27}
placeholder={t("tenant-town-placeholder")}
className="input input-bordered w-full placeholder:text-gray-600"
defaultValue={location?.tenantTown ?? ""}
onChange={(e) => handleTenantFieldChange("tenantTown", e.target.value)}
/>
<div id="tenantTown-error" aria-live="polite" aria-atomic="true">
{state.errors?.tenantTown &&
state.errors.tenantTown.map((error: string) => (
<p className="mt-2 text-sm text-red-500" key={error}>
{error}
</p>
))}
</div>
</div>
</>
)}
</fieldset>

View File

@@ -144,6 +144,10 @@
"tenant-first-name-placeholder": "Enter tenant's first name",
"tenant-last-name-label": "Tenant Last Name",
"tenant-last-name-placeholder": "Enter tenant's last name",
"tenant-street-label": "Tenant Street",
"tenant-street-placeholder": "Enter tenant's street",
"tenant-town-label": "Tenant Town",
"tenant-town-placeholder": "Enter tenant's town",
"auto-utility-bill-forwarding-legend": "AUTOMATIC UTILITY BILL FORWARDING",
"auto-utility-bill-forwarding-info": "This option enables automatic forwarding of utility bills to the tenant via email according to the selected forwarding strategy.",
"auto-utility-bill-forwarding-toggle-label": "forward utility bills",
@@ -173,6 +177,8 @@
"location-name-required": "Relaestate name is required",
"tenant-first-name-required": "tenant first name is missing",
"tenant-last-name-required": "tenant last name is missing",
"tenant-street-required": "tenant street is missing",
"tenant-town-required": "tenant town is missing",
"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",

View File

@@ -143,6 +143,10 @@
"tenant-first-name-placeholder": "Unesite ime podstanara",
"tenant-last-name-label": "Prezime podstanara",
"tenant-last-name-placeholder": "Unesite prezime podstanara",
"tenant-street-label": "Ulica podstanara",
"tenant-street-placeholder": "Unesite ulicu podstanara",
"tenant-town-label": "Grad podstanara",
"tenant-town-placeholder": "Unesite grad podstanara",
"auto-utility-bill-forwarding-legend": "AUTOMATSKO PROSLJEĐIVANJE REŽIJA",
"auto-utility-bill-forwarding-info": "Ova opcija omogućuje automatsko prosljeđivanje režija podstanaru putem emaila u skladu s odabranom strategijom.",
"auto-utility-bill-forwarding-toggle-label": "proslijedi režije automatski",
@@ -172,6 +176,8 @@
"location-name-required": "Ime nekretnine je obavezno",
"tenant-first-name-required": "nedostaje ime podstanara",
"tenant-last-name-required": "nedostaje prezime podstanara",
"tenant-street-required": "nedostaje ulica podstanara",
"tenant-town-required": "nedostaje grad podstanara",
"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",