diff --git a/src/components/Modal/ModalRegistration/ModalRegistration.jsx b/src/components/Modal/ModalRegistration/ModalRegistration.jsx index 4e03bb42..5f109475 100644 --- a/src/components/Modal/ModalRegistration/ModalRegistration.jsx +++ b/src/components/Modal/ModalRegistration/ModalRegistration.jsx @@ -20,6 +20,12 @@ export const ModalRegistration = ({ active, setActive }) => { password: "", }); + const [inputsError, setInputsError] = useState({ + name: false, + email: false, + password: false + }) + const validateEmail = (email) => { // регулярное выражение для проверки email const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; @@ -37,20 +43,25 @@ export const ModalRegistration = ({ active, setActive }) => { }; const { showNotification } = useNotification(); - const submitHandler = () => { - if (!inputsValue.password || !inputsValue.userName || !inputsValue.email) { - return showNotification({ - show: true, - text: "Введите коректные данные", - type: "error", - }); + + const validateForm = () => { + if (inputsValue.password.length < 6) { + setInputsError((prevValue) => ({...prevValue, password: true})) + } + if (inputsValue.userName.length < 6) { + setInputsError((prevValue) => ({...prevValue, name: true})) } if (!validateEmail(inputsValue.email)) { - return showNotification({ - show: true, - text: "Введите коректный email", - type: "error", - }); + setInputsError((prevValue) => ({...prevValue, email: true})) + } + if (inputsValue.password.length < 6 || inputsValue.userName.length < 6 || !validateEmail(inputsValue.email)) { + return true + } + } + + const submitHandler = () => { + if(validateForm()) { + return } apiRequest("/register/sign-up", { method: "POST", @@ -90,43 +101,76 @@ export const ModalRegistration = ({ active, setActive }) => {