diff --git a/src/api/request.js b/src/api/request.js
index 28ceaa74..aefaf36f 100644
--- a/src/api/request.js
+++ b/src/api/request.js
@@ -35,7 +35,7 @@ export const apiRequest = (
.then(
(response) =>
new Promise((resolve) => {
- if (response.data.redirect || response.status === 401) {
+ if (response.data?.redirect || response.status === 401) {
window.location.replace("/auth");
localStorage.clear();
// dispatch(auth(false));
diff --git a/src/components/AuthBlock/AuthBlock.js b/src/components/AuthBlock/AuthBlock.js
index 81f12a6e..b3c0f862 100644
--- a/src/components/AuthBlock/AuthBlock.js
+++ b/src/components/AuthBlock/AuthBlock.js
@@ -31,7 +31,7 @@ export const AuthBlock = ({ title, description, img, resetModal }) => {
>
Войти
- resetModal(true)}>Вспомнить пароль
+ resetModal(true)}>Восстановить пароль
{img && }
diff --git a/src/components/AuthBox/AuthBox.jsx b/src/components/AuthBox/AuthBox.jsx
index 1924dd00..f1e0cf67 100644
--- a/src/components/AuthBox/AuthBox.jsx
+++ b/src/components/AuthBox/AuthBox.jsx
@@ -11,6 +11,7 @@ import { apiRequest } from "@api/request";
import { Loader } from "@components/Common/Loader/Loader";
import ModalErrorLogin from "@components/Modal/ModalErrorLogin/ModalErrorLogin";
import ModalRegistration from "@components/Modal/ModalRegistration/ModalRegistration";
+import ModalResetPassword from "@components/Modal/ModalResetPassword/ModalResetPassword";
import authHead from "assets/icons/authHead.svg";
import eyePassword from "assets/icons/passwordIcon.svg";
@@ -27,6 +28,7 @@ export const AuthBox = ({ title }) => {
const [error, setError] = useState(null);
const [modalError, setModalError] = useState(false);
+ const [modalReset, setModalReset] = useState(false);
const [modalReg, setModalReg] = useState(false);
const [showPassword, setShowPassword] = useState(false);
@@ -120,8 +122,10 @@ export const AuthBox = ({ title }) => {
>
{isLoading ?
diff --git a/src/components/Modal/ModalRegistration/ModalRegistration.jsx b/src/components/Modal/ModalRegistration/ModalRegistration.jsx
index bbe925d3..4e03bb42 100644
--- a/src/components/Modal/ModalRegistration/ModalRegistration.jsx
+++ b/src/components/Modal/ModalRegistration/ModalRegistration.jsx
@@ -38,6 +38,20 @@ export const ModalRegistration = ({ active, setActive }) => {
const { showNotification } = useNotification();
const submitHandler = () => {
+ if (!inputsValue.password || !inputsValue.userName || !inputsValue.email) {
+ return showNotification({
+ show: true,
+ text: "Введите коректные данные",
+ type: "error",
+ });
+ }
+ if (!validateEmail(inputsValue.email)) {
+ return showNotification({
+ show: true,
+ text: "Введите коректный email",
+ type: "error",
+ });
+ }
apiRequest("/register/sign-up", {
method: "POST",
data: {
@@ -45,14 +59,22 @@ export const ModalRegistration = ({ active, setActive }) => {
email: inputsValue.email,
password: inputsValue.password,
},
- }).then(() => {
- setActive(false);
- resetInputsValue();
- showNotification({
- show: true,
- text: "Аккаунт успешно создан",
- type: "success",
- });
+ }).then((data) => {
+ if (!data) {
+ showNotification({
+ show: true,
+ text: "Аккаунт с таким логином или email уже существует",
+ type: "error",
+ });
+ } else {
+ setActive(false);
+ resetInputsValue();
+ showNotification({
+ show: true,
+ text: "Аккаунт успешно создан",
+ type: "success",
+ });
+ }
});
};
return (
@@ -113,13 +135,7 @@ export const ModalRegistration = ({ active, setActive }) => {
e.preventDefault();
submitHandler();
}}
- styles={
- inputsValue.userName &&
- validateEmail(inputsValue.email) &&
- inputsValue.password
- ? "button-box__submit"
- : "button-box__submit disable"
- }
+ styles="button-box__submit"
>
Отправить
diff --git a/src/components/Modal/ModalResetPassword/ModalResetPassword.jsx b/src/components/Modal/ModalResetPassword/ModalResetPassword.jsx
new file mode 100644
index 00000000..baed044a
--- /dev/null
+++ b/src/components/Modal/ModalResetPassword/ModalResetPassword.jsx
@@ -0,0 +1,165 @@
+import React, { useState } from "react";
+
+import { apiRequest } from "@api/request";
+
+import { useNotification } from "@hooks/useNotification";
+
+import ModalLayout from "@components/Common/ModalLayout/ModalLayout";
+
+import arrow from "assets/icons/arrows/arrowCalendar.png";
+import close from "assets/icons/close.png";
+
+import "./modalResetPassword.scss";
+
+export const ModalResetPassword = ({ active, setActive }) => {
+ const [step, setStep] = useState(false);
+ const [inputsValue, setInputsValue] = useState({
+ email: "",
+ token: "",
+ password: "",
+ });
+
+ const validateEmail = (email) => {
+ // регулярное выражение для проверки email
+ const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
+
+ // возвращаем true, если email проходит проверку, и false, если нет
+ return re.test(email);
+ };
+
+ const resetInputsValue = () => {
+ setInputsValue({
+ email: "",
+ token: "",
+ password: "",
+ });
+ };
+
+ const { showNotification } = useNotification();
+ const submitHandler = () => {
+ if (!validateEmail(inputsValue.email)) {
+ return showNotification({
+ show: true,
+ text: "Введите коректный email",
+ type: "error",
+ });
+ }
+ apiRequest("/register/request-password-reset", {
+ method: "POST",
+ data: {
+ email: inputsValue.email,
+ },
+ }).then((data) => {
+ if (data) {
+ showNotification({
+ show: true,
+ text: "Письмо отправлено Вам на почту",
+ type: "success",
+ });
+ setStep(true);
+ }
+ });
+ };
+ const resetPassword = () => {
+ if (!inputsValue.password || !inputsValue.token) {
+ return showNotification({
+ show: true,
+ text: "Введите данные",
+ type: "error",
+ });
+ }
+ apiRequest("/register/reset-password", {
+ method: "POST",
+ data: {
+ token: inputsValue.token,
+ password: inputsValue.password,
+ },
+ }).then(() => {
+ setActive(false);
+ resetInputsValue();
+ showNotification({
+ show: true,
+ text: "Пароль изменён",
+ type: "success",
+ });
+ });
+ };
+ return (
+ Восстановление пароля
+ {!step ? (
+ Введите email:
+
+ setInputsValue((prevValue) => ({
+ ...prevValue,
+ email: e.target.value,
+ }))
+ }
+ placeholder="Email"
+ />
+
+ Введите код подтверждения:
+
+ setInputsValue((prevValue) => ({
+ ...prevValue,
+ token: e.target.value,
+ }))
+ }
+ placeholder="token"
+ />
+ Введите новый пароль:
+
+ setInputsValue((prevValue) => ({
+ ...prevValue,
+ password: e.target.value,
+ }))
+ }
+ placeholder="password"
+ />
+
+
Вернуться на проекты
+Вернуться на проект