diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index 74493de..eb6c42b 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -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", diff --git a/app/lib/db-types.ts b/app/lib/db-types.ts index 6754305..5af4818 100644 --- a/app/lib/db-types.ts +++ b/app/lib/db-types.ts @@ -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 */ diff --git a/app/ui/LocationEditForm.tsx b/app/ui/LocationEditForm.tsx index 10d645a..effe3b8 100644 --- a/app/ui/LocationEditForm.tsx +++ b/app/ui/LocationEditForm.tsx @@ -47,6 +47,8 @@ export const LocationEditForm: FC = ({ 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 = ({ location, yearMont -
+
@@ -143,6 +145,54 @@ export const LocationEditForm: FC = ({ location, yearMont ))}
+ +
+ + handleTenantFieldChange("tenantStreet", e.target.value)} + /> +
+ {state.errors?.tenantStreet && + state.errors.tenantStreet.map((error: string) => ( +

+ {error} +

+ ))} +
+
+ +
+ + handleTenantFieldChange("tenantTown", e.target.value)} + /> +
+ {state.errors?.tenantTown && + state.errors.tenantTown.map((error: string) => ( +

+ {error} +

+ ))} +
+
)} diff --git a/messages/en.json b/messages/en.json index 2626dd2..9d45efb 100644 --- a/messages/en.json +++ b/messages/en.json @@ -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", diff --git a/messages/hr.json b/messages/hr.json index fe0f6b8..83a65ca 100644 --- a/messages/hr.json +++ b/messages/hr.json @@ -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",