From 63096be13350ac279227a3ede6677eb92f307d6b Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Tue, 18 Nov 2025 11:29:57 +0100 Subject: [PATCH] Add automatic rent notification feature to LocationEditForm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add rentDueNotification toggle to enable automatic rent notifications - Add rentDueDay selector (1-28) for specifying when rent is due - Extract tenant email to independent section shown when either autoBillFwd or rentDueNotification is enabled - Update email validation to be mandatory when any automatic notification is active - Update database schema to persist rentDueNotification and rentDueDay fields - Add all database operations to handle new fields with proper defaults - Add localization strings for English and Croatian 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/lib/actions/locationActions.ts | 20 ++++++- app/lib/db-types.ts | 4 ++ app/ui/LocationEditForm.tsx | 93 ++++++++++++++++++++---------- messages/en.json | 8 ++- messages/hr.json | 8 ++- 5 files changed, 99 insertions(+), 34 deletions(-) diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index c3daf65..ef54c39 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -21,6 +21,8 @@ export type State = { autoBillFwd?: string[]; tenantEmail?: string[]; billFwdStrategy?: string[]; + rentDueNotification?: string[]; + rentDueDay?: string[]; }; message?:string | null; }; @@ -39,6 +41,8 @@ const FormSchema = (t:IntlTemplateFn) => z.object({ 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(), + rentDueNotification: z.boolean().optional().nullable(), + rentDueDay: z.coerce.number().min(1).max(31).optional().nullable(), addToSubsequentMonths: z.boolean().optional().nullable(), updateScope: z.enum(["current", "subsequent", "all"]).optional().nullable(), }) @@ -64,7 +68,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({ path: ["tenantLastName"], }) .refine((data) => { - if (data.autoBillFwd) { + if (data.autoBillFwd || data.rentDueNotification) { return !!data.tenantEmail && data.tenantEmail.trim().length > 0; } return true; @@ -95,6 +99,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat autoBillFwd: formData.get('autoBillFwd') === 'on', tenantEmail: formData.get('tenantEmail') || null, billFwdStrategy: formData.get('billFwdStrategy') as "when-payed" | "when-attached" | undefined, + rentDueNotification: formData.get('rentDueNotification') === 'on', + rentDueDay: formData.get('rentDueDay') || null, addToSubsequentMonths: formData.get('addToSubsequentMonths') === 'on', updateScope: formData.get('updateScope') as "current" | "subsequent" | "all" | undefined, }); @@ -116,6 +122,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat autoBillFwd, tenantEmail, billFwdStrategy, + rentDueNotification, + rentDueDay, addToSubsequentMonths, updateScope, } = validatedFields.data; @@ -155,6 +163,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat autoBillFwd: autoBillFwd || false, tenantEmail: tenantEmail || null, billFwdStrategy: billFwdStrategy || "when-payed", + rentDueNotification: rentDueNotification || false, + rentDueDay: rentDueDay || null, } } ); @@ -182,6 +192,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat autoBillFwd: autoBillFwd || false, tenantEmail: tenantEmail || null, billFwdStrategy: billFwdStrategy || "when-payed", + rentDueNotification: rentDueNotification || false, + rentDueDay: rentDueDay || null, } } ); @@ -202,6 +214,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat autoBillFwd: autoBillFwd || false, tenantEmail: tenantEmail || null, billFwdStrategy: billFwdStrategy || "when-payed", + rentDueNotification: rentDueNotification || false, + rentDueDay: rentDueDay || null, } } ); @@ -220,6 +234,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat autoBillFwd: autoBillFwd || false, tenantEmail: tenantEmail || null, billFwdStrategy: billFwdStrategy || "when-payed", + rentDueNotification: rentDueNotification || false, + rentDueDay: rentDueDay || null, yearMonth: yearMonth, bills: [], }); @@ -290,6 +306,8 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat autoBillFwd: autoBillFwd || false, tenantEmail: tenantEmail || null, billFwdStrategy: billFwdStrategy || "when-payed", + rentDueNotification: rentDueNotification || false, + rentDueDay: rentDueDay || null, yearMonth: { year: monthData.year, month: monthData.month }, bills: [], }); diff --git a/app/lib/db-types.ts b/app/lib/db-types.ts index 103f303..fc8f4a5 100644 --- a/app/lib/db-types.ts +++ b/app/lib/db-types.ts @@ -55,6 +55,10 @@ export interface BillingLocation { tenantEmail?: string | null; /** (optional) bill forwarding strategy */ billFwdStrategy?: "when-payed" | "when-attached" | null; + /** (optional) whether to automatically send rent notification */ + rentDueNotification?: boolean | null; + /** (optional) day of month when rent is due (1-31) */ + rentDueDay?: number | null; }; export enum BilledTo { diff --git a/app/ui/LocationEditForm.tsx b/app/ui/LocationEditForm.tsx index a5f06f4..26f8657 100644 --- a/app/ui/LocationEditForm.tsx +++ b/app/ui/LocationEditForm.tsx @@ -38,6 +38,11 @@ export const LocationEditForm: FC = ({ location, yearMont location?.autoBillFwd ?? false ); + // Track whether to automatically send rent notification (use persisted value from database) + const [rentDueNotification, setrentDueNotification] = useState( + location?.rentDueNotification ?? false + ); + // Track tenant field values for real-time validation const [tenantFields, setTenantFields] = useState({ tenantFirstName: location?.tenantFirstName ?? "", @@ -168,38 +173,68 @@ export const LocationEditForm: FC = ({ location, yearMont {autoBillFwd && ( - <> -
- {t("utility-bill-forwarding-strategy-label")} - -
-
- {t("tenant-email-label")} - handleTenantFieldChange("tenantEmail", e.target.value)} - /> -
- {state.errors?.tenantEmail && - state.errors.tenantEmail.map((error: string) => ( -

- {error} -

- ))} -
-
- +
+ {t("utility-bill-forwarding-strategy-label")} + +
)} +
+ {t("auto-rent-notification-legend")} + {t("auto-rent-notification-info")} + +
+ +
+ + {rentDueNotification && ( +
+ {t("rent-due-day-label")} + +
+ )} +
+ + {(autoBillFwd || rentDueNotification) && ( +
+ {t("tenant-email-legend")} + handleTenantFieldChange("tenantEmail", e.target.value)} + /> +
+ {state.errors?.tenantEmail && + state.errors.tenantEmail.map((error: string) => ( +

+ {error} +

+ ))} +
+
+ )} + {/* Show different options for add vs edit operations */} {!location ? (
diff --git a/messages/en.json b/messages/en.json index 9c5b321..5a1ea55 100644 --- a/messages/en.json +++ b/messages/en.json @@ -134,11 +134,15 @@ "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", - "tenant-email-label": "Tenant Email", - "tenant-email-placeholder": "Enter tenant's email", "utility-bill-forwarding-strategy-label": "Forward utility bills when ...", "utility-bill-forwarding-when-payed": "all items are marked as paid", "utility-bill-forwarding-when-attached": "a bill (PDF) is attached to all items", + "auto-rent-notification-legend": "AUTOMATIC RENT NOTIFICATION", + "auto-rent-notification-info": "This option enables automatic sending of monthly rent bill to the tenant via email on the specified day of the month.", + "auto-rent-notification-toggle-label": "send rent notification", + "rent-due-day-label": "Day of month when rent is due", + "tenant-email-legend": "TENANT EMAIL", + "tenant-email-placeholder": "Enter tenant's email", "warning-missing-tenant-names": "Warning: Tenant first and last name are missing. The 2D barcode will not be displayed to the tenant when they open the shared link until both fields are filled in.", "save-button": "Save", "cancel-button": "Cancel", diff --git a/messages/hr.json b/messages/hr.json index e730d01..05181ca 100644 --- a/messages/hr.json +++ b/messages/hr.json @@ -133,11 +133,15 @@ "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", - "tenant-email-label": "Email podstanara", - "tenant-email-placeholder": "Unesite email podstanara", "utility-bill-forwarding-strategy-label": "Režije proslijedi kada...", "utility-bill-forwarding-when-payed": "sve stavke označim kao plaćene", "utility-bill-forwarding-when-attached": "za sve stavke priložim račun (PDF)", + "auto-rent-notification-legend": "AUTOMATSKA OBAVIJEST O NAJAMNINI", + "auto-rent-notification-info": "Ova opcija omogućuje automatsko slanje mjesečnog računa za najamninu podstanaru putem emaila na zadani dan u mjesecu.", + "auto-rent-notification-toggle-label": "pošalji obavijest o najamnini", + "rent-due-day-label": "Dan u mjesecu kada dospijeva najamnina", + "tenant-email-legend": "EMAIL PODSTANARA", + "tenant-email-placeholder": "Unesite email podstanara", "warning-missing-tenant-names": "Upozorenje: Ime i prezime podstanara nedostaju. 2D barkod neće biti prikazan podstanaru kada otvori podijeljenu poveznicu dok oba polja ne budu popunjena.", "save-button": "Spremi", "cancel-button": "Odbaci",