ChangePassPage.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React, { useState } from "react";
  2. import FloatingLabel from "react-bootstrap/FloatingLabel";
  3. import Form from "react-bootstrap/Form";
  4. import Button from "react-bootstrap/esm/Button";
  5. import { Link } from "react-router-dom";
  6. import { actionSetUserPass } from "../actions";
  7. import { connect } from "react-redux";
  8. import PasswordChecklist from "react-password-checklist";
  9. import { passValidator } from "../helpers/passValidator";
  10. const ChangePass = ({ onPassword, minLength = "5" }) => {
  11. const [password, setPassword] = useState("");
  12. const [passwordAgain, setPasswordAgain] = useState("");
  13. return (
  14. <div className="passwordSetting">
  15. <h1 className="textProfile">Change password</h1>
  16. <div className="inputContainer">
  17. <label for="passwordInput">Enter a new password: </label>
  18. <input
  19. className="form-control-editing form-control"
  20. id="passwordInput"
  21. type="password"
  22. value={password}
  23. onChange={(e) => {
  24. setPassword(e.target.value);
  25. }}
  26. />
  27. </div>
  28. <div className="inputContainer">
  29. <label for="passwordAgainInput">
  30. Re-enter the new password:
  31. </label>
  32. <input
  33. className="form-control-editing form-control"
  34. id="passwordAgainInput"
  35. type="password"
  36. value={passwordAgain}
  37. onChange={(e) => {
  38. setPasswordAgain(e.target.value);
  39. }}
  40. />
  41. </div>
  42. <PasswordChecklist
  43. rules={["minLength", "number", "capital", "match"]}
  44. className="validator"
  45. minLength={8}
  46. value={password}
  47. valueAgain={passwordAgain}
  48. onChange={(isValid) => {}}
  49. />
  50. <div className="df">
  51. <Button
  52. variant="primary"
  53. className="buttonSetting"
  54. onClick={() => {
  55. onPassword(password);
  56. console.log(password, passwordAgain);
  57. }}
  58. disabled={!passValidator(password, passwordAgain)}
  59. >
  60. <Link
  61. to="/changesdone"
  62. style={{ color: "white", textDecoration: "none" }}
  63. >
  64. Apply Changes
  65. </Link>
  66. </Button>
  67. <Link to="/profile" className="changepasLink">
  68. Back to profile
  69. </Link>
  70. </div>
  71. </div>
  72. );
  73. };
  74. export const CChangePass = connect(null, { onPassword: actionSetUserPass })(
  75. ChangePass
  76. );