Guest User

Untitled

a guest
Feb 28th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import { Field, reduxForm } from 'redux-form';
  5. import { Link } from 'react-router-dom';
  6. import $ from 'jquery/dist/jquery.min';
  7. import '../../Ui/styles/login.css';
  8. import logo from '../../Ui/images/logo_origin.png';
  9. import SecurityLayout from '../../Layouts/SecurityLayout';
  10. import renderField from '../../Components/renderField';
  11. import { SignInUser } from '../../Actions/authActions';
  12.  
  13.  
  14. class SignInFormContainer extends Component {
  15.  
  16. constructor(props) {
  17. super(props);
  18. this.handleFormSignInAndValidate = this.handleFormSignInAndValidate.bind(this);
  19. }
  20.  
  21. componentWillMount() {
  22. const body = $('body');
  23. body.removeClass('login-container login-cover');
  24. }
  25.  
  26. componentDidMount() {
  27. const body = $('body');
  28. body.addClass('login-container login-cover');
  29. }
  30.  
  31.  
  32.  
  33. handleFormSignInAndValidate = values => {
  34. this.props.SignInUser(values);
  35. };
  36.  
  37. render() {
  38. const { handleSubmit, submitting, errorMessage } = this.props;
  39. return (
  40. <SecurityLayout>
  41. <form onSubmit={handleSubmit(this.handleFormSignInAndValidate)}>
  42. <div className="panel panel-body login-form">
  43. <div className="text-center">
  44. <div>
  45. <img src={logo} alt="Toudeal Authentification" />
  46. </div>
  47. <h5 className="content-group-lg display-block pt-10">Connectez-vous à votre compte</h5>
  48. </div>
  49. {errorMessage &&
  50. !errorMessage.authenticated && (
  51. <div className="alert alert-danger no-border">{errorMessage}</div>
  52. )}
  53. <Field
  54. name="username"
  55. label="Entrez adresse Email (obligatoire)"
  56. placeholder="Entrez votre email..."
  57. type="text"
  58. component={renderField}
  59. />
  60. <Field
  61. name="password"
  62. label="Mot de passe (obligatoire)"
  63. type="password"
  64. component={renderField}
  65. placeholder="Mot de passe"
  66. />
  67. <div className="form-group">
  68. <div className="row">
  69. <div className="col-sm-8 text-right col-xs-offset-4">
  70. <a>Mot de passe oublié ?</a>
  71. </div>
  72. </div>
  73. </div>
  74. <div className="form-group">
  75. <button type="submit" className="btn bg-blue btn-block btn-xlg" disabled={submitting}>
  76. Se Connecter
  77. </button>
  78. </div>
  79. <div className="content-divider text-muted form-group">
  80. <span className="no-margin text-semibold">{`Vous n'avez pas de compte?`}</span>
  81. </div>
  82. <Link
  83. to="/accounts/signUp"
  84. className="btn text-orange-800 border-orange btn-flat btn-xlg btn-block content-group"
  85. >
  86. Créer un nouveau compte
  87. </Link>
  88. <span className="help-block text-center no-margin">
  89. {`By continuing, youre confirming that you've read our`} <a>{`Terms & Conditions`}</a> and{' '}
  90. <a>Cookie Policy</a>
  91. </span>
  92. </div>
  93. </form>
  94. </SecurityLayout>
  95. );
  96. }
  97. }
  98.  
  99. // Client-side validation informations
  100.  
  101. const validate = data => {
  102. const errors = {};
  103. if(!data.username) errors.username = "Entrez votre email pour vous connecter";
  104. if(!data.password) errors.password = "Le Mot de passe ne doit pas etre vide";
  105. // if (isValidPhoneNumber(!data.username)) errors.username = 'This field must be a valid phone number';
  106. return errors;
  107. };
  108.  
  109.  
  110. function mapStateToProps (state) {
  111. return {
  112. errorMessage: state.auth.error,
  113. auth: state.auth
  114. }
  115. }
  116.  
  117. SignInFormContainer.propTypes = {
  118. handleSubmit: PropTypes.func.isRequired,
  119. submitting: PropTypes.bool.isRequired,
  120. SignInUser: PropTypes.func.isRequired
  121. };
  122.  
  123. SignInFormContainer.defaultProps = {
  124. auth: PropTypes.shape({
  125. status: PropTypes.string.isRequired,
  126. authenticated: PropTypes.bool.isRequired,
  127. }),
  128. errorMessage: PropTypes.string,
  129. };
  130.  
  131. const reduxFormSignin = reduxForm({
  132. form: 'SignInValidation',
  133. validate,
  134. })(SignInFormContainer);
  135.  
  136. export default connect(mapStateToProps, { SignInUser })(reduxFormSignin);
Add Comment
Please, Sign In to add comment