Remove tenantLastName field from LocationEditForm and database

- Removed tenantLastName from BillingLocation interface
- Updated LocationEditForm to remove tenantLastName input field
- Removed tenantLastName from all database operations (insert and update)
- Updated form validation schema to remove tenantLastName validation
- Updated ViewLocationCard to use only tenantFirstName for payer name
- Removed tenantLastName from tenant field state tracking

🤖 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-22 22:09:13 +01:00
parent 280e2ec029
commit a1c683528c
4 changed files with 3 additions and 47 deletions

View File

@@ -16,7 +16,6 @@ export type State = {
locationName?: string[]; locationName?: string[];
generateTenantCode?: string[]; generateTenantCode?: string[];
tenantFirstName?: string[]; tenantFirstName?: string[];
tenantLastName?: string[];
tenantStreet?: string[]; tenantStreet?: string[];
tenantTown?: string[]; tenantTown?: string[];
autoBillFwd?: string[]; autoBillFwd?: string[];
@@ -38,7 +37,6 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
locationName: z.coerce.string().min(1, t("location-name-required")), locationName: z.coerce.string().min(1, t("location-name-required")),
generateTenantCode: z.boolean().optional().nullable(), generateTenantCode: z.boolean().optional().nullable(),
tenantFirstName: z.string().optional().nullable(), tenantFirstName: z.string().optional().nullable(),
tenantLastName: z.string().optional().nullable(),
tenantStreet: z.string().max(27).optional().nullable(), tenantStreet: z.string().max(27).optional().nullable(),
tenantTown: z.string().max(27).optional().nullable(), tenantTown: z.string().max(27).optional().nullable(),
autoBillFwd: z.boolean().optional().nullable(), autoBillFwd: z.boolean().optional().nullable(),
@@ -52,7 +50,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
}) })
// dont include the _id field in the response // dont include the _id field in the response
.omit({ _id: true }) .omit({ _id: true })
// Add conditional validation: if generateTenantCode is true, tenant names are required // Add conditional validation: if generateTenantCode is true, tenant fields are required
.refine((data) => { .refine((data) => {
if (data.generateTenantCode) { if (data.generateTenantCode) {
return !!data.tenantFirstName && data.tenantFirstName.trim().length > 0; return !!data.tenantFirstName && data.tenantFirstName.trim().length > 0;
@@ -62,15 +60,6 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
message: t("tenant-first-name-required"), message: t("tenant-first-name-required"),
path: ["tenantFirstName"], path: ["tenantFirstName"],
}) })
.refine((data) => {
if (data.generateTenantCode) {
return !!data.tenantLastName && data.tenantLastName.trim().length > 0;
}
return true;
}, {
message: t("tenant-last-name-required"),
path: ["tenantLastName"],
})
.refine((data) => { .refine((data) => {
if (data.generateTenantCode) { if (data.generateTenantCode) {
return !!data.tenantStreet && data.tenantStreet.trim().length > 0; return !!data.tenantStreet && data.tenantStreet.trim().length > 0;
@@ -125,7 +114,6 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
locationName: formData.get('locationName'), locationName: formData.get('locationName'),
generateTenantCode: formData.get('generateTenantCode') === 'on', generateTenantCode: formData.get('generateTenantCode') === 'on',
tenantFirstName: formData.get('tenantFirstName') || null, tenantFirstName: formData.get('tenantFirstName') || null,
tenantLastName: formData.get('tenantLastName') || null,
tenantStreet: formData.get('tenantStreet') || null, tenantStreet: formData.get('tenantStreet') || null,
tenantTown: formData.get('tenantTown') || null, tenantTown: formData.get('tenantTown') || null,
autoBillFwd: formData.get('autoBillFwd') === 'on', autoBillFwd: formData.get('autoBillFwd') === 'on',
@@ -150,7 +138,6 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
locationName, locationName,
generateTenantCode, generateTenantCode,
tenantFirstName, tenantFirstName,
tenantLastName,
tenantStreet, tenantStreet,
tenantTown, tenantTown,
autoBillFwd, autoBillFwd,
@@ -193,7 +180,6 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
name: locationName, name: locationName,
generateTenantCode: generateTenantCode || false, generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null, tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null,
tenantStreet: tenantStreet || null, tenantStreet: tenantStreet || null,
tenantTown: tenantTown || null, tenantTown: tenantTown || null,
autoBillFwd: autoBillFwd || false, autoBillFwd: autoBillFwd || false,
@@ -224,7 +210,6 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
name: locationName, name: locationName,
generateTenantCode: generateTenantCode || false, generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null, tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null,
tenantStreet: tenantStreet || null, tenantStreet: tenantStreet || null,
tenantTown: tenantTown || null, tenantTown: tenantTown || null,
autoBillFwd: autoBillFwd || false, autoBillFwd: autoBillFwd || false,
@@ -248,7 +233,6 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
name: locationName, name: locationName,
generateTenantCode: generateTenantCode || false, generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null, tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null,
tenantStreet: tenantStreet || null, tenantStreet: tenantStreet || null,
tenantTown: tenantTown || null, tenantTown: tenantTown || null,
autoBillFwd: autoBillFwd || false, autoBillFwd: autoBillFwd || false,
@@ -271,7 +255,6 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
notes: null, notes: null,
generateTenantCode: generateTenantCode || false, generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null, tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null,
tenantStreet: tenantStreet || null, tenantStreet: tenantStreet || null,
tenantTown: tenantTown || null, tenantTown: tenantTown || null,
autoBillFwd: autoBillFwd || false, autoBillFwd: autoBillFwd || false,
@@ -346,7 +329,6 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
notes: null, notes: null,
generateTenantCode: generateTenantCode || false, generateTenantCode: generateTenantCode || false,
tenantFirstName: tenantFirstName || null, tenantFirstName: tenantFirstName || null,
tenantLastName: tenantLastName || null,
tenantStreet: tenantStreet || null, tenantStreet: tenantStreet || null,
tenantTown: tenantTown || null, tenantTown: tenantTown || null,
autoBillFwd: autoBillFwd || false, autoBillFwd: autoBillFwd || false,

View File

@@ -53,8 +53,6 @@ export interface BillingLocation {
generateTenantCode?: boolean | null; generateTenantCode?: boolean | null;
/** (optional) tenant first name */ /** (optional) tenant first name */
tenantFirstName?: string | null; tenantFirstName?: string | null;
/** (optional) tenant last name */
tenantLastName?: string | null;
/** (optional) tenant street */ /** (optional) tenant street */
tenantStreet?: string | null; tenantStreet?: string | null;
/** (optional) tenant town */ /** (optional) tenant town */

View File

@@ -46,7 +46,6 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
// Track tenant field values for real-time validation // Track tenant field values for real-time validation
const [tenantFields, setTenantFields] = useState({ const [tenantFields, setTenantFields] = useState({
tenantFirstName: location?.tenantFirstName ?? "", tenantFirstName: location?.tenantFirstName ?? "",
tenantLastName: location?.tenantLastName ?? "",
tenantStreet: location?.tenantStreet ?? "", tenantStreet: location?.tenantStreet ?? "",
tenantTown: location?.tenantTown ?? "", tenantTown: location?.tenantTown ?? "",
tenantEmail: location?.tenantEmail ?? "", tenantEmail: location?.tenantEmail ?? "",
@@ -123,29 +122,6 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
</div> </div>
</div> </div>
<div className="form-control w-full">
<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 w-full"> <div className="form-control w-full">
<label className="label"> <label className="label">
<span className="label-text">{t("tenant-street-label")}</span> <span className="label-text">{t("tenant-street-label")}</span>

View File

@@ -16,7 +16,7 @@ export interface ViewLocationCardProps {
export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettings}) => { export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettings}) => {
const { _id, name, yearMonth, bills, tenantFirstName, tenantLastName, tenantStreet, tenantTown } = location; const { _id, name, yearMonth, bills, tenantFirstName, tenantStreet, tenantTown } = location;
const t = useTranslations("home-page.location-card"); const t = useTranslations("home-page.location-card");
@@ -25,7 +25,7 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettin
const paymentParams:PaymentParams = { const paymentParams:PaymentParams = {
Iznos: (monthlyExpense/100).toFixed(2).replace(".",","), Iznos: (monthlyExpense/100).toFixed(2).replace(".",","),
ImePlatitelja: (tenantFirstName && tenantLastName) ? `${tenantFirstName} ${tenantLastName}` : "", ImePlatitelja: tenantFirstName ?? "",
AdresaPlatitelja: tenantStreet ?? "", AdresaPlatitelja: tenantStreet ?? "",
SjedistePlatitelja: tenantTown ?? "", SjedistePlatitelja: tenantTown ?? "",
Primatelj: (userSettings?.firstName && userSettings?.lastName) ? `${userSettings.firstName} ${userSettings.lastName}` : "", Primatelj: (userSettings?.firstName && userSettings?.lastName) ? `${userSettings.firstName} ${userSettings.lastName}` : "",