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

ResetPasswordPageMUI.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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) { return pair[1]; }
  32. }
  33. return (false);
  34. }
  35. const ResetPasswordPage = ({ history }) => {
  36. const dispatch = useDispatch();
  37. const { t } = useTranslation();
  38. const [showPassword, setShowPassword] = useState(false);
  39. const [showConfirmPassword, setShowConfirmPassword] = useState(false);
  40. const handleClickShowPassword = () => setShowPassword(!showPassword);
  41. const handleMouseDownPassword = () => setShowPassword(!showPassword);
  42. const handleClickShowConfirmPassword = () => setShowConfirmPassword(!showConfirmPassword);
  43. const handleMouseDownConfirmPassword = () => setShowConfirmPassword(!showConfirmPassword);
  44. const resetPasswordValidationSchema = Yup.object().shape({
  45. password: Yup.string().required(t("login.passwordRequired")),
  46. confirmPassword: Yup.string().required(t("login.passwordRequired"))
  47. .oneOf([Yup.ref('password'), null], t('login.passwordDontMatch'))
  48. });
  49. const handleSubmit = (values) => {
  50. const password = values.password;
  51. // const confirmPassword = values.confirmPassword;
  52. // if (password === confirmPassword)
  53. {
  54. const code = getQueryVariable('token'),
  55. email = getQueryVariable('email');
  56. dispatch(
  57. resetPassword({
  58. code,
  59. email,
  60. password,
  61. handleApiResponseSuccess,
  62. })
  63. );
  64. }
  65. };
  66. const handleApiResponseSuccess = () => {
  67. history.push({
  68. pathname: BASE_PAGE,
  69. state: {
  70. from: history.location.pathname,
  71. },
  72. });
  73. };
  74. const formik = useFormik({
  75. initialValues: {
  76. password: '',
  77. confirmPassword: '',
  78. },
  79. validationSchema: resetPasswordValidationSchema,
  80. onSubmit: handleSubmit,
  81. validateOnBlur: true,
  82. enableReinitialize: true,
  83. });
  84. return (
  85. <Container
  86. component="main"
  87. maxWidth="xl"
  88. className="c-login-container"
  89. fullwidth="true">
  90. <div className="l-t-rectangle"></div>
  91. <div className="r-b-rectangle"></div>
  92. <Box
  93. sx={{
  94. marginTop: 2,
  95. width: 350,
  96. height: 684,
  97. display: "flex",
  98. flexDirection: "column",
  99. alignItems: "center",
  100. }}
  101. >
  102. <img src={HrLogo} className="login-logo" />
  103. <Typography variant="h5" sx={{ m: 2, mt: 3 }}>
  104. {t("login.resetYourPassword")}
  105. </Typography>
  106. <Typography variant="p">
  107. {t("login.resetYourPasswordHelpText")}
  108. </Typography>
  109. <Box
  110. component="form"
  111. onSubmit={formik.handleSubmit}
  112. sx={{ position: 'relative', mt: 1, p: 1 }}
  113. >
  114. <Backdrop position="absolute" isLoading={false} />
  115. <TextField
  116. className="rounded-input"
  117. name="password"
  118. label={t("common.labelPassword")}
  119. margin="normal"
  120. type={showPassword ? "text" : "password"}
  121. value={formik.values.password}
  122. onChange={formik.handleChange}
  123. error={formik.touched.password && Boolean(formik.errors.password)}
  124. helperText={formik.touched.password && formik.errors.password}
  125. fullWidth
  126. InputProps={{
  127. endAdornment: (
  128. <InputAdornment position="end">
  129. <IconButton
  130. onClick={handleClickShowPassword}
  131. onMouseDown={handleMouseDownPassword}
  132. >
  133. {showPassword ? <Visibility /> : <VisibilityOff />}
  134. </IconButton>
  135. </InputAdornment>
  136. ),
  137. }}
  138. />
  139. <TextField
  140. className="rounded-input"
  141. name="confirmPassword"
  142. label={t("common.labelConfirmPassword")}
  143. margin="normal"
  144. type={showConfirmPassword ? "text" : "password"}
  145. value={formik.values.confirmPassword}
  146. onChange={formik.handleChange}
  147. error={formik.touched.confirmPassword && Boolean(formik.errors.confirmPassword)}
  148. helperText={formik.touched.confirmPassword && formik.errors.confirmPassword}
  149. fullWidth
  150. InputProps={{
  151. endAdornment: (
  152. <InputAdornment position="end">
  153. <IconButton
  154. onClick={handleClickShowConfirmPassword}
  155. onMouseDown={handleMouseDownConfirmPassword}
  156. >
  157. {showConfirmPassword ? <Visibility /> : <VisibilityOff />}
  158. </IconButton>
  159. </InputAdornment>
  160. ),
  161. }}
  162. />
  163. <Button
  164. type="submit"
  165. variant="contained"
  166. sx={{ mt: 3, mb: 2 }}
  167. fullWidth
  168. className="c-btn c-btn--primary"
  169. >
  170. {t('login.forgotYourPasswordButton')}
  171. </Button>
  172. <Grid container justifyContent="center">
  173. <Link
  174. to={BASE_PAGE}
  175. component={NavLink}
  176. variant="body2"
  177. underline="hover"
  178. >
  179. {t('login.forgotYourPasswordBackLink')}
  180. </Link>
  181. </Grid>
  182. <div className="flex-center">
  183. <img src={DiligLogo} style={{ margin: "70px auto 0px auto" }} />
  184. </div>
  185. </Box>
  186. </Box>
  187. </Container>
  188. );
  189. };
  190. ResetPasswordPage.propTypes = {
  191. history: PropTypes.shape({
  192. replace: PropTypes.func,
  193. push: PropTypes.func,
  194. location: PropTypes.shape({
  195. pathname: PropTypes.string,
  196. }),
  197. }),
  198. }
  199. export default ResetPasswordPage;