Add automatic rent notification feature to LocationEditForm

- 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 <noreply@anthropic.com>
This commit is contained in:
Knee Cola
2025-11-18 11:29:57 +01:00
parent e9ae2b1189
commit 63096be133
5 changed files with 99 additions and 34 deletions

View File

@@ -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: [],
});

View File

@@ -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 {