Guest User

Untitled

a guest
Jul 17th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. import React, { PropTypes } from 'react';
  2. import Helmet from 'react-helmet';
  3. import { Link } from 'react-router';
  4. import { reduxForm, Field, Fields,formValueSelector, isDirty, getFormInitialValues,getFormValues} from 'redux-form/immutable';
  5. import { connect } from 'react-redux';
  6. import { bindActionCreators } from 'redux';
  7. import { PureRender, onMount } from 'utils/component-helpers';
  8. import { selectUser } from 'entities/user/selectors';
  9. import FormTextField from 'components/FormTextField';
  10. import SplashWrapper from 'components/SplashWrapper';
  11.  
  12. import Button from 'material-ui/Button';
  13. import Dialog, { DialogTitle, DialogContent, DialogContentText, DialogActions } from 'material-ui/Dialog';
  14. import * as Validators from 'utils/validators';
  15. import * as Actions from './actions';
  16. import { selectSubmitDone, selectErrorCode } from './selectors';
  17. import { selectLoginRejected } from './selectors';
  18.  
  19.  
  20.  
  21. const RenderFields = ({ loginRejected, evalue, dirty, ... fields }) => (
  22.  
  23. <div>
  24.  
  25. <Field
  26. name="email"
  27. type="email"
  28. label="Email"
  29. component={FormTextField}
  30.  
  31. fullWidth
  32. autoFocus
  33.  
  34. style={{ marginBottom: 20 }}
  35.  
  36.  
  37. validate={[Validators.required, Validators.isEmail]}
  38.  
  39. />
  40.  
  41. <br/>
  42. <Field
  43. name= "password"
  44. type= "password"
  45. label= "Password"
  46. fullWidth
  47. component={FormTextField}
  48.  
  49. autoFocus
  50. // onChange={(e) => {e.target.email.valid=true,e.target.email.required=true}}
  51.  
  52.  
  53.  
  54. style={{ marginBottom: 50 }}
  55. validate={[Validators.required]}
  56.  
  57. />
  58.  
  59.  
  60. <Button
  61. type="submit"
  62. color="primary"
  63. raised
  64.  
  65. disabled={!(fields.email.meta.valid&&fields.password.meta.valid)&&fields.email.meta.visited}
  66.  
  67. style={{ width: '100%' }}
  68. >Login</Button>
  69. <div style={{ display: 'flex', justifyContent: 'center', marginTop: 20 }}>
  70. <p>Don&apos;t have an account? <Link to={'/register'}>Register here!</Link></p>
  71. </div>
  72. </div>
  73.  
  74.  
  75. );
  76.  
  77. RenderFields.propTypes = {
  78.  
  79. loginRejected: PropTypes.bool,
  80. evalue: PropTypes.string,
  81. dirty: PropTypes.bool
  82.  
  83. };
  84.  
  85.  
  86.  
  87. const LoginPage = (props) => {
  88.  
  89. const {
  90. params,
  91. actions,
  92. loginRejected,
  93. evalue,
  94. dirty
  95.  
  96. } = props;
  97.  
  98.  
  99.  
  100.  
  101. const onLoginFormSubmit = (evt) => {
  102. if (evt !== undefined && evt.preventDefault) evt.preventDefault();
  103.  
  104. actions.loginAction(evt.target.email.value, evt.target.password.value);
  105. debugger;
  106.  
  107.  
  108. }
  109.  
  110.  
  111.  
  112. console.log(evalue);
  113.  
  114.  
  115.  
  116. return (
  117.  
  118. <SplashWrapper>
  119. <Helmet title="Login" />
  120. <h1 style={{ fontSize: 25, fontWeight: 600, marginBottom: 20 }}>Organizer Portal</h1>
  121.  
  122. <form onSubmit={onLoginFormSubmit}>
  123.  
  124.  
  125.  
  126. <Fields
  127. names={[
  128. 'email',
  129. 'password'
  130.  
  131. ]}
  132.  
  133. component={RenderFields}
  134. loginRejected={loginRejected}
  135.  
  136.  
  137. />
  138.  
  139.  
  140.  
  141. <Dialog
  142. open={loginRejected}
  143. onRequestClose={actions.loginAction}
  144. >
  145. <DialogTitle>Failed to Log In!</DialogTitle>
  146.  
  147. <DialogContent>
  148. <DialogContentText>Either the information you entered was incorrect, or your user is still pending review by DEED staff.</DialogContentText>
  149. </DialogContent>
  150. <DialogActions>
  151. <Link to={`/login${location.search}`}>
  152. <Button color="primary" raised onTouchTap={actions.resetLoginAction}>Close</Button></Link>
  153. </DialogActions>
  154.  
  155.  
  156. </Dialog>
  157.  
  158. </form>
  159.  
  160. </SplashWrapper>
  161.  
  162. );
  163.  
  164. };
  165.  
  166. LoginPage.propTypes = {
  167. params: PropTypes.object,
  168. actions: PropTypes.object,
  169. loginRejected: PropTypes.bool,
  170. location: PropTypes.object,
  171. evalue: PropTypes.string,
  172. dirty: PropTypes.bool
  173.  
  174.  
  175. };
  176. const selector = formValueSelector('/login')
  177.  
  178. export default connect(
  179.  
  180.  
  181.  
  182. (state) => ({
  183. loginRejected: selectLoginRejected(state),
  184. evalue : selector(state, 'email'),
  185. dirty: isDirty('/login')(state),
  186.  
  187.  
  188.  
  189.  
  190. }),
  191. (dispatch) => ({
  192. actions: bindActionCreators(Actions, dispatch)
  193. })
  194. )(reduxForm({
  195. form: '/login',
  196. destroyOnUnmount: false,
  197. enableReinitialize: true,
  198. keepDirtyOnReinitialize: true
  199. })(PureRender(onMount((props) => props.actions.resetLoginAction())(LoginPage))));
Add Comment
Please, Sign In to add comment