From bec4eb326a381f0d1154345cf89fb5882f17e7b4 Mon Sep 17 00:00:00 2001 From: Eduard Gert Date: Tue, 19 May 2026 18:53:19 +0200 Subject: [PATCH] update new profile modal --- client/ui/frontend/src/components/Dialog.tsx | 4 +-- .../src/components/NewProfileModal.tsx | 31 ++++++++++++++----- .../src/components/ProfileDropdown.tsx | 1 + .../frontend/src/i18n/locales/en/common.json | 3 +- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/client/ui/frontend/src/components/Dialog.tsx b/client/ui/frontend/src/components/Dialog.tsx index 1c8c8470e..7f0680e05 100644 --- a/client/ui/frontend/src/components/Dialog.tsx +++ b/client/ui/frontend/src/components/Dialog.tsx @@ -66,8 +66,8 @@ export const Content = forwardRef, Co {showClose && ( { const { t } = useTranslation(); const [name, setName] = useState(""); + const [error, setError] = useState(null); + const inputRef = useRef(null); useEffect(() => { - if (!open) setName(""); + if (!open) { + setName(""); + setError(null); + } }, [open]); - const trimmed = name.trim(); - const canSubmit = trimmed.length > 0; - const handleSubmit = (e: FormEvent) => { e.preventDefault(); - if (!canSubmit) return; + const trimmed = name.trim(); + if (trimmed.length === 0) { + setError(t("profile.dialog.required")); + inputRef.current?.focus(); + return; + } onCreate(trimmed); onOpenChange(false); }; + const handleChange = (value: string) => { + setName(value); + if (error) setError(null); + }; + return ( e.preventDefault()}> @@ -41,10 +54,12 @@ export const NewProfileModal = ({ open, onOpenChange, onCreate }: Props) => {
setName(e.target.value)} + onChange={(e) => handleChange(e.target.value)} + error={error ?? undefined} />
@@ -53,9 +68,9 @@ export const NewProfileModal = ({ open, onOpenChange, onCreate }: Props) => { type="submit" variant="primary" size={"md"} - disabled={!canSubmit} className="w-full" > + {t("profile.dialog.submit")} diff --git a/client/ui/frontend/src/components/ProfileDropdown.tsx b/client/ui/frontend/src/components/ProfileDropdown.tsx index fcf2b2268..331210159 100644 --- a/client/ui/frontend/src/components/ProfileDropdown.tsx +++ b/client/ui/frontend/src/components/ProfileDropdown.tsx @@ -66,6 +66,7 @@ export const ProfileDropdown = ({ onManageProfiles }: ProfileDropdownProps) => { const handleCreateProfile = async (name: string) => { try { await addProfile(name); + await switchProfile(name); } catch (e) { await Dialogs.Error({ Title: t("profile.error.createTitle"), diff --git a/client/ui/frontend/src/i18n/locales/en/common.json b/client/ui/frontend/src/i18n/locales/en/common.json index 6d9c7ce75..ca330b3db 100644 --- a/client/ui/frontend/src/i18n/locales/en/common.json +++ b/client/ui/frontend/src/i18n/locales/en/common.json @@ -79,7 +79,8 @@ "profile.dialog.title": "Enter Profile Name", "profile.dialog.description": "Choose a memorable name.", "profile.dialog.placeholder": "e.g. Work", - "profile.dialog.submit": "Create Profile", + "profile.dialog.submit": "Add Profile", + "profile.dialog.required": "Please enter a profile name, e.g. Work, Home", "profile.deregister.title": "Deregister Profile", "profile.deregister.message": "Are you sure you want to deregister \"{name}\"? You will need to log in again to use it.",