Rename firstName to ownerName with updated validation

- Renamed firstName to ownerName in UserSettings interface
- Updated UserSettingsForm field to accept full name (first and last)
- Set maximum length to 25 characters for owner name field
- Updated all database operations to use ownerName
- Changed English label from "First Name" to "Your First and Last Name"
- Updated Croatian translations to match (Vaše ime i prezime)
- Updated form validation schema and error messages
- Removed old lastName-related translations
- Updated ViewLocationCard to use ownerName for recipient

🤖 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:31:07 +01:00
parent c1762f7157
commit db1df76ed6
6 changed files with 29 additions and 34 deletions

View File

@@ -14,7 +14,7 @@ import * as IBAN from 'iban';
export type State = { export type State = {
errors?: { errors?: {
firstName?: string[]; ownerName?: string[];
street?: string[]; street?: string[];
town?: string[]; town?: string[];
iban?: string[]; iban?: string[];
@@ -29,7 +29,7 @@ export type State = {
* Schema for validating user settings form fields * Schema for validating user settings form fields
*/ */
const FormSchema = (t: IntlTemplateFn) => z.object({ const FormSchema = (t: IntlTemplateFn) => z.object({
firstName: z.string().optional(), ownerName: z.string().max(25).optional(),
street: z.string().optional(), street: z.string().optional(),
town: z.string().optional(), town: z.string().optional(),
iban: z.string() iban: z.string()
@@ -48,12 +48,12 @@ const FormSchema = (t: IntlTemplateFn) => z.object({
}) })
.refine((data) => { .refine((data) => {
if (data.show2dCodeInMonthlyStatement) { if (data.show2dCodeInMonthlyStatement) {
return !!data.firstName && data.firstName.trim().length > 0; return !!data.ownerName && data.ownerName.trim().length > 0;
} }
return true; return true;
}, { }, {
message: t("first-name-required"), message: t("owner-name-required"),
path: ["firstName"], path: ["ownerName"],
}) })
.refine((data) => { .refine((data) => {
if (data.show2dCodeInMonthlyStatement) { if (data.show2dCodeInMonthlyStatement) {
@@ -136,7 +136,7 @@ export const updateUserSettings = withUser(async (user: AuthenticatedUser, prevS
const t = await getTranslations("user-settings-form.validation"); const t = await getTranslations("user-settings-form.validation");
const validatedFields = FormSchema(t).safeParse({ const validatedFields = FormSchema(t).safeParse({
firstName: formData.get('firstName') || undefined, ownerName: formData.get('ownerName') || undefined,
street: formData.get('street') || undefined, street: formData.get('street') || undefined,
town: formData.get('town') || undefined, town: formData.get('town') || undefined,
iban: formData.get('iban') || undefined, iban: formData.get('iban') || undefined,
@@ -153,7 +153,7 @@ export const updateUserSettings = withUser(async (user: AuthenticatedUser, prevS
}; };
} }
const { firstName, street, town, iban, currency, show2dCodeInMonthlyStatement } = validatedFields.data; const { ownerName, street, town, iban, currency, show2dCodeInMonthlyStatement } = validatedFields.data;
// Normalize IBAN: remove spaces and convert to uppercase // Normalize IBAN: remove spaces and convert to uppercase
const normalizedIban = iban ? iban.replace(/\s/g, '').toUpperCase() : null; const normalizedIban = iban ? iban.replace(/\s/g, '').toUpperCase() : null;
@@ -164,7 +164,7 @@ export const updateUserSettings = withUser(async (user: AuthenticatedUser, prevS
const userSettings: UserSettings = { const userSettings: UserSettings = {
userId, userId,
firstName: firstName || null, ownerName: ownerName || null,
street: street || null, street: street || null,
town: town || null, town: town || null,
iban: normalizedIban, iban: normalizedIban,

View File

@@ -18,8 +18,8 @@ export interface YearMonth {
export interface UserSettings { export interface UserSettings {
/** user's ID */ /** user's ID */
userId: string; userId: string;
/** first name */ /** owner name */
firstName?: string | null; ownerName?: string | null;
/** street */ /** street */
street?: string | null; street?: string | null;
/** town */ /** town */

View File

@@ -27,7 +27,7 @@ const FormFields: FC<FormFieldsProps> = ({ userSettings, errors, message }) => {
// Track current form values for real-time validation // Track current form values for real-time validation
const [formValues, setFormValues] = useState({ const [formValues, setFormValues] = useState({
firstName: userSettings?.firstName ?? "", ownerName: userSettings?.ownerName ?? "",
street: userSettings?.street ?? "", street: userSettings?.street ?? "",
town: userSettings?.town ?? "", town: userSettings?.town ?? "",
iban: formatIban(userSettings?.iban) ?? "", iban: formatIban(userSettings?.iban) ?? "",
@@ -40,7 +40,7 @@ const FormFields: FC<FormFieldsProps> = ({ userSettings, errors, message }) => {
// Check if any required field is missing (clean IBAN of spaces for validation) // Check if any required field is missing (clean IBAN of spaces for validation)
const cleanedIban = formValues.iban.replace(/\s/g, ''); const cleanedIban = formValues.iban.replace(/\s/g, '');
const hasMissingData = !formValues.firstName || !formValues.street || !formValues.town || !cleanedIban || !formValues.currency; const hasMissingData = !formValues.ownerName || !formValues.street || !formValues.town || !cleanedIban || !formValues.currency;
// Track whether to generate 2D code for tenant (use persisted value from database) // Track whether to generate 2D code for tenant (use persisted value from database)
const [show2dCodeInMonthlyStatement, setShow2dCodeInMonthlyStatement] = useState( const [show2dCodeInMonthlyStatement, setShow2dCodeInMonthlyStatement] = useState(
@@ -71,21 +71,22 @@ const FormFields: FC<FormFieldsProps> = ({ userSettings, errors, message }) => {
<> <>
<div className="form-control w-full"> <div className="form-control w-full">
<label className="label"> <label className="label">
<span className="label-text">{t("first-name-label")}</span> <span className="label-text">{t("owner-name-label")}</span>
</label> </label>
<input <input
id="firstName" id="ownerName"
name="firstName" name="ownerName"
type="text" type="text"
placeholder={t("first-name-placeholder")} maxLength={25}
placeholder={t("owner-name-placeholder")}
className="input input-bordered w-full placeholder:text-gray-600" className="input input-bordered w-full placeholder:text-gray-600"
defaultValue={userSettings?.firstName ?? ""} defaultValue={userSettings?.ownerName ?? ""}
onChange={(e) => handleInputChange("firstName", e.target.value)} onChange={(e) => handleInputChange("ownerName", e.target.value)}
disabled={pending} disabled={pending}
/> />
<div id="firstName-error" aria-live="polite" aria-atomic="true"> <div id="ownerName-error" aria-live="polite" aria-atomic="true">
{errors?.firstName && {errors?.ownerName &&
errors.firstName.map((error: string) => ( errors.ownerName.map((error: string) => (
<p className="mt-2 text-sm text-red-500" key={error}> <p className="mt-2 text-sm text-red-500" key={error}>
{error} {error}
</p> </p>

View File

@@ -28,7 +28,7 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettin
ImePlatitelja: tenantName ?? "", ImePlatitelja: tenantName ?? "",
AdresaPlatitelja: tenantStreet ?? "", AdresaPlatitelja: tenantStreet ?? "",
SjedistePlatitelja: tenantTown ?? "", SjedistePlatitelja: tenantTown ?? "",
Primatelj: userSettings?.firstName ?? "", Primatelj: userSettings?.ownerName ?? "",
AdresaPrimatelja: userSettings?.street ?? "", AdresaPrimatelja: userSettings?.street ?? "",
SjedistePrimatelja: userSettings?.town ?? "", SjedistePrimatelja: userSettings?.town ?? "",
IBAN: userSettings?.iban ?? "", IBAN: userSettings?.iban ?? "",

View File

@@ -189,10 +189,8 @@
"info-box-message": "By activating this option, a 2D barcode will be included in the monthly statement sent to the tenant, allowing them to make a direct payment to your bank account.", "info-box-message": "By activating this option, a 2D barcode will be included in the monthly statement sent to the tenant, allowing them to make a direct payment to your bank account.",
"tenant-2d-code-legend": "TENANT 2D CODE", "tenant-2d-code-legend": "TENANT 2D CODE",
"tenant-2d-code-toggle-label": "include 2D code in monthly statements", "tenant-2d-code-toggle-label": "include 2D code in monthly statements",
"first-name-label": "First Name", "owner-name-label": "Your First and Last Name",
"first-name-placeholder": "enter your first name", "owner-name-placeholder": "enter your first and last name",
"last-name-label": "Last Name",
"last-name-placeholder": "enter your last name",
"street-label": "Street", "street-label": "Street",
"street-placeholder": "enter your street", "street-placeholder": "enter your street",
"town-label": "Town", "town-label": "Town",
@@ -203,8 +201,7 @@
"save-button": "Save", "save-button": "Save",
"cancel-button": "Cancel", "cancel-button": "Cancel",
"validation": { "validation": {
"first-name-required": "First name is mandatory", "owner-name-required": "Name is mandatory",
"last-name-required": "Last name is mandatory",
"street-required": "Street is mandatory", "street-required": "Street is mandatory",
"town-required": "Town is mandatory", "town-required": "Town is mandatory",
"iban-required": "Valid IBAN is mandatory", "iban-required": "Valid IBAN is mandatory",

View File

@@ -188,10 +188,8 @@
"info-box-message": "Ako uključite ovu opciji na mjesečnom obračunu koji se šalje podstanaru biti će prikazan 2D bar kod, putem kojeg će moći izvršiti izravnu uplatu na vaš bankovni račun.", "info-box-message": "Ako uključite ovu opciji na mjesečnom obračunu koji se šalje podstanaru biti će prikazan 2D bar kod, putem kojeg će moći izvršiti izravnu uplatu na vaš bankovni račun.",
"tenant-2d-code-legend": "2D BARKOD ZA PODSTANARA", "tenant-2d-code-legend": "2D BARKOD ZA PODSTANARA",
"tenant-2d-code-toggle-label": "prikazuj 2D barkod u mjesečnom obračunu", "tenant-2d-code-toggle-label": "prikazuj 2D barkod u mjesečnom obračunu",
"first-name-label": "Ime", "owner-name-label": "Vaše ime i prezime",
"first-name-placeholder": "unesite svoje ime", "owner-name-placeholder": "unesite svoje ime i prezime",
"last-name-label": "Prezime",
"last-name-placeholder": "unesite svoje prezime",
"street-label": "Ulica i kućni broj", "street-label": "Ulica i kućni broj",
"street-placeholder": "unesite ulicu i kućni broj", "street-placeholder": "unesite ulicu i kućni broj",
"town-label": "Poštanski broj i Grad", "town-label": "Poštanski broj i Grad",
@@ -202,8 +200,7 @@
"save-button": "Spremi", "save-button": "Spremi",
"cancel-button": "Odbaci", "cancel-button": "Odbaci",
"validation": { "validation": {
"first-name-required": "Ime je obavezno", "owner-name-required": "Ime i prezime je obavezno",
"last-name-required": "Prezime je obavezno",
"street-required": "Ulica je obavezna", "street-required": "Ulica je obavezna",
"town-required": "Grad je obavezan", "town-required": "Grad je obavezan",
"iban-required": "Ispravan IBAN je obavezan", "iban-required": "Ispravan IBAN je obavezan",