From 87c9415d37cdbbf417043267b110d58ff25eb577 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Thu, 23 May 2024 21:18:52 +0200 Subject: [PATCH] Fix error message edit role --- frontend/src/i18n/en/translation.json | 4 +- frontend/src/i18n/nl/translation.json | 4 +- frontend/src/pages/editRole/EditRole.tsx | 49 +++++++++++++++++++----- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/frontend/src/i18n/en/translation.json b/frontend/src/i18n/en/translation.json index 18681fbf..19e97a33 100644 --- a/frontend/src/i18n/en/translation.json +++ b/frontend/src/i18n/en/translation.json @@ -86,8 +86,8 @@ "search": "Search", "emailError": "Please enter a valid email", "emailTooShort": "Email must be at least 3 characters long", - "nameError": "Name must be at least 3 characters long", - "surnameError": "Surname must be at least 3 characters long", + "nameError": "Name or surname must be at least 3 characters long", + "surnameError": "Name or surname must be at least 3 characters long", "searchTutorial": "Enter a name, surname, or email to find users.", "searchTooShort": "The search must be at least 3 characters long", "noUsersFound": "No users found", diff --git a/frontend/src/i18n/nl/translation.json b/frontend/src/i18n/nl/translation.json index d9f45ea3..78973557 100644 --- a/frontend/src/i18n/nl/translation.json +++ b/frontend/src/i18n/nl/translation.json @@ -87,8 +87,8 @@ "search": "Zoeken", "emailError": "Vul een geldig email adres in", "emailTooShort": "Email moet minstens 3 karakters lang zijn", - "nameError": "Naam moet minstens 3 karakters lang zijn", - "surnameError": "Achternaam moet minstens 3 karakters lang zijn", + "nameError": "Naam of achternaam moet minstens 3 karakters lang zijn", + "surnameError": "Naam of achternaam moet minstens 3 karakters lang zijn", "searchTooShort": "Zoekopdracht moet minstens 3 karakters lang zijn", "searchTutorial": "Vul een email adres, naam of achternaam in om gebruikers op te zoeken.", "noUsersFound": "Geen gebruikers gevonden", diff --git a/frontend/src/pages/editRole/EditRole.tsx b/frontend/src/pages/editRole/EditRole.tsx index 21081ed2..ce669205 100644 --- a/frontend/src/pages/editRole/EditRole.tsx +++ b/frontend/src/pages/editRole/EditRole.tsx @@ -47,19 +47,45 @@ const ProfileContent = () => { }) } - const onSearch = async () => { - //validation - const firstValue = form.getFieldValue("first") - if (searchType === "name") { + const [isError, setIsError] = useState(false) + + const checkValidate = () => { + if (searchType === "email") { + if (!emailRegex.test(form.getFieldValue("first"))) { + return false + } else { + return true + } + } else { + const firstValue = form.getFieldValue("first") const secondValue = form.getFieldValue("second") - if (!firstValue && !secondValue) return - if (firstValue && firstValue.length < 3) return - if (secondValue && secondValue.length < 3) return + const firstValueLength = firstValue ? firstValue.length : 0 + const secondValueLength = secondValue ? secondValue.length : 0 + if (firstValueLength < 3 && secondValueLength < 3) { + console.log("error") + return false + } else { + console.log("no error") + return true + } + } + } + + const validate = () => { + if (!checkValidate()) { + setIsError(true) } else { - if (!firstValue || firstValue.length < 3) return - if (!emailRegex.test(firstValue)) return + setIsError(false) + } + } + + const onSearch = async () => { + //validation + if (!checkValidate()) { + return } + const firstValue = form.getFieldValue("first") setLoading(true) const params = new URLSearchParams() if (searchType === "email") { @@ -82,6 +108,8 @@ const ProfileContent = () => { form={form} name="search" onFinish={onSearch} + onChange={validate} + validateTrigger={[]} >