From f4e82b7314b447f62e1bbf8c74d5df2f60739e80 Mon Sep 17 00:00:00 2001
From: Knee Cola
Date: Tue, 18 Nov 2025 10:10:18 +0100
Subject: [PATCH] Implement bill forwarding strategy with radio button
persistence
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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
---
app/lib/actions/locationActions.ts | 9 ++
app/lib/db-types.ts | 2 +
app/ui/LocationEditForm.tsx | 228 +++++++++++++++++------------
messages/en.json | 9 +-
messages/hr.json | 9 +-
5 files changed, 157 insertions(+), 100 deletions(-)
diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts
index 940d948..c3daf65 100644
--- a/app/lib/actions/locationActions.ts
+++ b/app/lib/actions/locationActions.ts
@@ -20,6 +20,7 @@ export type State = {
tenantLastName?: string[];
autoBillFwd?: string[];
tenantEmail?: string[];
+ billFwdStrategy?: string[];
};
message?:string | null;
};
@@ -37,6 +38,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
tenantLastName: z.string().optional().nullable(),
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(),
addToSubsequentMonths: z.boolean().optional().nullable(),
updateScope: z.enum(["current", "subsequent", "all"]).optional().nullable(),
})
@@ -92,6 +94,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: formData.get('tenantLastName') || null,
autoBillFwd: formData.get('autoBillFwd') === 'on',
tenantEmail: formData.get('tenantEmail') || null,
+ billFwdStrategy: formData.get('billFwdStrategy') as "when-payed" | "when-attached" | undefined,
addToSubsequentMonths: formData.get('addToSubsequentMonths') === 'on',
updateScope: formData.get('updateScope') as "current" | "subsequent" | "all" | undefined,
});
@@ -112,6 +115,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName,
autoBillFwd,
tenantEmail,
+ billFwdStrategy,
addToSubsequentMonths,
updateScope,
} = validatedFields.data;
@@ -150,6 +154,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: tenantLastName || null,
autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null,
+ billFwdStrategy: billFwdStrategy || "when-payed",
}
}
);
@@ -176,6 +181,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: tenantLastName || null,
autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null,
+ billFwdStrategy: billFwdStrategy || "when-payed",
}
}
);
@@ -195,6 +201,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: tenantLastName || null,
autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null,
+ billFwdStrategy: billFwdStrategy || "when-payed",
}
}
);
@@ -212,6 +219,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: tenantLastName || null,
autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null,
+ billFwdStrategy: billFwdStrategy || "when-payed",
yearMonth: yearMonth,
bills: [],
});
@@ -281,6 +289,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: tenantLastName || null,
autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null,
+ billFwdStrategy: billFwdStrategy || "when-payed",
yearMonth: { year: monthData.year, month: monthData.month },
bills: [],
});
diff --git a/app/lib/db-types.ts b/app/lib/db-types.ts
index 4789525..103f303 100644
--- a/app/lib/db-types.ts
+++ b/app/lib/db-types.ts
@@ -53,6 +53,8 @@ export interface BillingLocation {
autoBillFwd?: boolean | null;
/** (optional) tenant email */
tenantEmail?: string | null;
+ /** (optional) bill forwarding strategy */
+ billFwdStrategy?: "when-payed" | "when-attached" | null;
};
export enum BilledTo {
diff --git a/app/ui/LocationEditForm.tsx b/app/ui/LocationEditForm.tsx
index eb08593..5eaf7cd 100644
--- a/app/ui/LocationEditForm.tsx
+++ b/app/ui/LocationEditForm.tsx
@@ -79,107 +79,143 @@ export const LocationEditForm: FC = ({ location, yearMont
))}
+