// src/views/home/auth/Login.tsx import { useState, useEffect } from 'react'; import { PrimaryButton } from '../../../components/button/PrimaryButton'; import { Input } from '../../../components/input/Input'; import { useAppDispatch, useAppSelector } from '../../../redux/hooks'; import { Link, useLocation, useNavigate } from 'react-router-dom'; import { loginUser } from '../../../redux/slices/auth'; // import { cn } from "../../../lib/cn"; import { setMenuActivePage } from '../../../redux/slices/store'; import { Balloon } from '../../../assets/icons/auth'; import { SecondaryButton } from '../../../components/button/SecondaryButton'; import { googleLogo } from '../../../assets/icons/input'; const Login = () => { const dispatch = useAppDispatch(); const navigate = useNavigate(); const location = useLocation(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [submitClicked, setSubmitClicked] = useState(false); const { status, jwt } = useAppSelector((state) => state.auth); // const [err, setErr] = useState(""); // После успешного логина useEffect(() => { dispatch(setMenuActivePage('account')); }, []); useEffect(() => { if (jwt) { const from = location.state?.from; const path = from ? from.pathname + from.search : '/home/account'; navigate(path, { replace: true }); } }, [jwt]); const handleLogin = () => { // setErr(err == "" ? "Неверная почта и/или пароль" : ""); setSubmitClicked(true); if (!username || !password) return; dispatch(loginUser({ username, password })); }; const getErrorLoginMessage = (): string => { if (!submitClicked) return ''; if (username == '') return 'Поле не может быть пустым'; if (password == '') return ''; if (status === 'failed') return 'Неверное имя пользователя и/или пароль'; return ''; }; const getErrorPasswordMessage = (): string => { if (!submitClicked) return ''; if (password == '') return 'Поле не может быть пустым'; return ''; }; return (
С возвращением
Вход в аккаунт
{ setUsername(v); }} placeholder="login" error={getErrorLoginMessage()} /> { setPassword(v); }} placeholder="abCD1234" error={getErrorPasswordMessage()} />
Забыли пароль?
{}}>
Вход с Google
Нет аккаунта?{' '} Регистрация
); }; export default Login;