Guest User

Untitled

a guest
Jul 10th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. /**
  2. *
  3. * LoginPage
  4. *
  5. */
  6.  
  7. import React from 'react'
  8. import PropTypes from 'prop-types'
  9. import { FormattedMessage, injectIntl } from 'react-intl'
  10.  
  11. import { connect } from 'react-redux'
  12. import { compose } from 'redux'
  13. import injectSaga from 'utils/injectSaga'
  14. import injectReducer from 'utils/injectReducer'
  15. import Button from 'components/Button'
  16. import styled from 'styled-components'
  17. import messages from './messages'
  18. // import api from '../../utils/apiFactory'
  19. import saga from '../../sagas/LoginSagas'
  20. import reducer, { Actions } from '../../redux/LoginRedux'
  21.  
  22. /* eslint-disable react/prefer-stateless-function */
  23. export class LoginPage extends React.PureComponent {
  24. state = {
  25. username: '',
  26. password: '',
  27. }
  28. btnClick = () => {
  29. this.props.login(this.state.username, this.state.password)
  30. /* api
  31. .login(this.state.username, this.state.password)
  32. .then(response => console.log(response)) */
  33. }
  34. handleUsernameChange = event =>
  35. this.setState({ username: event.target.value })
  36. handlePasswordChange = event =>
  37. this.setState({ password: event.target.value })
  38. render() {
  39. return (
  40. <LoginContainer>
  41. <FormElement>
  42. <h1>
  43. <FormattedMessage {...messages.header} />
  44. </h1>
  45. <h2>
  46. <FormattedMessage {...messages.subhead} />
  47. </h2>
  48. <FormattedMessage {...messages.usernameInput}>
  49. {msg => (
  50. <LoginInput
  51. type="text"
  52. value={this.state.username}
  53. onChange={this.handleUsernameChange}
  54. placeholder={msg}
  55. />
  56. )}
  57. </FormattedMessage>
  58. <FormattedMessage {...messages.passwordInput}>
  59. {msg => (
  60. <LoginInput
  61. type="password"
  62. onChange={this.handlePasswordChange}
  63. value={this.state.password}
  64. placeholder={msg}
  65. />
  66. )}
  67. </FormattedMessage>
  68. <Button
  69. onClick={this.btnClick}
  70. disabled={
  71. !(this.state.username.length && this.state.password.length)
  72. }
  73. >
  74. <FormattedMessage {...messages.loginButtonContent} />
  75. </Button>
  76. </FormElement>
  77. </LoginContainer>
  78. )
  79. }
  80. }
  81.  
  82. const LoginContainer = styled.div`
  83. margin: 0 auto;
  84. background-color: white;
  85. border: solid 1px gray;
  86. border-radius: 10px;
  87. width: 700px;
  88. `
  89.  
  90. const LoginInput = styled.input`
  91. border: solid 1px gray;
  92. border-radius: 5px;
  93. padding: 12px;
  94. margin: 20px 0;
  95. display: block;
  96. width: 100%;
  97. `
  98.  
  99. const FormElement = styled.div`
  100. padding: 30px;
  101. `
  102.  
  103. LoginPage.propTypes = {
  104. login: PropTypes.func,
  105. }
  106.  
  107. const mapDispatchToProps = {
  108. // defaultAction,
  109. // fetchData,
  110.  
  111. }
  112.  
  113. const withConnect = connect(
  114. // mapStateToProps,
  115. {},
  116. mapDispatchToProps,
  117. )
  118.  
  119. export default compose(
  120. withReducer,
  121. withSaga,
  122. withConnect,
  123. injectIntl,
  124. )(LoginPage)
Advertisement
Add Comment
Please, Sign In to add comment