You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RegisterPage.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* eslint-disable */
  2. import React, { useEffect, useState, useContext } from "react";
  3. import PropTypes from "prop-types";
  4. import { useFormik } from "formik";
  5. import { useDispatch, useSelector } from "react-redux";
  6. import { NavLink, useLocation } from "react-router-dom";
  7. import * as Yup from "yup";
  8. import { useTranslation } from "react-i18next";
  9. import HrLogo from "../../assets/images/hrcenter.png";
  10. import jwt_decode from "jwt-decode";
  11. import {
  12. clearLoginErrors,
  13. fetchUser,
  14. fetchGoogleUser,
  15. } from "../../store/actions/login/loginActions";
  16. import { selectLoginError } from "../../store/selectors/loginSelectors";
  17. import {
  18. ADS_PAGE,
  19. FORGOT_PASSWORD_PAGE,
  20. HOME_PAGE,
  21. } from "../../constants/pages";
  22. import {
  23. Box,
  24. Button,
  25. Container,
  26. Grid,
  27. IconButton,
  28. InputAdornment,
  29. Link,
  30. TextField,
  31. Typography,
  32. } from "@mui/material";
  33. import { Visibility, VisibilityOff } from "@mui/icons-material";
  34. import Backdrop from "../../components/MUI/BackdropComponent";
  35. import ErrorMessage from "../../components/MUI/ErrorMessageComponent";
  36. import { selectIsLoadingByActionType } from "../../store/selectors/loadingSelectors";
  37. import {
  38. LOGIN_USER_LOADING,
  39. LOGIN_GOOGLE_USER_LOADING,
  40. } from "../../store/actions/login/loginActionConstants";
  41. import { authScopeStringGetHelper } from "../../util/helpers/authScopeHelpers";
  42. import { JWT_TOKEN } from "../../constants/localStorage";
  43. import Step from "../../components/Registration/Step";
  44. import { FormContext, FormProvider } from "../../context/FormContext";
  45. import { selectIsUserAuthenticated } from "../../store/selectors/userSelectors";
  46. const RegisterPage = ({ history }) => {
  47. // const dispatch = useDispatch();
  48. const { t } = useTranslation();
  49. // const error = useSelector(selectLoginError);
  50. const { search } = useLocation();
  51. const { activeStepIndex } = useContext(FormContext);
  52. const [showPassword, setShowPassword] = useState(false);
  53. const [firstDone, setFirst] = useState(false);
  54. const [isInit, setIsInit] = useState(true);
  55. const handleClickShowPassword = () => setShowPassword(!showPassword);
  56. const handleMouseDownPassword = () => setShowPassword(!showPassword);
  57. const handleCallbackResponse = (response) => {
  58. const userObject = jwt_decode(response.credential);
  59. const user = userObject;
  60. const token = response.credential;
  61. dispatch(clearLoginErrors());
  62. dispatch(
  63. fetchGoogleUser({
  64. user,
  65. token,
  66. handleApiResponseSuccess,
  67. })
  68. );
  69. };
  70. const isLoading = useSelector(
  71. selectIsLoadingByActionType(LOGIN_USER_LOADING)
  72. );
  73. const isGoogleLoading = useSelector(
  74. selectIsLoadingByActionType(LOGIN_GOOGLE_USER_LOADING)
  75. );
  76. const isUserAuthenticated = useSelector(selectIsUserAuthenticated);
  77. useEffect(() => {
  78. if (isInit) {
  79. setIsInit(false);
  80. return;
  81. }
  82. if (!isUserAuthenticated) {
  83. history.push({ pathname: ADS_PAGE });
  84. }
  85. }, [isInit]);
  86. return (
  87. <>
  88. <Container
  89. component="main"
  90. maxWidth="xl"
  91. className="c-login-container"
  92. fullwidth="true"
  93. >
  94. <div className="l-t-rectangle"></div>
  95. <div className="r-b-rectangle"></div>
  96. <Box
  97. sx={{
  98. marginTop: 2,
  99. width: 289,
  100. height: 684,
  101. display: "flex",
  102. flexDirection: "column",
  103. alignItems: "center",
  104. }}
  105. >
  106. <img src={HrLogo} className="login-logo" />
  107. {search.split("&")[1]?.split("=")[1] ? (
  108. <>
  109. <Typography variant="h5" sx={{ m: 1, mt: 3 }}>
  110. {t("login.welcome")}
  111. </Typography>
  112. <Typography variant="p" sx={{ mb: 2 }}>
  113. Dva koraka do HR Centra.
  114. </Typography>
  115. <div className="steps-cont">
  116. <div
  117. className={`step ${
  118. activeStepIndex && activeStepIndex === 1
  119. ? "done"
  120. : "current"
  121. }`}
  122. >
  123. 1
  124. </div>
  125. <div className="line-btw"></div>
  126. <div
  127. className={`step ${
  128. activeStepIndex && activeStepIndex === 1
  129. ? "current"
  130. : "disallowed"
  131. }`}
  132. >
  133. 2
  134. </div>
  135. </div>
  136. <Step />
  137. </>
  138. ) : (
  139. <h3 style={{ margin: "50px 0px" }}>There was a mistake...</h3>
  140. )}
  141. </Box>
  142. </Container>
  143. </>
  144. );
  145. };
  146. RegisterPage.propTypes = {
  147. history: PropTypes.shape({
  148. replace: PropTypes.func,
  149. push: PropTypes.func,
  150. location: PropTypes.shape({
  151. pathname: PropTypes.string,
  152. }),
  153. }),
  154. };
  155. export default RegisterPage;