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.

AuthCallback.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React, { useEffect } from "react";
  2. import { useLocation } from "react-router-dom";
  3. import { HOME_PAGE } from "constants/pages";
  4. import PropTypes from "prop-types";
  5. import { useParams } from "react-router-dom";
  6. import { useDispatch, useSelector } from "react-redux";
  7. import { fetchAuthProvider } from "store/actions/authProvider/authProviderActions";
  8. import { selectIsLoadingByActionType } from "store/selectors/loadingSelectors";
  9. import { AUTH_PROVIDER_SCOPE } from "store/actions/authProvider/authProviderActionConstants";
  10. import Backdrop from 'components/MUI/BackdropComponent';
  11. function AuthCallback({ history }) {
  12. const dispatch = useDispatch();
  13. const { provider } = useParams();
  14. const location = useLocation();
  15. const handleApiResponseSuccess = () => {
  16. history.push({
  17. pathname: HOME_PAGE,
  18. state: {
  19. from: history.location.pathname,
  20. },
  21. });
  22. };
  23. const isLoading = useSelector(selectIsLoadingByActionType(AUTH_PROVIDER_SCOPE));
  24. useEffect(() => {
  25. if (!location) {
  26. return;
  27. }
  28. const { search } = location;
  29. dispatch(fetchAuthProvider({ provider, search, handleApiResponseSuccess }));
  30. }, [location]);
  31. return (
  32. <div>
  33. {isLoading && <Backdrop position="absolute" isLoading={isLoading} />}
  34. </div>
  35. );
  36. }
  37. AuthCallback.propTypes = {
  38. history: PropTypes.shape({
  39. replace: PropTypes.func,
  40. push: PropTypes.func,
  41. location: PropTypes.shape({
  42. pathname: PropTypes.string,
  43. }),
  44. }),
  45. };
  46. export default AuthCallback;