Fixed sidebar, AuthBox, and modalError

This commit is contained in:
MaxOvs19 2023-03-22 15:33:12 +03:00
parent 84e55a0f54
commit 8b8dda215f
5 changed files with 23 additions and 31 deletions

View File

@ -3,24 +3,20 @@ import { Link, useNavigate } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { Loader } from "../Loader/Loader"; import { Loader } from "../Loader/Loader";
import ErrorBoundary from "../../hoc/ErrorBoundary";
import { auth, selectAuth, setUserInfo } from "../../redux/outstaffingSlice"; import { auth, selectAuth, setUserInfo } from "../../redux/outstaffingSlice";
import { loading } from "../../redux/loaderSlice"; import { loading } from "../../redux/loaderSlice";
import { setRole } from "../../redux/roleSlice"; import { setRole } from "../../redux/roleSlice";
import { selectIsLoading } from "../../redux/loaderSlice"; import { selectIsLoading } from "../../redux/loaderSlice";
import ModalErrorLogin from "../../components/UI/ModalErrorLogin/ModalErrorLogin";
import { apiRequest } from "../../api/request"; import { apiRequest } from "../../api/request";
import ellipse from "../../images/ellipse.png"; import ellipse from "../../images/ellipse.png";
import "./authBox.scss"; import "./authBox.scss";
import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content";
const SweetAlert = withReactContent(Swal);
export const AuthBox = ({ title }) => { export const AuthBox = ({ title }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const ref = useRef(); const ref = useRef();
@ -30,15 +26,7 @@ export const AuthBox = ({ title }) => {
const isLoading = useSelector(selectIsLoading); const isLoading = useSelector(selectIsLoading);
const [error, setError] = useState(null); const [error, setError] = useState(null);
const [modalError, setModalError] = useState(false);
const handleModalError = (error) => {
SweetAlert.fire({
title: "Ошибка",
text: error,
});
setError(null);
};
useEffect(() => { useEffect(() => {
if (!localStorage.getItem("auth_token")) { if (!localStorage.getItem("auth_token")) {
@ -62,6 +50,7 @@ export const AuthBox = ({ title }) => {
}).then((res) => { }).then((res) => {
if (!res.access_token) { if (!res.access_token) {
setError("Некорректные данные для входа"); setError("Некорректные данные для входа");
setModalError(true);
dispatch(loading(false)); dispatch(loading(false));
} else { } else {
localStorage.setItem("auth_token", res.access_token); localStorage.setItem("auth_token", res.access_token);
@ -104,15 +93,11 @@ export const AuthBox = ({ title }) => {
{error && ( {error && (
<div className="auth-box__form-error"> <div className="auth-box__form-error">
<ErrorBoundary> <ModalErrorLogin
{handleModalError(error)} active={modalError}
{/*<SweetAlert*/} setActive={setModalError}
{/* show={!!error}*/} title={error}
{/* title='Ошибка'*/} />
{/* text={error}*/}
{/* onConfirm={() => setError(null)}*/}
{/*/>*/}
</ErrorBoundary>
</div> </div>
)} )}
@ -130,7 +115,9 @@ export const AuthBox = ({ title }) => {
{/* TODO: при клике отправлять на форму/модалку/страницу регистрации */} {/* TODO: при клике отправлять на форму/модалку/страницу регистрации */}
<button <button
className="auth-box__form-btn--role auth-box__auth-link" className="auth-box__form-btn--role auth-box__auth-link"
onClick={(e) => e.preventDefault()} onClick={(e) => {
e.preventDefault();
}}
> >
Регистрация Регистрация
</button> </button>

View File

@ -1,6 +1,6 @@
.auth-menu { .auth-menu {
z-index: 99; z-index: 99;
position: absolute; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
width: 141px; width: 141px;

View File

@ -144,7 +144,6 @@
img { img {
margin: 0; margin: 0;
width: 50%;
} }
p { p {

View File

@ -2,7 +2,7 @@ import React from "react";
import "./modalErrorLogin.scss"; import "./modalErrorLogin.scss";
export const ModalErrorLogin = ({ active, setActive }) => { export const ModalErrorLogin = ({ active, setActive, title }) => {
return ( return (
<div <div
className={active ? "modal-error active" : "modal-error"} className={active ? "modal-error active" : "modal-error"}
@ -13,8 +13,14 @@ export const ModalErrorLogin = ({ active, setActive }) => {
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
> >
<h2>Ошибка входа</h2> <h2>Ошибка входа</h2>
<p>Введены некоректные данные для входа</p> <p>{title}</p>
<button className="modal-error__content-button"> <button
className="modal-error__content-button"
onClick={(e) => {
e.preventDefault();
setActive(false);
}}
>
Попробовать еще раз Попробовать еще раз
</button> </button>
<span onClick={() => setActive(false)}></span> <span onClick={() => setActive(false)}></span>

View File

@ -1,4 +1,4 @@
import React, { useEffect } from "react"; import React, { useEffect, useState } from "react";
import { AuthBox } from "../../components/AuthBox/AuthBox"; import { AuthBox } from "../../components/AuthBox/AuthBox";