diff --git a/app/ui/MonthLocationList.tsx b/app/ui/MonthLocationList.tsx
index 25533b8..7938415 100644
--- a/app/ui/MonthLocationList.tsx
+++ b/app/ui/MonthLocationList.tsx
@@ -52,9 +52,9 @@ export const MonthLocationList:React.FC
= ({
const params = new URLSearchParams(search.toString());
let messageShown = false;
- if (search.get('profileSaved') === 'true') {
- toast.success(t("profile-saved-message"), { theme: "dark" });
- params.delete('profileSaved');
+ if (search.get('userSettingsSaved') === 'true') {
+ toast.success(t("user-settings-saved-message"), { theme: "dark" });
+ params.delete('userSettingsSaved');
messageShown = true;
}
diff --git a/app/ui/UserSettingsForm.tsx b/app/ui/UserSettingsForm.tsx
new file mode 100644
index 0000000..0873d5f
--- /dev/null
+++ b/app/ui/UserSettingsForm.tsx
@@ -0,0 +1,230 @@
+"use client";
+
+import { FC, useState } from "react";
+import { UserSettings } from "../lib/db-types";
+import { updateUserSettings } from "../lib/actions/userSettingsActions";
+import { useFormState, useFormStatus } from "react-dom";
+import { useLocale, useTranslations } from "next-intl";
+import Link from "next/link";
+import SettingsIcon from "@mui/icons-material/Settings";
+import { formatIban } from "../lib/formatStrings";
+import { InfoBox } from "./InfoBox";
+
+export type UserSettingsFormProps = {
+ userSettings: UserSettings | null;
+}
+
+type FormFieldsProps = {
+ userSettings: UserSettings | null;
+ errors: any;
+ message: string | null;
+}
+
+const FormFields: FC = ({ userSettings, errors, message }) => {
+ const { pending } = useFormStatus();
+ const t = useTranslations("user-settings-form");
+ const locale = useLocale();
+
+ // Track current form values for real-time validation
+ const [formValues, setFormValues] = useState({
+ firstName: userSettings?.firstName ?? "",
+ lastName: userSettings?.lastName ?? "",
+ address: userSettings?.address ?? "",
+ iban: formatIban(userSettings?.iban) ?? "",
+ });
+
+ const handleInputChange = (field: keyof typeof formValues, value: string) => {
+ setFormValues(prev => ({ ...prev, [field]: value }));
+ };
+
+ // 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.lastName || !formValues.address || !cleanedIban;
+
+ // Track whether to generate 2D code for tenant (use persisted value from database)
+ const [show2dCodeInMonthlyStatement, setShow2dCodeInMonthlyStatement] = useState(
+ userSettings?.show2dCodeInMonthlyStatement ?? false
+ );
+
+ return (
+ <>
+
+
+
+ {message && (
+
+ {message}
+
+ )}
+
+
+
+
+
+ {t("cancel-button")}
+
+
+ >
+ );
+};
+
+export const UserSettingsForm: FC = ({ userSettings }) => {
+ const initialState = { message: null, errors: {} };
+ const [state, dispatch] = useFormState(updateUserSettings, initialState);
+ const t = useTranslations("user-settings-form");
+
+ return (
+
+ );
+};
+
+export const UserSettingsFormSkeleton: FC = () => {
+ return (
+
+ );
+};
diff --git a/messages/en.json b/messages/en.json
index d9a1846..280615c 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -74,7 +74,7 @@
"empty-state-title": "No Barcode Data Found",
"empty-state-message": "No bills with 2D barcodes found for {yearMonth}"
},
- "profile-saved-message": "Profile updated successfully",
+ "user-settings-saved-message": "User settings updated successfully",
"bill-saved-message": "Bill saved successfully",
"bill-deleted-message": "Bill deleted successfully",
"location-saved-message": "Location saved successfully",
@@ -164,8 +164,8 @@
"validation-failed": "Validation failed. Please check the form and try again."
}
},
- "settings-form": {
- "title": "Settings",
+ "user-settings-form": {
+ "title": "User settings",
"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",
diff --git a/messages/hr.json b/messages/hr.json
index 569304a..342ae79 100644
--- a/messages/hr.json
+++ b/messages/hr.json
@@ -74,7 +74,7 @@
"empty-state-title": "Nema Podataka o Barkodovima",
"empty-state-message": "Nema računa s 2D barkodovima za {yearMonth}"
},
- "profile-saved-message": "Profil uspješno ažuriran",
+ "user-settings-saved-message": "Korisničke postavke uspješno ažurirane",
"bill-saved-message": "Račun uspješno spremljen",
"bill-deleted-message": "Račun uspješno obrisan",
"location-saved-message": "Nekretnina uspješno spremljena",
@@ -163,8 +163,8 @@
"validation-failed": "Validacija nije uspjela. Molimo provjerite formu i pokušajte ponovno."
}
},
- "settings-form": {
- "title": "Postavke",
+ "user-settings-form": {
+ "title": "Korisničke postavke",
"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",