From 93cf159c4494b9178e7ad89bdd1c793f1eec3619 Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Tue, 18 Nov 2025 09:24:18 +0100 Subject: [PATCH] Add auto tenant notification toggle to LocationEditForm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added toggle to control automatic tenant notifications with conditional email field visibility based on the toggle state. Changes: - Added autoTenantNotification field to BillingLocation interface - Updated LocationEditForm with "Notify tenant automatically" toggle - Email field now only visible when autoTenantNotification is enabled - Toggle appears after tenant name fields (when generateTenantCode is active) - Updated updateOrAddLocation action to persist autoTenantNotification flag - Added localization strings for toggle (Croatian/English) Field visibility hierarchy: 1. Generate 2D code toggle (always visible) 2. Tenant name fields (visible when #1 is ON) 3. Auto notification toggle (visible when #1 is ON) 4. Email field (visible when #1 AND #3 are ON) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/lib/actions/locationActions.ts | 9 +++++ app/lib/db-types.ts | 2 + app/ui/LocationEditForm.tsx | 62 ++++++++++++++++++++---------- messages/en.json | 1 + messages/hr.json | 1 + 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index 539b0d0..b0fb218 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -18,6 +18,7 @@ export type State = { generateTenantCode?: string[]; tenantFirstName?: string[]; tenantLastName?: string[]; + autoTenantNotification?: string[]; tenantEmail?: string[]; }; message?:string | null; @@ -34,6 +35,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({ generateTenantCode: z.boolean().optional().nullable(), tenantFirstName: z.string().optional().nullable(), tenantLastName: z.string().optional().nullable(), + autoTenantNotification: z.boolean().optional().nullable(), tenantEmail: z.string().optional().nullable(), addToSubsequentMonths: z.boolean().optional().nullable(), updateScope: z.enum(["current", "subsequent", "all"]).optional().nullable(), @@ -79,6 +81,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat generateTenantCode: formData.get('generateTenantCode') === 'on', tenantFirstName: formData.get('tenantFirstName') || null, tenantLastName: formData.get('tenantLastName') || null, + autoTenantNotification: formData.get('autoTenantNotification') === 'on', tenantEmail: formData.get('tenantEmail') || null, addToSubsequentMonths: formData.get('addToSubsequentMonths') === 'on', updateScope: formData.get('updateScope') as "current" | "subsequent" | "all" | undefined, @@ -98,6 +101,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat generateTenantCode, tenantFirstName, tenantLastName, + autoTenantNotification, tenantEmail, addToSubsequentMonths, updateScope, @@ -135,6 +139,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat generateTenantCode: generateTenantCode || false, tenantFirstName: tenantFirstName || null, tenantLastName: tenantLastName || null, + autoTenantNotification: autoTenantNotification || false, tenantEmail: tenantEmail || null, } } @@ -160,6 +165,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat generateTenantCode: generateTenantCode || false, tenantFirstName: tenantFirstName || null, tenantLastName: tenantLastName || null, + autoTenantNotification: autoTenantNotification || false, tenantEmail: tenantEmail || null, } } @@ -178,6 +184,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat generateTenantCode: generateTenantCode || false, tenantFirstName: tenantFirstName || null, tenantLastName: tenantLastName || null, + autoTenantNotification: autoTenantNotification || false, tenantEmail: tenantEmail || null, } } @@ -194,6 +201,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat generateTenantCode: generateTenantCode || false, tenantFirstName: tenantFirstName || null, tenantLastName: tenantLastName || null, + autoTenantNotification: autoTenantNotification || false, tenantEmail: tenantEmail || null, yearMonth: yearMonth, bills: [], @@ -262,6 +270,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat generateTenantCode: generateTenantCode || false, tenantFirstName: tenantFirstName || null, tenantLastName: tenantLastName || null, + autoTenantNotification: autoTenantNotification || false, tenantEmail: tenantEmail || null, yearMonth: { year: monthData.year, month: monthData.month }, bills: [], diff --git a/app/lib/db-types.ts b/app/lib/db-types.ts index e920b37..e932b8f 100644 --- a/app/lib/db-types.ts +++ b/app/lib/db-types.ts @@ -49,6 +49,8 @@ export interface BillingLocation { tenantFirstName?: string | null; /** (optional) tenant last name */ tenantLastName?: string | null; + /** (optional) whether to automatically notify tenant */ + autoTenantNotification?: boolean | null; /** (optional) tenant email */ tenantEmail?: string | null; }; diff --git a/app/ui/LocationEditForm.tsx b/app/ui/LocationEditForm.tsx index 6e0b3a7..ae6bf85 100644 --- a/app/ui/LocationEditForm.tsx +++ b/app/ui/LocationEditForm.tsx @@ -32,6 +32,11 @@ export const LocationEditForm: FC = ({ location, yearMont location?.generateTenantCode ?? false ); + // Track whether to automatically notify tenant (use persisted value from database) + const [autoTenantNotification, setAutoTenantNotification] = useState( + location?.autoTenantNotification ?? false + ); + // Track tenant field values for real-time validation const [tenantFields, setTenantFields] = useState({ tenantFirstName: location?.tenantFirstName ?? "", @@ -113,7 +118,7 @@ export const LocationEditForm: FC = ({ location, yearMont -
+
@@ -138,29 +143,44 @@ export const LocationEditForm: FC = ({ location, yearMont )} -
-