diff --git a/app/lib/actions/userSettingsActions.ts b/app/lib/actions/userSettingsActions.ts index e721eeb..e10d85b 100644 --- a/app/lib/actions/userSettingsActions.ts +++ b/app/lib/actions/userSettingsActions.ts @@ -14,7 +14,7 @@ import * as IBAN from 'iban'; export type State = { errors?: { - firstName?: string[]; + ownerName?: string[]; street?: string[]; town?: string[]; iban?: string[]; @@ -29,7 +29,7 @@ export type State = { * Schema for validating user settings form fields */ const FormSchema = (t: IntlTemplateFn) => z.object({ - firstName: z.string().optional(), + ownerName: z.string().max(25).optional(), street: z.string().optional(), town: z.string().optional(), iban: z.string() @@ -48,12 +48,12 @@ const FormSchema = (t: IntlTemplateFn) => z.object({ }) .refine((data) => { if (data.show2dCodeInMonthlyStatement) { - return !!data.firstName && data.firstName.trim().length > 0; + return !!data.ownerName && data.ownerName.trim().length > 0; } return true; }, { - message: t("first-name-required"), - path: ["firstName"], + message: t("owner-name-required"), + path: ["ownerName"], }) .refine((data) => { if (data.show2dCodeInMonthlyStatement) { @@ -136,7 +136,7 @@ export const updateUserSettings = withUser(async (user: AuthenticatedUser, prevS const t = await getTranslations("user-settings-form.validation"); const validatedFields = FormSchema(t).safeParse({ - firstName: formData.get('firstName') || undefined, + ownerName: formData.get('ownerName') || undefined, street: formData.get('street') || undefined, town: formData.get('town') || 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 const normalizedIban = iban ? iban.replace(/\s/g, '').toUpperCase() : null; @@ -164,7 +164,7 @@ export const updateUserSettings = withUser(async (user: AuthenticatedUser, prevS const userSettings: UserSettings = { userId, - firstName: firstName || null, + ownerName: ownerName || null, street: street || null, town: town || null, iban: normalizedIban, diff --git a/app/lib/db-types.ts b/app/lib/db-types.ts index b023176..bdb4e19 100644 --- a/app/lib/db-types.ts +++ b/app/lib/db-types.ts @@ -18,8 +18,8 @@ export interface YearMonth { export interface UserSettings { /** user's ID */ userId: string; - /** first name */ - firstName?: string | null; + /** owner name */ + ownerName?: string | null; /** street */ street?: string | null; /** town */ diff --git a/app/ui/UserSettingsForm.tsx b/app/ui/UserSettingsForm.tsx index cba8a84..7220b34 100644 --- a/app/ui/UserSettingsForm.tsx +++ b/app/ui/UserSettingsForm.tsx @@ -27,7 +27,7 @@ const FormFields: FC = ({ userSettings, errors, message }) => { // Track current form values for real-time validation const [formValues, setFormValues] = useState({ - firstName: userSettings?.firstName ?? "", + ownerName: userSettings?.ownerName ?? "", street: userSettings?.street ?? "", town: userSettings?.town ?? "", iban: formatIban(userSettings?.iban) ?? "", @@ -40,7 +40,7 @@ const FormFields: FC = ({ userSettings, errors, message }) => { // Check if any required field is missing (clean IBAN of spaces for validation) 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) const [show2dCodeInMonthlyStatement, setShow2dCodeInMonthlyStatement] = useState( @@ -71,21 +71,22 @@ const FormFields: FC = ({ userSettings, errors, message }) => { <>
handleInputChange("firstName", e.target.value)} + defaultValue={userSettings?.ownerName ?? ""} + onChange={(e) => handleInputChange("ownerName", e.target.value)} disabled={pending} /> -
- {errors?.firstName && - errors.firstName.map((error: string) => ( +
+ {errors?.ownerName && + errors.ownerName.map((error: string) => (

{error}

diff --git a/app/ui/ViewLocationCard.tsx b/app/ui/ViewLocationCard.tsx index 8728f63..faa727f 100644 --- a/app/ui/ViewLocationCard.tsx +++ b/app/ui/ViewLocationCard.tsx @@ -28,7 +28,7 @@ export const ViewLocationCard:FC = ({location, userSettin ImePlatitelja: tenantName ?? "", AdresaPlatitelja: tenantStreet ?? "", SjedistePlatitelja: tenantTown ?? "", - Primatelj: userSettings?.firstName ?? "", + Primatelj: userSettings?.ownerName ?? "", AdresaPrimatelja: userSettings?.street ?? "", SjedistePrimatelja: userSettings?.town ?? "", IBAN: userSettings?.iban ?? "", diff --git a/messages/en.json b/messages/en.json index a7e4ecf..1ebf6f9 100644 --- a/messages/en.json +++ b/messages/en.json @@ -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.", "tenant-2d-code-legend": "TENANT 2D CODE", "tenant-2d-code-toggle-label": "include 2D code in monthly statements", - "first-name-label": "First Name", - "first-name-placeholder": "enter your first name", - "last-name-label": "Last Name", - "last-name-placeholder": "enter your last name", + "owner-name-label": "Your First and Last Name", + "owner-name-placeholder": "enter your first and last name", "street-label": "Street", "street-placeholder": "enter your street", "town-label": "Town", @@ -203,8 +201,7 @@ "save-button": "Save", "cancel-button": "Cancel", "validation": { - "first-name-required": "First name is mandatory", - "last-name-required": "Last name is mandatory", + "owner-name-required": "Name is mandatory", "street-required": "Street is mandatory", "town-required": "Town is mandatory", "iban-required": "Valid IBAN is mandatory", diff --git a/messages/hr.json b/messages/hr.json index 6eb7d8b..c82e73d 100644 --- a/messages/hr.json +++ b/messages/hr.json @@ -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.", "tenant-2d-code-legend": "2D BARKOD ZA PODSTANARA", "tenant-2d-code-toggle-label": "prikazuj 2D barkod u mjesečnom obračunu", - "first-name-label": "Ime", - "first-name-placeholder": "unesite svoje ime", - "last-name-label": "Prezime", - "last-name-placeholder": "unesite svoje prezime", + "owner-name-label": "Vaše ime i prezime", + "owner-name-placeholder": "unesite svoje ime i prezime", "street-label": "Ulica i kućni broj", "street-placeholder": "unesite ulicu i kućni broj", "town-label": "Poštanski broj i Grad", @@ -202,8 +200,7 @@ "save-button": "Spremi", "cancel-button": "Odbaci", "validation": { - "first-name-required": "Ime je obavezno", - "last-name-required": "Prezime je obavezno", + "owner-name-required": "Ime i prezime je obavezno", "street-required": "Ulica je obavezna", "town-required": "Grad je obavezan", "iban-required": "Ispravan IBAN je obavezan",