registration

This commit is contained in:
Mikola 2023-11-08 18:27:58 +03:00
parent b9cea4e7f7
commit b3a2851329
3 changed files with 154 additions and 134 deletions

View File

@ -28,7 +28,7 @@ export const AuthBox = ({ title }) => {
const [error, setError] = useState(null); const [error, setError] = useState(null);
const [modalError, setModalError] = useState(false); const [modalError, setModalError] = useState(false);
const [modalReset, setModalReset] = useState(false) const [modalReset, setModalReset] = useState(false);
const [modalReg, setModalReg] = useState(false); const [modalReg, setModalReg] = useState(false);
const [showPassword, setShowPassword] = useState(false); const [showPassword, setShowPassword] = useState(false);
@ -122,7 +122,9 @@ export const AuthBox = ({ title }) => {
> >
{isLoading ? <Loader /> : "Войти"} {isLoading ? <Loader /> : "Войти"}
</button> </button>
<span className="auth-box__reset" onClick={() => setModalReset(true)}>Восстановить пароль</span> <span className="auth-box__reset" onClick={() => setModalReset(true)}>
Восстановить пароль
</span>
<ModalResetPassword active={modalReset} setActive={setModalReset} /> <ModalResetPassword active={modalReset} setActive={setModalReset} />
<ModalRegistration active={modalReg} setActive={setModalReg} /> <ModalRegistration active={modalReg} setActive={setModalReg} />
</div> </div>

View File

@ -5,146 +5,161 @@ import { apiRequest } from "@api/request";
import { useNotification } from "@hooks/useNotification"; import { useNotification } from "@hooks/useNotification";
import ModalLayout from "@components/Common/ModalLayout/ModalLayout"; import ModalLayout from "@components/Common/ModalLayout/ModalLayout";
import arrow from "assets/icons/arrows/arrowCalendar.png"; import arrow from "assets/icons/arrows/arrowCalendar.png";
import close from "assets/icons/close.png"; import close from "assets/icons/close.png";
import "./modalResetPassword.scss"; import "./modalResetPassword.scss";
export const ModalResetPassword = ({ active, setActive }) => { export const ModalResetPassword = ({ active, setActive }) => {
const [step, setStep] = useState(false) const [step, setStep] = useState(false);
const [inputsValue, setInputsValue] = useState({ const [inputsValue, setInputsValue] = useState({
email: "", email: "",
token: "", token: "",
password: "" password: "",
});
const validateEmail = (email) => {
// регулярное выражение для проверки email
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
// возвращаем true, если email проходит проверку, и false, если нет
return re.test(email);
};
const resetInputsValue = () => {
setInputsValue({
email: "",
token: "",
password: "",
}); });
};
const validateEmail = (email) => { const { showNotification } = useNotification();
// регулярное выражение для проверки email const submitHandler = () => {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!validateEmail(inputsValue.email)) {
return showNotification({
// возвращаем true, если email проходит проверку, и false, если нет show: true,
return re.test(email); text: "Введите коректный email",
}; type: "error",
});
const resetInputsValue = () => { }
setInputsValue({ apiRequest("/register/request-password-reset", {
email: "", method: "POST",
token: "", data: {
password: "", email: inputsValue.email,
},
}).then((data) => {
if (data) {
showNotification({
show: true,
text: "Письмо отправлено Вам на почту",
type: "success",
}); });
}; setStep(true);
}
const { showNotification } = useNotification(); });
const submitHandler = () => { };
if (!validateEmail(inputsValue.email)) { const resetPassword = () => {
return showNotification({ if (!inputsValue.password || !inputsValue.token) {
show: true, return showNotification({
text: "Введите коректный email", show: true,
type: "error", text: "Введите данные",
}); type: "error",
} });
apiRequest("/register/request-password-reset", { }
method: "POST", apiRequest("/register/reset-password", {
data: { method: "POST",
email: inputsValue.email, data: {
}, token: inputsValue.token,
}).then((data) => { password: inputsValue.password,
if (data) { },
showNotification({ }).then(() => {
show: true, setActive(false);
text: "Письмо отправлено Вам на почту", resetInputsValue();
type: "success", showNotification({
}); show: true,
setStep(true) text: "Пароль изменён",
} type: "success",
}); });
}; });
const resetPassword = () => { };
if (!inputsValue.password || !inputsValue.token) { return (
return showNotification({ <ModalLayout active={active} setActive={setActive}>
show: true, <div className="resetPassword">
text: "Введите данные", <img
type: "error", className="resetPassword__close"
}); src={close}
} alt="close"
apiRequest("/register/reset-password", { onClick={() => setActive(false)}
method: "POST", />
data: { <h3 className="resetPassword__title">Восстановление пароля</h3>
token : inputsValue.token, {!step ? (
password: inputsValue.password <div className="resetPassword__email">
}, <h5>Введите email:</h5>
}).then(() => { <input
setActive(false) type="email"
resetInputsValue() onChange={(e) =>
showNotification({ setInputsValue((prevValue) => ({
show: true, ...prevValue,
text: "Пароль изменён", email: e.target.value,
type: "success", }))
}); }
}); placeholder="Email"
}; />
return ( <button
<ModalLayout active={active} setActive={setActive}> className="resetPassword__btn"
<div className='resetPassword'> onClick={(e) => {
<img e.preventDefault();
className='resetPassword__close' submitHandler();
src={close} }}
alt="close" >
onClick={() => setActive(false)} Отправить
/> </button>
<h3 className='resetPassword__title'>Восстановление пароля</h3> </div>
{!step ? ) : (
<div className='resetPassword__email'> <div className="resetPassword__email">
<h5>Введите email:</h5> <img
<input src={arrow}
type="email" onClick={() => setStep(false)}
onChange={(e) => className="resetPassword__email__arrow"
setInputsValue((prevValue) => ({ />
...prevValue, <h5>Введите код подтверждения:</h5>
email: e.target.value, <input
})) type="text"
} onChange={(e) =>
placeholder="Email" setInputsValue((prevValue) => ({
/> ...prevValue,
<button className='resetPassword__btn' onClick={(e) => { token: e.target.value,
e.preventDefault() }))
submitHandler() }
}}>Отправить</button> placeholder="token"
</div> />
: <h5>Введите новый пароль:</h5>
<div className='resetPassword__email'> <input
<img src={arrow} onClick={() => setStep(false)} className='resetPassword__email__arrow' /> type="password"
<h5>Введите код подтверждения:</h5> onChange={(e) =>
<input setInputsValue((prevValue) => ({
type="text" ...prevValue,
onChange={(e) => password: e.target.value,
setInputsValue((prevValue) => ({ }))
...prevValue, }
token: e.target.value, placeholder="password"
})) />
} <button
placeholder="token" className="resetPassword__btn"
/> onClick={(e) => {
<h5>Введите новый пароль:</h5> e.preventDefault();
<input resetPassword();
type="password" }}
onChange={(e) => >
setInputsValue((prevValue) => ({ Отправить
...prevValue, </button>
password: e.target.value, </div>
})) )}
} </div>
placeholder="password" </ModalLayout>
/> );
<button className='resetPassword__btn' onClick={(e) => {
e.preventDefault()
resetPassword()
}}>Отправить</button>
</div>
}
</div>
</ModalLayout>
);
}; };
export default ModalResetPassword; export default ModalResetPassword;

View File

@ -729,7 +729,10 @@ export const TicketFullScreen = () => {
</div> </div>
)} )}
</div> </div>
<Link to={`/tracker/project/${taskInfo.project_id}`} className="link"> <Link
to={`/tracker/project/${taskInfo.project_id}`}
className="link"
>
<div className="tasks__head__back"> <div className="tasks__head__back">
<p>Вернуться на проект</p> <p>Вернуться на проект</p>
<img src={arrow} alt="arrow" /> <img src={arrow} alt="arrow" />