From 3696ccb02c01296ae85b91b6793c4cfc7035a8b4 Mon Sep 17 00:00:00 2001 From: Mikola Date: Thu, 23 Nov 2023 16:48:56 +0300 Subject: [PATCH] registration and reset warning text --- .../ModalRegistration/ModalRegistration.jsx | 29 +++--- .../ModalResetPassword/ModalResetPassword.jsx | 89 +++++++++++-------- 2 files changed, 66 insertions(+), 52 deletions(-) diff --git a/src/components/Modal/ModalRegistration/ModalRegistration.jsx b/src/components/Modal/ModalRegistration/ModalRegistration.jsx index 41907352..1b426d1f 100644 --- a/src/components/Modal/ModalRegistration/ModalRegistration.jsx +++ b/src/components/Modal/ModalRegistration/ModalRegistration.jsx @@ -5,8 +5,8 @@ import { apiRequest } from "@api/request"; import { useNotification } from "@hooks/useNotification"; import BaseButton from "@components/Common/BaseButton/BaseButton"; -import ModalLayout from "@components/Common/ModalLayout/ModalLayout"; import { Loader } from "@components/Common/Loader/Loader"; +import ModalLayout from "@components/Common/ModalLayout/ModalLayout"; import anyMoment from "assets/icons/anyMoment.svg"; import doc from "assets/icons/doc.svg"; @@ -27,7 +27,7 @@ export const ModalRegistration = ({ active, setActive }) => { password: false, }); - const [loader, setLoader] = useState(false) + const [loader, setLoader] = useState(false); const validateEmail = (email) => { // регулярное выражение для проверки email @@ -62,7 +62,7 @@ export const ModalRegistration = ({ active, setActive }) => { if (validateForm()) { return; } - setLoader(true) + setLoader(true); apiRequest("/register/sign-up", { method: "POST", data: { @@ -71,7 +71,7 @@ export const ModalRegistration = ({ active, setActive }) => { password: inputsValue.password, }, }).then((data) => { - setLoader(false) + setLoader(false); if (!data) { showNotification({ show: true, @@ -79,7 +79,7 @@ export const ModalRegistration = ({ active, setActive }) => { type: "error", }); } else { - closeModal() + closeModal(); showNotification({ show: true, text: "Аккаунт успешно создан", @@ -101,7 +101,7 @@ export const ModalRegistration = ({ active, setActive }) => { password: false, }); setActive(false); - } + }; return (
@@ -185,18 +185,19 @@ export const ModalRegistration = ({ active, setActive }) => {
- {loader ? - : + {loader ? ( + + ) : ( { - e.preventDefault(); - submitHandler(); - }} - styles="button-box__submit" + onClick={(e) => { + e.preventDefault(); + submitHandler(); + }} + styles="button-box__submit" > Отправить - } + )} {/*
*/} {/* У вас уже есть аккаунт?

Войти

*/} {/*
*/} diff --git a/src/components/Modal/ModalResetPassword/ModalResetPassword.jsx b/src/components/Modal/ModalResetPassword/ModalResetPassword.jsx index f373c66f..1d4e16af 100644 --- a/src/components/Modal/ModalResetPassword/ModalResetPassword.jsx +++ b/src/components/Modal/ModalResetPassword/ModalResetPassword.jsx @@ -4,8 +4,8 @@ import { apiRequest } from "@api/request"; import { useNotification } from "@hooks/useNotification"; -import ModalLayout from "@components/Common/ModalLayout/ModalLayout"; import { Loader } from "@components/Common/Loader/Loader"; +import ModalLayout from "@components/Common/ModalLayout/ModalLayout"; import arrow from "assets/icons/arrows/arrowCalendar.png"; import close from "assets/icons/close.png"; @@ -23,7 +23,7 @@ export const ModalResetPassword = ({ active, setActive }) => { const [inputsError, setInputsError] = useState({ email: false, password: false, - token: false + token: false, }); const validateEmail = (email) => { @@ -34,7 +34,7 @@ export const ModalResetPassword = ({ active, setActive }) => { return re.test(email); }; - const [loader, setLoader] = useState(false) + const [loader, setLoader] = useState(false); const resetInputsValue = () => { setInputsValue({ @@ -54,14 +54,14 @@ export const ModalResetPassword = ({ active, setActive }) => { type: "error", }); } - setLoader(true) + setLoader(true); apiRequest("/register/request-password-reset", { method: "POST", data: { email: inputsValue.email, }, }).then((data) => { - setLoader(false) + setLoader(false); if (data) { showNotification({ show: true, @@ -74,7 +74,11 @@ export const ModalResetPassword = ({ active, setActive }) => { }; const resetPassword = () => { if (!inputsValue.password || !inputsValue.token) { - setInputsError((prevValue) => ({ ...prevValue, password: true, token: true })); + setInputsError((prevValue) => ({ + ...prevValue, + password: true, + token: true, + })); return showNotification({ show: true, text: "Введите данные", @@ -83,9 +87,9 @@ export const ModalResetPassword = ({ active, setActive }) => { } if (inputsValue.password.length < 6) { setInputsError((prevValue) => ({ ...prevValue, password: true })); - return + return; } - setLoader(true) + setLoader(true); apiRequest("/register/reset-password", { method: "POST", data: { @@ -93,7 +97,7 @@ export const ModalResetPassword = ({ active, setActive }) => { password: inputsValue.password, }, }).then((data) => { - setLoader(false) + setLoader(false); if (data.code === 0) { showNotification({ show: true, @@ -130,30 +134,33 @@ export const ModalResetPassword = ({ active, setActive }) => { setInputsValue((prevValue) => ({ ...prevValue, email: e.target.value, - })) + })); setInputsError({ email: false, password: false, - token: false + token: false, }); }} placeholder="Email" value={inputsValue.email} className={inputsError.email ? "error" : ""} /> - {inputsError.email && Введите коректный email} - {loader ? - : - - } + + )}
) : (
@@ -169,18 +176,20 @@ export const ModalResetPassword = ({ active, setActive }) => { setInputsError({ email: false, password: false, - token: false + token: false, }); setInputsValue((prevValue) => ({ ...prevValue, token: e.target.value, - })) + })); }} value={inputsValue.token} className={inputsError.token ? "error" : ""} placeholder="token" /> - {inputsError.token && Введите данные} + {inputsError.token && ( + Введите данные + )}
Введите новый пароль:
{ setInputsValue((prevValue) => ({ ...prevValue, password: e.target.value, - })) + })); setInputsError({ email: false, password: false, - token: false + token: false, }); }} placeholder="password" value={inputsValue.password} className={inputsError.password ? "error" : ""} /> - {inputsError.password && Минимум 6 символов} - {loader ? : - - } + {inputsError.password && ( + Минимум 6 символов + )} + {loader ? ( + + ) : ( + + )}
)}