Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ResetPasswordPageMUI.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import React, { useState } from "react";
  2. import PropTypes from "prop-types";
  3. import { useFormik } from "formik";
  4. import { useTranslation } from "react-i18next";
  5. import { useDispatch } from "react-redux";
  6. import DiligLogo from "../../assets/images/logo_horizontal_black.png";
  7. import * as Yup from "yup";
  8. // import i18next from 'i18next';
  9. import HrLogo from "../../assets/images/hrcenter.png";
  10. import {
  11. Box,
  12. Container,
  13. Typography,
  14. Button,
  15. InputAdornment,
  16. IconButton,
  17. TextField,
  18. Link,
  19. Grid,
  20. } from "@mui/material";
  21. import { Visibility, VisibilityOff } from "@mui/icons-material";
  22. import Backdrop from "../../components/MUI/BackdropComponent";
  23. import { BASE_PAGE } from "../../constants/pages";
  24. import { NavLink } from "react-router-dom";
  25. import { resetPassword } from "../../store/actions/login/loginActions";
  26. function getQueryVariable(variable) {
  27. var query = window.location.search.substring(1);
  28. var vars = query.split("&");
  29. for (var i = 0; i < vars.length; i++) {
  30. var pair = vars[i].split("=");
  31. if (pair[0] == variable) {
  32. return pair[1];
  33. }
  34. }
  35. return false;
  36. }
  37. const ResetPasswordPage = ({ history }) => {
  38. const dispatch = useDispatch();
  39. const { t } = useTranslation();
  40. const [showPassword, setShowPassword] = useState(false);
  41. const [showConfirmPassword, setShowConfirmPassword] = useState(false);
  42. const handleClickShowPassword = () => setShowPassword(!showPassword);
  43. const handleMouseDownPassword = () => setShowPassword(!showPassword);
  44. const handleClickShowConfirmPassword = () =>
  45. setShowConfirmPassword(!showConfirmPassword);
  46. const handleMouseDownConfirmPassword = () =>
  47. setShowConfirmPassword(!showConfirmPassword);
  48. const resetPasswordValidationSchema = Yup.object().shape({
  49. password: Yup.string().required(t("login.passwordRequired")),
  50. confirmPassword: Yup.string()
  51. .required(t("login.passwordRequired"))
  52. .oneOf([Yup.ref("password"), null], t("login.passwordDontMatch")),
  53. });
  54. const handleSubmit = (values) => {
  55. const password = values.password;
  56. // const confirmPassword = values.confirmPassword;
  57. // if (password === confirmPassword)
  58. {
  59. const code = getQueryVariable("token"),
  60. email = getQueryVariable("email");
  61. dispatch(
  62. resetPassword({
  63. code,
  64. email,
  65. password,
  66. handleApiResponseSuccess,
  67. })
  68. );
  69. }
  70. };
  71. const handleApiResponseSuccess = () => {
  72. history.push({
  73. pathname: BASE_PAGE,
  74. state: {
  75. from: history.location.pathname,
  76. },
  77. });
  78. };
  79. const formik = useFormik({
  80. initialValues: {
  81. password: "",
  82. confirmPassword: "",
  83. },
  84. validationSchema: resetPasswordValidationSchema,
  85. onSubmit: handleSubmit,
  86. validateOnBlur: true,
  87. enableReinitialize: true,
  88. });
  89. return (
  90. <Container
  91. component="main"
  92. maxWidth="xl"
  93. className="c-login-container"
  94. fullwidth="true"
  95. >
  96. <div className="l-t-rectangle"></div>
  97. <div className="r-b-rectangle"></div>
  98. <Box
  99. sx={{
  100. marginTop: 2,
  101. width: 350,
  102. height: 684,
  103. display: "flex",
  104. flexDirection: "column",
  105. alignItems: "center",
  106. }}
  107. >
  108. <img src={HrLogo} className="login-logo" />
  109. <Typography variant="h5" sx={{ m: 2, mt: 3 }}>
  110. {t("login.resetYourPassword")}
  111. </Typography>
  112. <Typography variant="p">
  113. {t("login.resetYourPasswordHelpText")}
  114. </Typography>
  115. <Box
  116. component="form"
  117. onSubmit={formik.handleSubmit}
  118. sx={{ position: "relative", mt: 1, p: 1 }}
  119. >
  120. <Backdrop position="absolute" isLoading={false} />
  121. <TextField
  122. className="rounded-input"
  123. name="password"
  124. label={t("common.labelPassword")}
  125. margin="normal"
  126. type={showPassword ? "text" : "password"}
  127. value={formik.values.password}
  128. onChange={formik.handleChange}
  129. error={formik.touched.password && Boolean(formik.errors.password)}
  130. helperText={formik.touched.password && formik.errors.password}
  131. fullWidth
  132. inputProps={{ "data-testid": "password-input" }}
  133. InputProps={{
  134. endAdornment: (
  135. <InputAdornment position="end">
  136. <IconButton
  137. onClick={handleClickShowPassword}
  138. onMouseDown={handleMouseDownPassword}
  139. >
  140. {showPassword ? <Visibility /> : <VisibilityOff />}
  141. </IconButton>
  142. </InputAdornment>
  143. ),
  144. }}
  145. />
  146. <TextField
  147. className="rounded-input"
  148. name="confirmPassword"
  149. label={t("common.labelConfirmPassword")}
  150. margin="normal"
  151. type={showConfirmPassword ? "text" : "password"}
  152. value={formik.values.confirmPassword}
  153. onChange={formik.handleChange}
  154. error={
  155. formik.touched.confirmPassword &&
  156. Boolean(formik.errors.confirmPassword)
  157. }
  158. helperText={
  159. formik.touched.confirmPassword && formik.errors.confirmPassword
  160. }
  161. fullWidth
  162. inputProps={{ "data-testid": "confirm-password-input" }}
  163. InputProps={{
  164. endAdornment: (
  165. <InputAdornment position="end">
  166. <IconButton
  167. onClick={handleClickShowConfirmPassword}
  168. onMouseDown={handleMouseDownConfirmPassword}
  169. >
  170. {showConfirmPassword ? <Visibility /> : <VisibilityOff />}
  171. </IconButton>
  172. </InputAdornment>
  173. ),
  174. }}
  175. />
  176. <Button
  177. type="submit"
  178. variant="contained"
  179. sx={{ mt: 3, mb: 2 }}
  180. fullWidth
  181. className="c-btn c-btn--primary"
  182. >
  183. {t("login.forgotYourPasswordButton")}
  184. </Button>
  185. <Grid container justifyContent="center">
  186. <Link
  187. to={BASE_PAGE}
  188. component={NavLink}
  189. variant="body2"
  190. underline="hover"
  191. data-testid="back-link"
  192. >
  193. {t("login.forgotYourPasswordBackLink")}
  194. </Link>
  195. </Grid>
  196. <div className="flex-center" data-testid="dilig-logo">
  197. <img src={DiligLogo} style={{ margin: "70px auto 0px auto" }} />
  198. </div>
  199. </Box>
  200. </Box>
  201. </Container>
  202. );
  203. };
  204. ResetPasswordPage.propTypes = {
  205. history: PropTypes.shape({
  206. replace: PropTypes.func,
  207. push: PropTypes.func,
  208. location: PropTypes.shape({
  209. pathname: PropTypes.string,
  210. }),
  211. }),
  212. };
  213. export default ResetPasswordPage;