Advertisement
Guest User

Untitled

a guest
Jul 5th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import FadeIn from 'react-fade-in'
  4. import { compose, withStateHandlers, branch, renderComponent } from 'recompose'
  5. import { withStyles } from '@material-ui/core/styles';
  6.  
  7. import TextField from '@material-ui/core/TextField'
  8. import Button from '@material-ui/core/Button'
  9. import CircularProgress from '@material-ui/core/CircularProgress';
  10.  
  11. const styles = theme => ({
  12. margin: {
  13. marginTop: 20,
  14. },
  15. heading: {
  16. fontWeight:100,
  17. margin:0
  18. }
  19. })
  20.  
  21. const enhance = compose(
  22. connect(
  23. state => ({
  24. // isLoggedIn: state.authentication.isLoggedIn
  25. }),
  26. dispatch => ({
  27. // attemptLogin: (username: string, password: string) => dispatch(authenticationActions.login({ username, password })),
  28. })
  29. ),
  30. withStateHandlers(
  31. {
  32. username: 'username',
  33. password: 'password',
  34. isLoading: false
  35. },
  36. {
  37. onSubmit: (state, props) => () => {
  38. // props.attemptLogin(state.username, state.password)
  39. props.toggleLoading(true)
  40. return state
  41. },
  42. toggleLoading: (state) => (toggle) => ({ isLoading: toggle }),
  43. changeInput: (state) => (text, key) => {
  44. return { ...state, [key]: text }
  45. }
  46. }
  47. ),
  48. withStyles(styles)
  49. )
  50.  
  51. const Login = enhance(({classes, username, password, changeInput, onSubmit, isLoading}) => {
  52. return (
  53. <FadeIn transitionDuration={1000}>
  54. <div className='login'>
  55. { isLoading ? <CircularProgress /> :
  56. <div>
  57. <TextField
  58. autoFocus
  59. margin="dense"
  60. id="name"
  61. label="Email Address"
  62. type="email"
  63. value={username}
  64. fullWidth
  65. className={classes.margin}
  66. onChange={(event) => {changeInput(event.target.value, 'username')}}
  67. />
  68. <TextField
  69. autoFocus
  70. margin="dense"
  71. id="password"
  72. label="Password"
  73. type="password"
  74. value={password}
  75. fullWidth
  76. className={classes.margin}
  77. onChange={(event) => {changeInput(event.target.value, 'password')}}
  78. />
  79. <Button className={classes.margin} variant="contained" fullWidth color="primary" onClick={() => onSubmit()}>
  80. Login
  81. </Button>
  82. </div>
  83. }
  84.  
  85.  
  86. </div>
  87. </FadeIn>
  88. )
  89. })
  90.  
  91. export default Login
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement