From 3f5f221702d37a3d899597896e39975be7b9255d Mon Sep 17 00:00:00 2001 From: Mikola Date: Sun, 19 Nov 2023 18:50:04 +0300 Subject: [PATCH] validate registration --- .../ModalRegistration/ModalRegistration.jsx | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/src/components/Modal/ModalRegistration/ModalRegistration.jsx b/src/components/Modal/ModalRegistration/ModalRegistration.jsx index 5f109475..8123d88f 100644 --- a/src/components/Modal/ModalRegistration/ModalRegistration.jsx +++ b/src/components/Modal/ModalRegistration/ModalRegistration.jsx @@ -23,8 +23,8 @@ export const ModalRegistration = ({ active, setActive }) => { const [inputsError, setInputsError] = useState({ name: false, email: false, - password: false - }) + password: false, + }); const validateEmail = (email) => { // регулярное выражение для проверки email @@ -46,22 +46,26 @@ export const ModalRegistration = ({ active, setActive }) => { const validateForm = () => { if (inputsValue.password.length < 6) { - setInputsError((prevValue) => ({...prevValue, password: true})) + setInputsError((prevValue) => ({ ...prevValue, password: true })); } if (inputsValue.userName.length < 6) { - setInputsError((prevValue) => ({...prevValue, name: true})) + setInputsError((prevValue) => ({ ...prevValue, name: true })); } if (!validateEmail(inputsValue.email)) { - setInputsError((prevValue) => ({...prevValue, email: true})) + setInputsError((prevValue) => ({ ...prevValue, email: true })); } - if (inputsValue.password.length < 6 || inputsValue.userName.length < 6 || !validateEmail(inputsValue.email)) { - return true + if ( + inputsValue.password.length < 6 || + inputsValue.userName.length < 6 || + !validateEmail(inputsValue.email) + ) { + return true; } - } + }; const submitHandler = () => { - if(validateForm()) { - return + if (validateForm()) { + return; } apiRequest("/register/sign-up", { method: "POST", @@ -101,75 +105,69 @@ export const ModalRegistration = ({ active, setActive }) => {
-
+
Ваше имя
{ setInputsError({ name: false, email: false, - password: false - }) + password: false, + }); setInputsValue((prevValue) => ({ ...prevValue, userName: e.target.value, - })) + })); }} placeholder="Name" /> - {inputsError.name && - Минимум 6 символов - } + {inputsError.name && Минимум 6 символов}
-
+
E-mail
{ setInputsError({ name: false, email: false, - password: false - }) + password: false, + }); setInputsValue((prevValue) => ({ ...prevValue, email: e.target.value, - })) + })); }} placeholder="Email" /> - {inputsError.email && - Введите коректный email - } + {inputsError.email && Введите коректный email}
{/*
Название компании
*/} {/**/} -
+
Пароль
{ setInputsError({ name: false, email: false, - password: false - }) + password: false, + }); setInputsValue((prevValue) => ({ ...prevValue, password: e.target.value, - })) + })); }} placeholder="Password" /> - {inputsError.password && - Минимум 6 символов - } + {inputsError.password && Минимум 6 символов}