Implement bill forwarding strategy with radio button persistence

Added billFwdStrategy field to store user's choice for when to forward
utility bills to tenants, with database persistence and UI updates.

Changes:
- Added billFwdStrategy field to BillingLocation interface ("when-payed" | "when-attached")
- Updated FormSchema to validate billFwdStrategy enum values
- Modified updateOrAddLocation to persist billFwdStrategy in all database operations
- Defaults to "when-payed" (first option) when no value exists in database
- Updated LocationEditForm radio buttons to use persisted database values
- Radio button selection is preserved across edits and restored from database
- Renamed autoTenantNotification to autoBillFwd throughout codebase
- Updated localization strings for bill forwarding features

Form behavior:
- New locations: "when-payed" radio selected by default
- Existing locations: Radio selection matches stored database value
- Value persisted in current, subsequent, and all month update operations

🤖 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 10:10:18 +01:00
parent c5fe184f9c
commit f4e82b7314
5 changed files with 157 additions and 100 deletions

View File

@@ -79,107 +79,143 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
</p>
))}
</div>
<fieldset className="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4 pb-2 mt-4">
<legend className="fieldset-legend font-semibold">{t("tenant-2d-code-legend")}</legend>
<div className="form-control mt-4">
<label className="label cursor-pointer justify-start gap-3">
<input
type="checkbox"
name="generateTenantCode"
className="toggle toggle-primary"
checked={generateTenantCode}
onChange={(e) => setGenerateTenantCode(e.target.checked)}
/>
<span className="label-text">{t("generate-tenant-code")}</span>
</label>
</div>
{generateTenantCode && (
<>
<div className="form-control w-full">
<label className="label">
<span className="label-text">{t("tenant-first-name-label")}</span>
</label>
<div className="form-control mt-[-1em]">
<label className="label cursor-pointer justify-start gap-3">
<input
id="tenantFirstName"
name="tenantFirstName"
type="text"
placeholder={t("tenant-first-name-placeholder")}
className="input input-bordered w-full placeholder:text-gray-600"
defaultValue={location?.tenantFirstName ?? ""}
onChange={(e) => handleTenantFieldChange("tenantFirstName", e.target.value)}
type="checkbox"
name="generateTenantCode"
className="toggle toggle-primary"
checked={generateTenantCode}
onChange={(e) => setGenerateTenantCode(e.target.checked)}
/>
<div id="tenantFirstName-error" aria-live="polite" aria-atomic="true">
{state.errors?.tenantFirstName &&
state.errors.tenantFirstName.map((error: string) => (
<p className="mt-2 text-sm text-red-500" key={error}>
{error}
</p>
))}
</div>
</div>
<div className="form-control w-full mb-4">
<label className="label">
<span className="label-text">{t("tenant-last-name-label")}</span>
</label>
<input
id="tenantLastName"
name="tenantLastName"
type="text"
placeholder={t("tenant-last-name-placeholder")}
className="input input-bordered w-full placeholder:text-gray-600"
defaultValue={location?.tenantLastName ?? ""}
onChange={(e) => handleTenantFieldChange("tenantLastName", e.target.value)}
/>
<div id="tenantLastName-error" aria-live="polite" aria-atomic="true">
{state.errors?.tenantLastName &&
state.errors.tenantLastName.map((error: string) => (
<p className="mt-2 text-sm text-red-500" key={error}>
{error}
</p>
))}
</div>
</div>
</>
)}
<div className="form-control">
<label className="label cursor-pointer justify-start gap-3">
<input
type="checkbox"
name="autoBillFwd"
className="toggle toggle-primary"
checked={autoBillFwd}
onChange={(e) => setautoBillFwd(e.target.checked)}
/>
<span className="label-text">{t("auto-utility-bill-forwarding")}</span>
</label>
</div>
{autoBillFwd && (
<div className="form-control w-full">
<label className="label">
<span className="label-text">{t("tenant-email-label")}</span>
<span className="label-text">{t("tenant-2d-code-toggle-label")}</span>
</label>
<input
id="tenantEmail"
name="tenantEmail"
type="email"
placeholder={t("tenant-email-placeholder")}
className="input input-bordered w-full placeholder:text-gray-600"
defaultValue={location?.tenantEmail ?? ""}
onChange={(e) => handleTenantFieldChange("tenantEmail", e.target.value)}
/>
<div id="tenantEmail-error" aria-live="polite" aria-atomic="true">
{state.errors?.tenantEmail &&
state.errors.tenantEmail.map((error: string) => (
<p className="mt-2 text-sm text-red-500" key={error}>
{error}
</p>
))}
</div>
</div>
)}
{generateTenantCode && (
<>
<div className="form-control w-full">
<label className="label">
<span className="label-text">{t("tenant-first-name-label")}</span>
</label>
<input
id="tenantFirstName"
name="tenantFirstName"
type="text"
placeholder={t("tenant-first-name-placeholder")}
className="input input-bordered w-full placeholder:text-gray-600"
defaultValue={location?.tenantFirstName ?? ""}
onChange={(e) => handleTenantFieldChange("tenantFirstName", e.target.value)}
/>
<div id="tenantFirstName-error" aria-live="polite" aria-atomic="true">
{state.errors?.tenantFirstName &&
state.errors.tenantFirstName.map((error: string) => (
<p className="mt-2 text-sm text-red-500" key={error}>
{error}
</p>
))}
</div>
</div>
<div className="form-control w-full mb-4">
<label className="label">
<span className="label-text">{t("tenant-last-name-label")}</span>
</label>
<input
id="tenantLastName"
name="tenantLastName"
type="text"
placeholder={t("tenant-last-name-placeholder")}
className="input input-bordered w-full placeholder:text-gray-600"
defaultValue={location?.tenantLastName ?? ""}
onChange={(e) => handleTenantFieldChange("tenantLastName", e.target.value)}
/>
<div id="tenantLastName-error" aria-live="polite" aria-atomic="true">
{state.errors?.tenantLastName &&
state.errors.tenantLastName.map((error: string) => (
<p className="mt-2 text-sm text-red-500" key={error}>
{error}
</p>
))}
</div>
</div>
</>
)}
</fieldset>
<fieldset className="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4 pb-2 mt-4">
<legend className="fieldset-legend font-semibold">{t("auto-utility-bill-forwarding-legend")}</legend>
<div className="form-control">
<label className="label cursor-pointer justify-start gap-3">
<input
type="checkbox"
name="autoBillFwd"
className="toggle toggle-primary"
checked={autoBillFwd}
onChange={(e) => setautoBillFwd(e.target.checked)}
/>
<span className="label-text">{t("auto-utility-bill-forwarding-toggle-label")}</span>
</label>
</div>
{autoBillFwd && (
<>
<div className="form-control">
<div className="label">
<span className="label-text font-medium">{t("utility-bill-forwarding-strategy-label")}</span>
</div>
<div className="flex flex-col gap-1 ml-4">
<label className="label cursor-pointer justify-start gap-3 py-1">
<input
type="radio"
name="billFwdStrategy"
value="when-payed"
className="radio radio-primary"
defaultChecked={(location?.billFwdStrategy ?? "when-payed") === "when-payed"}
/>
<span className="label-text">{t("utility-bill-forwarding-when-payed")}</span>
</label>
<label className="label cursor-pointer justify-start gap-3 py-1">
<input
type="radio"
name="billFwdStrategy"
value="when-attached"
className="radio radio-primary"
defaultChecked={location?.billFwdStrategy === "when-attached"}
/>
<span className="label-text">{t("utility-bill-forwarding-when-attached")}</span>
</label>
</div>
</div>
<div className="form-control w-full">
<label className="label">
<span className="label-text">{t("tenant-email-label")}</span>
</label>
<input
id="tenantEmail"
name="tenantEmail"
type="email"
placeholder={t("tenant-email-placeholder")}
className="input input-bordered w-full placeholder:text-gray-600"
defaultValue={location?.tenantEmail ?? ""}
onChange={(e) => handleTenantFieldChange("tenantEmail", e.target.value)}
/>
<div id="tenantEmail-error" aria-live="polite" aria-atomic="true">
{state.errors?.tenantEmail &&
state.errors.tenantEmail.map((error: string) => (
<p className="mt-2 text-sm text-red-500" key={error}>
{error}
</p>
))}
</div>
</div>
</>
)}
</fieldset>
{/* Show different options for add vs edit operations */}
{!location ? (