Passed
Push — master ( 669be3...4762c7 )
by Guangyu
19:25 queued 10s
created

src/components/MyEMS/auth/ForgetPasswordForm.js   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 65
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 53
mnd 1
bc 1
fnc 0
dl 0
loc 65
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React, { useState, useEffect } from 'react';
2
import PropTypes from 'prop-types';
3
import { Link } from 'react-router-dom';
4
import { toast } from 'react-toastify';
5
import { Button, Form, FormGroup, Input } from 'reactstrap';
6
import withRedirect from '../../../hoc/withRedirect';
7
import { getItemFromStore, setItemToStore } from '../../../helpers/utils';
8
import { withTranslation } from 'react-i18next';
9
10
const ForgetPasswordForm = ({ setRedirect, setRedirectUrl, layout, t }) => {
11
  // State
12
  const [email, setEmail] = useState(getItemFromStore('email', ''));
13
14
  // Handler
15
  const handleSubmit = e => {
16
    e.preventDefault();
17
    if (email) {
18
      toast.success(t('An email with password reset link is sent to ') + email );
19
      setRedirect(true);
20
    }
21
  };
22
23
  useEffect(() => {
24
    setRedirectUrl(`/authentication/${layout}/confirm-mail`);
25
  }, [setRedirectUrl, layout]);
26
27
  useEffect(() => {
28
    setItemToStore('email', email);
29
    // eslint-disable-next-line
30
  }, [email]);
31
32
  return (
33
    <Form className="mt-4" onSubmit={handleSubmit}>
34
      <FormGroup>
35
        <Input
36
          className="form-control"
37
          placeholder={t('Email address')}
38
          value={email}
39
          onChange={({ target }) => setEmail(target.value)}
40
          type="email"
41
        />
42
      </FormGroup>
43
      <FormGroup>
44
        <Button color="primary" block disabled={!email}>
45
          {t('Send reset link')}
46
        </Button>
47
      </FormGroup>
48
      {/* <Link className="fs--1 text-600" to="#!">
49
        I can't recover my account using this page
50
        <span className="d-inline-block ml-1">&rarr;</span>
51
      </Link> */}
52
    </Form>
53
  );
54
};
55
56
ForgetPasswordForm.propTypes = {
57
  setRedirect: PropTypes.func.isRequired,
58
  setRedirectUrl: PropTypes.func.isRequired,
59
  layout: PropTypes.string
60
};
61
62
ForgetPasswordForm.defaultProps = { layout: 'basic' };
63
64
export default withTranslation()(withRedirect(ForgetPasswordForm));
65