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>