Advertisement
Guest User

erroer

a guest
Jan 20th, 2018
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3.  
  4. import {Container, Row, Col, CardGroup, Card, CardBody, Button, Input, InputGroup, InputGroupAddon,
  5. Form, Grid, Header, Message, Segment} from 'reactstrap';
  6. import Validator from 'validator';
  7.  
  8. import InlineError from '../../../components/messages/InlineError';
  9. import Clock from '../../../components/timeRuns/Clock';
  10.  
  11.  
  12.  
  13. class Login extends React.Component {
  14. //Run Clock =================
  15. constructor(props){
  16. super(props);
  17. this.state={
  18. deadline:'June 30, 2018',
  19. newDeadline:''
  20. }
  21. }
  22.  
  23. changeDeadline(){
  24. this.setState({deadline: this.state.newDeadline});
  25. }
  26. //================
  27.  
  28.  
  29. state = {
  30. data: {
  31. email:"",
  32. password:""
  33. },
  34. loading: false,
  35. errors: {}
  36. }
  37. onChange = e => this.setState({
  38. data: { ...this.state.data, [e.target.name]: e.target.value }
  39. });
  40.  
  41. onSubmit = () => {
  42. const errors = this.validate(this.state.data);
  43. this.setState({ errors });
  44. if (Object.keys(errors).length === 0) {
  45. this.setState({ loading: true });
  46. this.props
  47. .submit(this.state.data)
  48. .catch(err =>
  49. this.setState({ errors: err.response.data.errors, loading: false })
  50. );
  51. }
  52. };
  53.  
  54. validate = data => {
  55. const errors = {};
  56. if (!Validator.isEmail(data.email)) errors.email = "Invalid email";
  57. if (!data.password) errors.password = "Can't be blank";
  58. return errors;
  59. };
  60. //=======================
  61.  
  62.  
  63.  
  64.  
  65. render() {
  66. //Login validator 2
  67. const { data, errors, loading } = this.state;
  68. //=================
  69. return (
  70. <div className="app flex-row align-items-center login-form">
  71. <Container>
  72. <Row className="justify-content-center">
  73. <Col md="8">
  74. <CardGroup>
  75.  
  76. <Card className="p-4">
  77. <CardBody>
  78. <h1>Login</h1>
  79. <p className="text-muted">Sign In to your account</p>
  80. <Form size='large' onSubmit={this.onSubmit} loading={loading}>
  81. {errors.global && (
  82. <Message negative>
  83. <Message.Header>Something went wrong</Message.Header>
  84. <p>{errors.global}</p>
  85. </Message>
  86. )}
  87. <Segment stacked>
  88. <InputGroup className="mb-3">
  89. <InputGroupAddon><i className="fa fa-envelope-o"></i></InputGroupAddon>
  90. <Form.Input error={!!errors.email}
  91. fluid
  92. type="text"
  93. placeholder="example@example.com"
  94. id="email"
  95. name="email"
  96. value={data.email}
  97. onChange={this.onChange}
  98. />
  99. {errors.email && <InlineError text={errors.email} />}
  100. </InputGroup>
  101. <InputGroup className="mb-4">
  102. <InputGroupAddon><i className="icon-lock"></i></InputGroupAddon>
  103. <Form.Input error={!!errors.password}
  104. fluid
  105. placeholder='Password'
  106. type='password'
  107. id="password"
  108. name="password"
  109. value={data.password}
  110. onChange={this.onChange}
  111. maxLength="8"
  112. minLength="6"
  113. />
  114. {errors.password && <InlineError text={errors.password} />}
  115. </InputGroup>
  116. </Segment>
  117.  
  118. <Row>
  119. <Col xs="6">
  120. <Button color="primary" fluid className="px-4">Login</Button>
  121. </Col>
  122. <Col xs="6" className="text-right">
  123. {/* <Button color="link" className="px-0">Forgot password?</Button> */}
  124. </Col>
  125. </Row>
  126. </Form>
  127. </CardBody>
  128. </Card>
  129.  
  130. <Card className="text-white bg-primary py-5 d-md-down-none" style={{ width: 44 + '%' }}>
  131. <CardBody className="text-center">
  132. <div>
  133. Informasi
  134. <h4>Countdown to </h4>
  135. <p>{this.state.deadline}</p>
  136. <div className="Appc-title">
  137. <Clock deadline={this.state.deadline} />
  138. </div>
  139. {/* <h2>Informasi</h2>
  140. <p>App ini untuk memperoleh ....</p>
  141. <Button color="primary" className="mt-3" active>Register Now!</Button> */}
  142. </div>
  143. </CardBody>
  144. </Card>
  145. </CardGroup>
  146. </Col>
  147. </Row>
  148. </Container>
  149. </div>
  150. );
  151. }
  152. }
  153.  
  154.  
  155. Login.propTypes = {
  156. submit: PropTypes.func.isRequired
  157. };
  158. export default Login;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement