Advertisement
Guest User

Untitled

a guest
Sep 7th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { Form, Button, Input } from '@my/react-ui-elements';
  4. import { authenticateUser } from '../../actions/index';
  5. import { translate } from 'react-i18next';
  6. import { I18nextProvider } from 'react-i18next';
  7. import i18n from '../../i18n';
  8.  
  9. const styles = {
  10. wrapper: {
  11. padding: '30px 20px',
  12. background: '#fff',
  13. borderRadius: '3px',
  14. border: '1px solid #e5e5e5'
  15. },
  16. subTitle: {
  17. opacity: 0.3
  18. }
  19. };
  20.  
  21. @connect(store => {
  22. return {
  23. config: store.config.components.Authentication,
  24. loading: store.authentication.loginform_loading,
  25. errorMessage: store.authentication.loginform_errorMessage,
  26. forgotpasswordEnabled: store.config.components.Authentication.forgotpassword_enabled
  27. };
  28. })
  29.  
  30. @translate(['common'], { wait: false })
  31.  
  32. class LoginForm extends React.Component {
  33.  
  34. constructor() {
  35. super();
  36. this.state = {
  37. username: null,
  38. password: null
  39. };
  40. this.handleForm = this.handleForm.bind(this);
  41. }
  42.  
  43. handleForm(e) {
  44. e.preventDefault();
  45. this.props.dispatch(authenticateUser(this.state.username, this.state.password));
  46. }
  47.  
  48. render() {
  49. const { t } = this.props;
  50.  
  51. // Forgot password
  52. var forgotPassword = null;
  53. if(this.props.forgotpasswordEnabled) {
  54. forgotPassword = <Form.Field>
  55. <Button as='a' href={this.props.config.forgotpassword_path} secondary fluid>Forgot password</Button>
  56. </Form.Field>;
  57. }
  58. // Full element
  59. return (
  60. <I18nextProvider i18n={ i18n }>
  61. <Form style={styles.wrapper} onSubmit={this.handleForm}>
  62. <h3>{t('Login')}</h3>
  63. <p>{this.props.errorMessage}</p>
  64. <Form.Field>
  65. <Input onChange={e => this.setState({username: e.target.value})} label='Username'/>
  66. </Form.Field>
  67. <Form.Field>
  68. <Input onChange={e => this.setState({password: e.target.value})} type='password' label='Password'/>
  69. </Form.Field>
  70. <Form.Field>
  71. <Button loading={this.props.loading} disabled={this.props.loading} type='submit' primary fluid>Login</Button>
  72. </Form.Field>
  73. {forgotPassword}
  74. </Form>
  75. </I18nextProvider>
  76. );
  77. }
  78. }
  79.  
  80. export default LoginForm;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement