import React, { useState, useEffect } from "react";
import { connect } from "react-redux";
import { Form, Input, Button, Checkbox } from "antd";
import { UserOutlined, LockOutlined } from "@ant-design/icons";
import { Link } from 'react-router-dom';
import { doLogin, newUser } from "../actions/authActions";
import history from "../utils/history";
// import { logOut } from "../actions/authActions";
// import { BrowserRouter as Router, Route } from 'react-router-dom';
// import {getGQL, url, headers }from "../utils/getGQL";
import {getGQL }from "../utils/getGQL";
import "../styles/RegisterForm.css";
// const history = createHistory()
const RegisterForm = ({store, history, newUser, state, id, doLogOut, doLogin }) => {
const [login, setLogin] = useState("");
const [password, setPassword] = useState("");
const [confPassword, setConfPassword] = useState("");
const [form] = Form.useForm();
useEffect (() => {
// newUser && newUser(login, password);
if(id){
history.push("/my_playlists")
}
console.log(login, password);
}, [id])
const onFinish = (values) => {
// console.log("Success:", values);
};
const onFinishFailed = (errorInfo) => {
// console.log("Failed:", errorInfo);
};
// console.log('state: ',state)
// console.log('store: ',store)
return (
{
console.log('state: ',state),
console.log('id: ',state.auth._id)
}
setLogin(e.target.value)}
label="Username"
name="username"
value={login}
rules={[
{
required: true,
message: "Please input your username!",
},
]}
>
}
onChange={(e) => {
form.setFieldsValue({ username: e.target.value });
}}
/>
setPassword(e.target.value)}
label="Password"
name="password"
value={password}
rules={[
{
required: true,
message: "Please input your password!",
},
]}
>
}
/>
setConfPassword(e.target.value)}
label="Confirm password"
name="Confirm password"
value={confPassword}
rules={[
{
required: true,
message: "Please input your password!",
},
]}
>
}
/>
I have an account
{/* Sign_in */}
);
};
const mapStateToProps = (state) => ({
isCreateUser: !!state.auth.token,
state: state,
id: state && state.auth && state.auth.data && state.auth.data.data && state.auth.data.data.sub && state.auth.data.data.sub.id,
});
const mapDispatchToProps = (dispatch) => ({
newUser: (login, password) => dispatch(newUser(login, password)),
// dologOut: logOut,
});
export default connect(mapStateToProps, mapDispatchToProps)(RegisterForm);
// export default RegisterForm;