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.
 
 

72 line
2.4 KiB

  1. import * as React from "react";
  2. import * as HttpUtils from "utils/HttpUtils";
  3. import * as UrlUtils from "utils/ApiPathConst";
  4. import { useNavigate } from "react-router-dom";
  5. import { useDispatch } from "react-redux";
  6. import { handleLogoutFunction, handleLogin } from 'auth/index';
  7. import Loadable from 'components/Loadable';
  8. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  9. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  10. const Index = () => {
  11. const dispatch = useDispatch()
  12. const navigate = useNavigate()
  13. React.useEffect(() => {
  14. getPrfile();
  15. }, []);
  16. function getPrfile(){
  17. dispatch(handleLogoutFunction());
  18. let params = new URLSearchParams(window.location.search)
  19. if(params.get("code")){
  20. HttpUtils.post({
  21. url: UrlUtils.GET_SMART_LOGIN,
  22. params:{
  23. code: params.get("code")
  24. },
  25. onSuccess: (responseData) => {
  26. //navigate('/iAmSmartRegisterFrom', { state: { responseData: responseData } });
  27. console.log(response)
  28. const userData = {
  29. id: responseData.id,
  30. fullenName: responseData.name,
  31. fullchName: responseData.chName,
  32. email: responseData.email,
  33. type: responseData.type,
  34. role: responseData.role,
  35. abilities: responseData.abilities,
  36. creditor: responseData.creditor,
  37. //avatar: require('src/assets/images/users/avatar-3.png').default,
  38. }
  39. const data = { ...userData, accessToken: responseData.accessToken, refreshToken: responseData.refreshToken }
  40. // setSuccess(true)
  41. dispatch(handleLogin(data))
  42. navigate('/dashboard');
  43. location.reload()
  44. },
  45. onFail: ()=>{
  46. window.location.assign("/login");
  47. },
  48. onError:()=>{
  49. window.location.assign("/login");
  50. }
  51. });
  52. }
  53. }
  54. return (
  55. <LoadingComponent />
  56. );
  57. };
  58. export default Index;