/* eslint-disable @typescript-eslint/no-var-requires */
import * as React from 'react';
import { useEffect } from 'react';
import { HashRouter } from 'react-router-dom';
import { useDispatch } from 'react-redux';
import Layouts from 'layout';
import { getUserInfo } from 'store/reducers/user';

import fetchData from 'utils/fetchData';

const projectConfig = require('configure/projectConfig.json');

function App() {
  const dispatch = useDispatch();
  const fetchUserInfo = () => {
    const { curUser } = projectConfig.ajax;
    return fetchData(curUser);
  };

  useEffect(() => {
    fetchUserInfo().then((data: any) => {
      const { name, account } = data || {};
      dispatch(
        getUserInfo({
          userName: name,
          userId: account,
        })
      );
    });
  }, [dispatch]);

  return (
    <HashRouter basename="">
      <Layouts />
    </HashRouter>
  );
}

export default App;
