soapbox/app/gabsocial/features/auth_login/index.js

36 wiersze
928 B
JavaScript
Czysty Zwykły widok Historia

2020-04-04 01:52:13 +00:00
import React from 'react';
2020-04-04 20:28:57 +00:00
import { connect } from 'react-redux'
2020-04-04 01:52:13 +00:00
import ImmutablePureComponent from 'react-immutable-pure-component';
2020-04-04 20:28:57 +00:00
import { createApp, logIn } from 'gabsocial/actions/auth';
2020-04-04 01:52:13 +00:00
2020-04-04 20:28:57 +00:00
class LoginForm extends ImmutablePureComponent {
componentWillMount() {
this.props.dispatch(createApp());
2020-04-04 01:52:13 +00:00
}
2020-04-04 20:28:57 +00:00
getFormData = (form) => {
2020-04-04 01:52:13 +00:00
return Object.fromEntries(
Array.from(form).map(i => [i.name, i.value])
);
}
2020-04-04 20:28:57 +00:00
handleSubmit = (event) => {
2020-04-04 01:52:13 +00:00
const {username, password} = this.getFormData(event.target);
2020-04-04 20:28:57 +00:00
this.props.dispatch(logIn(username, password));
2020-04-04 01:52:13 +00:00
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<input name='username' placeholder='me@example.com' />
<input name='password' type='password' placeholder='Password' />
<input type='submit' value='Login' />
</form>
)
}
}
2020-04-04 20:28:57 +00:00
export default connect()(LoginForm);