Add email validation to tenant email field

Added conditional required validation and format validation for tenant email.

Changes:
- Tenant email is now required when autoTenantNotification is enabled
- Added email format validation using Zod's built-in email validator
- Email field validates format even when autoTenantNotification is off (if not empty)
- Added localization strings for validation errors (Croatian/English)

Validation logic:
- Format validation: Always checks if email is valid format (when not empty)
- Required validation: Email required when autoTenantNotification is true
- Error messages: "email address is invalid" for format, "tenant email is missing" for required

🤖 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 09:31:24 +01:00
parent 93cf159c44
commit 67706c575d
3 changed files with 14 additions and 1 deletions

View File

@@ -36,7 +36,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
tenantFirstName: z.string().optional().nullable(), tenantFirstName: z.string().optional().nullable(),
tenantLastName: z.string().optional().nullable(), tenantLastName: z.string().optional().nullable(),
autoTenantNotification: z.boolean().optional().nullable(), autoTenantNotification: z.boolean().optional().nullable(),
tenantEmail: z.string().optional().nullable(), tenantEmail: z.string().email(t("tenant-email-invalid")).optional().or(z.literal("")).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(),
}) })
@@ -60,6 +60,15 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
}, { }, {
message: t("tenant-last-name-required"), message: t("tenant-last-name-required"),
path: ["tenantLastName"], path: ["tenantLastName"],
})
.refine((data) => {
if (data.autoTenantNotification) {
return !!data.tenantEmail && data.tenantEmail.trim().length > 0;
}
return true;
}, {
message: t("tenant-email-required"),
path: ["tenantEmail"],
}); });
/** /**

View File

@@ -145,6 +145,8 @@
"location-name-required": "Relaestate name is required", "location-name-required": "Relaestate name is required",
"tenant-first-name-required": "tenant first name is missing", "tenant-first-name-required": "tenant first name is missing",
"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-invalid": "email address is invalid",
"validation-failed": "Validation failed. Please check the form and try again." "validation-failed": "Validation failed. Please check the form and try again."
} }
}, },

View File

@@ -144,6 +144,8 @@
"location-name-required": "Ime nekretnine je obavezno", "location-name-required": "Ime nekretnine je obavezno",
"tenant-first-name-required": "nedostaje ime podstanara", "tenant-first-name-required": "nedostaje ime podstanara",
"tenant-last-name-required": "nedostaje prezime podstanara", "tenant-last-name-required": "nedostaje prezime podstanara",
"tenant-email-required": "nedostaje email podstanara",
"tenant-email-invalid": "email adresa nije ispravna",
"validation-failed": "Validacija nije uspjela. Molimo provjerite formu i pokušajte ponovno." "validation-failed": "Validacija nije uspjela. Molimo provjerite formu i pokušajte ponovno."
} }
}, },