From 67706c575df8c900ced8c77fa32657add78785d1 Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Tue, 18 Nov 2025 09:31:24 +0100 Subject: [PATCH] Add email validation to tenant email field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/lib/actions/locationActions.ts | 11 ++++++++++- messages/en.json | 2 ++ messages/hr.json | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index b0fb218..a90ee43 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -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"], }); /** diff --git a/messages/en.json b/messages/en.json index 38f6455..4cb1368 100644 --- a/messages/en.json +++ b/messages/en.json @@ -145,6 +145,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-email-required": "tenant email is missing", + "tenant-email-invalid": "email address is invalid", "validation-failed": "Validation failed. Please check the form and try again." } }, diff --git a/messages/hr.json b/messages/hr.json index 7f65d84..e76a481 100644 --- a/messages/hr.json +++ b/messages/hr.json @@ -144,6 +144,8 @@ "location-name-required": "Ime nekretnine je obavezno", "tenant-first-name-required": "nedostaje ime 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." } },