import {BrowserRouter as Router, Route, Link, Switch, Redirect, useHistory} from 'react-router-dom';
import {Provider, connect} from 'react-redux';
import React, {Component, useState, useEffect} from 'react';
import {createStore, combineReducers, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import jwt_decode from "jwt-decode"
import { bindActionCreators } from 'redux';
import {actionLogin, authReducer, actionAuthLogout, actionReg} from "../reducers/";
const ButtonLogout = ({onLogout, isLoggedIn}) =>
const CButtonLogout = connect(s => ({isLoggedIn: s.auth.payload}),{onLogout: actionAuthLogout})(ButtonLogout)
// const DashboardLink = ({login}) =>{
// console.log(login)
// return(
//
{login ? {login} : Anon}
// )
// }
// const CDashboardLink = connect(s => ({login: s.auth.payload && s.auth.payload.sub.login, }))(DashboardLink)
const PasswordConfirm = ({state, login, isLoggedIn, onLogin = null }) => {
const [pass1, setPass1] = useState("");
const [pass2, setPass2] = useState("");
const history = useHistory();
useEffect(() => login ? history.push(`/profile/` + login) : history.push(`/login`),[login])
console.log(state)
return (
<>
{
setPass1(e.target.value);
}}
onKeyDown = {(e) => e.keyCode == 13 && onLogin(pass1, pass2)}
/>
{
setPass2(e.target.value);
}}
onKeyDown = {(e) => e.keyCode == 13 && onLogin(pass1, pass2)}
/>
>
);
};
const FormReg = ({onReg, onLogin, login, state, isReg}) => {
const [pass1, setPass1] = useState("");
const [pass2, setPass2] = useState("");
const history = useHistory();
useEffect(() => login ? history.push(`/profile/` + login) : history.push(`/login`),[login])
console.log(isReg)
return (
<>
{
setPass1(e.target.value);
}}
onKeyDown = {(e) => {
if (e.keyCode == 13 ) {
onReg(pass1, pass2)
if(!isReg) {
onLogin(pass1, pass2)
} else {
history.push('/loginError')
}
}
}}
/>
{
setPass2(e.target.value);
}}
onKeyDown = {(e) => {
if (e.keyCode == 13 ) {
onReg(pass1, pass2)
debugger
if(!isReg) {
onLogin(pass1, pass2)
} else {
history.push('/loginError')
}
}
}}
/>
>
)
}
const CFormReg = connect((state) => ({
state: state,
login: state.auth.payload && state.auth.payload.sub.login,
isReg: state.promiseRed && state.promiseRed.registration &&
state.promiseRed.registration.payload &&
state.promiseRed.registration.payload.errors
}), {
onReg:actionReg,
onLogin:actionLogin})(FormReg);
const CFormLogin = connect((s) => ({state: s, isLoggedIn: s.auth.payload, login: s.auth.payload && s.auth.payload.sub.login}), {
onLogin:actionLogin})(PasswordConfirm);
// const LoginError = () => {
// const history = useHistory();
// return(
// <>
// Упс, щось пішло не так. Можливо це ім'я вже зайнято. Спробуйте ще.
//
// >
// )}
const LoginForm = ({}) => {
return(
<>
Будь ласка, увійдіть в свій аккаунд
{/* */}
Не маєте аккаунта? То не біда, зареєструйтесь
>
)
}
export default LoginForm;