import React from 'react'
import { Field, reduxForm } from 'redux-form';

import './login.scss';

let LoginForm = props => {
    const { handleSubmit, postLoginSubmit, history } = props;

    const submit = value => {
        postLoginSubmit(value);
        history.push('/profile');
    };

    return (
        <form className="form" onSubmit={handleSubmit(submit)}>
            <div>
                <label htmlFor="email">E-mail</label>
                <Field name="email" component="input" type="text" />
            </div>
            <div>
                <label htmlFor="password">Password</label>
                <Field name="password" component="input" type="text" />
            </div>
            <button type="submit">Sign in</button>
        </form>
        )
};

LoginForm = reduxForm({
    form: 'login'
})(LoginForm)

export default LoginForm