From 6d6c65d4e353a4270a316ef8924328b7e677e9b0 Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Mon, 17 Nov 2025 20:33:40 +0100 Subject: [PATCH] Add real-time warning for missing profile data in account form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added conditional warning alert that displays when required fields are empty, updating in real-time as the user types: - Tracks form values with useState and onChange handlers - Displays warning when firstName, lastName, address, or IBAN is missing - Warning appears/disappears instantly as user fills or clears fields - Explains that 2D barcode won't be shown to tenants until all data is complete - Added translations in English and Croatian 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/ui/AccountForm.tsx | 30 +++++++++++++++++++++++++++++- messages/en.json | 1 + messages/hr.json | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/ui/AccountForm.tsx b/app/ui/AccountForm.tsx index 03c17d3..b17d4e8 100644 --- a/app/ui/AccountForm.tsx +++ b/app/ui/AccountForm.tsx @@ -1,6 +1,6 @@ "use client"; -import { FC } from "react"; +import { FC, useState } from "react"; import { UserProfile } from "../lib/db-types"; import { updateUserProfile } from "../lib/actions/userProfileActions"; import { useFormState, useFormStatus } from "react-dom"; @@ -23,6 +23,21 @@ const FormFields: FC = ({ profile, errors, message }) => { const t = useTranslations("account-form"); const locale = useLocale(); + // Track current form values for real-time validation + const [formValues, setFormValues] = useState({ + firstName: profile?.firstName ?? "", + lastName: profile?.lastName ?? "", + address: profile?.address ?? "", + iban: profile?.iban ?? "", + }); + + const handleInputChange = (field: keyof typeof formValues, value: string) => { + setFormValues(prev => ({ ...prev, [field]: value })); + }; + + // Check if any required field is missing + const hasMissingData = !formValues.firstName || !formValues.lastName || !formValues.address || !formValues.iban; + return ( <>
@@ -42,6 +57,7 @@ const FormFields: FC = ({ profile, errors, message }) => { placeholder={t("first-name-placeholder")} className="input input-bordered w-full" defaultValue={profile?.firstName ?? ""} + onChange={(e) => handleInputChange("firstName", e.target.value)} disabled={pending} />
@@ -65,6 +81,7 @@ const FormFields: FC = ({ profile, errors, message }) => { placeholder={t("last-name-placeholder")} className="input input-bordered w-full" defaultValue={profile?.lastName ?? ""} + onChange={(e) => handleInputChange("lastName", e.target.value)} disabled={pending} />
@@ -87,6 +104,7 @@ const FormFields: FC = ({ profile, errors, message }) => { className="textarea textarea-bordered w-full" placeholder={t("address-placeholder")} defaultValue={profile?.address ?? ""} + onChange={(e) => handleInputChange("address", e.target.value)} disabled={pending} >
@@ -110,6 +128,7 @@ const FormFields: FC = ({ profile, errors, message }) => { placeholder={t("iban-placeholder")} className="input input-bordered w-full" defaultValue={profile?.iban ?? ""} + onChange={(e) => handleInputChange("iban", e.target.value)} disabled={pending} />
@@ -130,6 +149,15 @@ const FormFields: FC = ({ profile, errors, message }) => { )}
+ {hasMissingData && ( +
+ + + + {t("warning-missing-data")} +
+ )} +