Skip to content

Instantly share code, notes, and snippets.

@Necmttn
Created November 28, 2018 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Necmttn/c4ed869a946fe577793bcc48a265f30c to your computer and use it in GitHub Desktop.
Save Necmttn/c4ed869a946fe577793bcc48a265f30c to your computer and use it in GitHub Desktop.
import React from 'react';
import { Form, Input, Button, Col, Icon } from 'antd';
import { Logger } from 'aws-amplify';
import { intlShape, injectIntl } from 'react-intl';
import styled from 'styled-components';
import * as t from '../../i18n';
const logger = new Logger('Form:Login', 'DEBUG');
const StyledForm = styled(Form)`
width: 200px;
margin: auto;
.login-button {
width: 100%;
float: right;
}
.ant-form-item {
margin-bottom: 5px;
}
`;
class Login extends React.Component {
state = { confirmDirty: false }
onSubmit = (e) => {
e.preventDefault();
const { validateFields } = this.props.form;
validateFields((err, values) => {
if (err) { return; }
this.props.onSubmit(values);
});
}
render() {
const { form, centered, initialValues, status } = this.props;
const { getFieldDecorator } = form;
return (
<StyledForm centered={centered} status={status}>
<Form.Item>
{
getFieldDecorator('email')
(<Input placeholder="Email" placeholder={this.props.intl.formatMessage({
id: 'signin.placeholder_email'
})} />)
}
</Form.Item>
<Form.Item>
{
getFieldDecorator('password', {
rules: [
{required: true, message: 'Please input your password!'},
]
})(<Input type="password" placeholder={this.props.intl.formatMessage({
id: 'signin.placeholder_password'
})} />)
}
</Form.Item>
<Form.Item>
<Button
ghost
className="login-button"
type={ status === "error" ? "danger" : "primary" }
onClick={this.onSubmit}
>{status === "loading" ? <Icon type="loading" /> : t.signin.confirm }</Button>
</Form.Item>
</StyledForm>
);
}
}
Login.propTypes = {
intl: intlShape.isRequired
}
export default Form.create()(injectIntl(Login));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment