Add rent amount field to location form
- Add rentAmount field to BillingLocation interface (stored in cents) - Implement Zod validation with conditional requirement when rent notification is enabled - Add rent amount input field to LocationEditForm with decimal display - Update all database operations to persist rentAmount - Add localization strings for both English and Croatian - Fix missing notes field in insertOne/insertMany operations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@ export type State = {
|
||||
billFwdStrategy?: string[];
|
||||
rentDueNotification?: string[];
|
||||
rentDueDay?: string[];
|
||||
rentAmount?: string[];
|
||||
};
|
||||
message?:string | null;
|
||||
};
|
||||
@@ -41,6 +42,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
|
||||
billFwdStrategy: z.enum(["when-payed", "when-attached"]).optional().nullable(),
|
||||
rentDueNotification: z.boolean().optional().nullable(),
|
||||
rentDueDay: z.coerce.number().min(1).max(31).optional().nullable(),
|
||||
rentAmount: z.coerce.number().positive(t("rent-amount-positive")).optional().nullable(),
|
||||
addToSubsequentMonths: z.boolean().optional().nullable(),
|
||||
updateScope: z.enum(["current", "subsequent", "all"]).optional().nullable(),
|
||||
})
|
||||
@@ -73,6 +75,15 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
|
||||
}, {
|
||||
message: t("tenant-email-required"),
|
||||
path: ["tenantEmail"],
|
||||
})
|
||||
.refine((data) => {
|
||||
if (data.rentDueNotification) {
|
||||
return !!data.rentAmount && data.rentAmount > 0;
|
||||
}
|
||||
return true;
|
||||
}, {
|
||||
message: t("rent-amount-required"),
|
||||
path: ["rentAmount"],
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -98,6 +109,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
billFwdStrategy: formData.get('billFwdStrategy') as "when-payed" | "when-attached" | undefined,
|
||||
rentDueNotification: formData.get('rentDueNotification') === 'on',
|
||||
rentDueDay: formData.get('rentDueDay') || null,
|
||||
rentAmount: formData.get('rentAmount') || null,
|
||||
addToSubsequentMonths: formData.get('addToSubsequentMonths') === 'on',
|
||||
updateScope: formData.get('updateScope') as "current" | "subsequent" | "all" | undefined,
|
||||
});
|
||||
@@ -120,6 +132,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
billFwdStrategy,
|
||||
rentDueNotification,
|
||||
rentDueDay,
|
||||
rentAmount,
|
||||
addToSubsequentMonths,
|
||||
updateScope,
|
||||
} = validatedFields.data;
|
||||
@@ -160,6 +173,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
billFwdStrategy: billFwdStrategy || "when-payed",
|
||||
rentDueNotification: rentDueNotification || false,
|
||||
rentDueDay: rentDueDay || null,
|
||||
rentAmount: rentAmount || null,
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -188,6 +202,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
billFwdStrategy: billFwdStrategy || "when-payed",
|
||||
rentDueNotification: rentDueNotification || false,
|
||||
rentDueDay: rentDueDay || null,
|
||||
rentAmount: rentAmount || null,
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -209,6 +224,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
billFwdStrategy: billFwdStrategy || "when-payed",
|
||||
rentDueNotification: rentDueNotification || false,
|
||||
rentDueDay: rentDueDay || null,
|
||||
rentAmount: rentAmount || null,
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -220,6 +236,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
userId,
|
||||
userEmail,
|
||||
name: locationName,
|
||||
notes: null,
|
||||
generateTenantCode: generateTenantCode || false,
|
||||
tenantFirstName: tenantFirstName || null,
|
||||
tenantLastName: tenantLastName || null,
|
||||
@@ -228,6 +245,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
billFwdStrategy: billFwdStrategy || "when-payed",
|
||||
rentDueNotification: rentDueNotification || false,
|
||||
rentDueDay: rentDueDay || null,
|
||||
rentAmount: rentAmount || null,
|
||||
yearMonth: yearMonth,
|
||||
bills: [],
|
||||
});
|
||||
@@ -291,6 +309,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
userId,
|
||||
userEmail,
|
||||
name: locationName,
|
||||
notes: null,
|
||||
generateTenantCode: generateTenantCode || false,
|
||||
tenantFirstName: tenantFirstName || null,
|
||||
tenantLastName: tenantLastName || null,
|
||||
@@ -299,6 +318,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
billFwdStrategy: billFwdStrategy || "when-payed",
|
||||
rentDueNotification: rentDueNotification || false,
|
||||
rentDueDay: rentDueDay || null,
|
||||
rentAmount: rentAmount || null,
|
||||
yearMonth: { year: monthData.year, month: monthData.month },
|
||||
bills: [],
|
||||
});
|
||||
|
||||
@@ -61,6 +61,8 @@ export interface BillingLocation {
|
||||
rentDueNotification?: boolean | null;
|
||||
/** (optional) day of month when rent is due (1-31) */
|
||||
rentDueDay?: number | null;
|
||||
/** (optional) monthly rent amount in cents */
|
||||
rentAmount?: number | null;
|
||||
};
|
||||
|
||||
export enum BilledTo {
|
||||
|
||||
@@ -194,14 +194,37 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
|
||||
</fieldset>
|
||||
|
||||
{rentDueNotification && (
|
||||
<fieldset className="fieldset mt-2 p-2">
|
||||
<legend className="fieldset-legend">{t("rent-due-day-label")}</legend>
|
||||
<select defaultValue={location?.rentDueDay ?? 1} className="select input-bordered w-full" name="rentDueDay">
|
||||
{Array.from({ length: 28 }, (_, i) => i + 1).map(day => (
|
||||
<option key={day} value={day}>{day}</option>
|
||||
))}
|
||||
</select>
|
||||
</fieldset>
|
||||
<>
|
||||
<fieldset className="fieldset mt-2 p-2">
|
||||
<legend className="fieldset-legend">{t("rent-due-day-label")}</legend>
|
||||
<select defaultValue={location?.rentDueDay ?? 1} className="select input-bordered w-full" name="rentDueDay">
|
||||
{Array.from({ length: 28 }, (_, i) => i + 1).map(day => (
|
||||
<option key={day} value={day}>{day}</option>
|
||||
))}
|
||||
</select>
|
||||
</fieldset>
|
||||
<fieldset className="fieldset mt-2 p-2">
|
||||
<legend className="fieldset-legend">{t("rent-amount-label")}</legend>
|
||||
<input
|
||||
id="rentAmount"
|
||||
name="rentAmount"
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
placeholder={t("rent-amount-placeholder")}
|
||||
className="input input-bordered w-full placeholder:text-gray-600"
|
||||
defaultValue={location?.rentAmount ? (location.rentAmount / 100).toFixed(2) : ""}
|
||||
/>
|
||||
<div id="rentAmount-error" aria-live="polite" aria-atomic="true">
|
||||
{state.errors?.rentAmount &&
|
||||
state.errors.rentAmount.map((error: string) => (
|
||||
<p className="mt-2 text-sm text-red-500" key={error}>
|
||||
{error}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
</>
|
||||
)}
|
||||
</fieldset>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user