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:
@@ -36,7 +36,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
|
||||
tenantFirstName: z.string().optional().nullable(),
|
||||
tenantLastName: z.string().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(),
|
||||
updateScope: z.enum(["current", "subsequent", "all"]).optional().nullable(),
|
||||
})
|
||||
@@ -60,6 +60,15 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
|
||||
}, {
|
||||
message: t("tenant-last-name-required"),
|
||||
path: ["tenantLastName"],
|
||||
})
|
||||
.refine((data) => {
|
||||
if (data.autoTenantNotification) {
|
||||
return !!data.tenantEmail && data.tenantEmail.trim().length > 0;
|
||||
}
|
||||
return true;
|
||||
}, {
|
||||
message: t("tenant-email-required"),
|
||||
path: ["tenantEmail"],
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user