diff --git a/src/App.tsx b/src/App.tsx
index 91f8a9c..af397d5 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -2,32 +2,11 @@ import { Suspense } from "react";
import styles from "./App.module.less";
import { useRoutes } from "react-router-dom";
import routes from "./routes";
-import { getToken } from "./utils/index";
-import { login } from "./api/index";
-import { useDispatch } from "react-redux";
-import {
- IsLoginActionCreator,
- SetUserActionCreator,
- SetPermisssionsActionCreator,
-} from "./store/user/userActions";
import LoadingPage from "./pages/loading";
function App() {
const Views = () => useRoutes(routes);
- const dispatch = useDispatch();
- const getUser = () => {
- login.getUser().then((res: any) => {
- const data = res.data;
- dispatch(IsLoginActionCreator());
- dispatch(SetUserActionCreator(data.user));
- dispatch(SetPermisssionsActionCreator(data.permissions));
- });
- };
- if (getToken()) {
- getUser();
- }
-
return (
}>
diff --git a/src/compenents/header/index.tsx b/src/compenents/header/index.tsx
index d9b864f..8953bd2 100644
--- a/src/compenents/header/index.tsx
+++ b/src/compenents/header/index.tsx
@@ -1,19 +1,19 @@
import React from "react";
import styles from "./index.module.less";
import { Button, Dropdown, MenuProps } from "antd";
-import { useSelector } from "../../store/hooks";
-import { useDispatch } from "react-redux";
+import { useDispatch, useSelector } from "react-redux";
import { useNavigate } from "react-router-dom";
-import { LoginOutActionCreator } from "../../store/user/userActions";
import avatar from "../../assets/images/commen/avatar.png";
+import { logoutAction } from "../../store/user/loginUserSlice";
export const Header: React.FC = () => {
const dispatch = useDispatch();
const navigate = useNavigate();
- const user = useSelector((state: any) => state.user);
+ const user = useSelector((state: any) => state.loginUser.value.user);
+
const onClick: MenuProps["onClick"] = ({ key }) => {
if (key === "login_out") {
- dispatch(LoginOutActionCreator());
+ dispatch(logoutAction());
navigate("/login");
} else if (key === "change_password") {
navigate("/change-password");
diff --git a/src/compenents/permission-button/index.tsx b/src/compenents/permission-button/index.tsx
index 8abc1bf..97d73a1 100644
--- a/src/compenents/permission-button/index.tsx
+++ b/src/compenents/permission-button/index.tsx
@@ -1,5 +1,5 @@
import { Button } from "antd";
-import { useSelector } from "../../store/hooks";
+import { useSelector } from "react-redux";
interface PropInterface {
type: "link" | "text" | "primary" | "default";
@@ -12,16 +12,18 @@ interface PropInterface {
}
export const PerButton = (props: PropInterface) => {
- const permisssions = useSelector((state: any) => state.permisssions);
- const through = () => {
- if (!permisssions) {
+ const permissions = useSelector(
+ (state: any) => state.loginUser.value.permissions
+ );
+ const isThrough = () => {
+ if (!permissions) {
return false;
}
- return typeof permisssions[props.p] !== "undefined";
+ return typeof permissions[props.p] !== "undefined";
};
return (
<>
- {through() && props.type === "link" && (
+ {isThrough() && props.type === "link" && (
)}
- {through() && props.type !== "link" && (
+ {isThrough() && props.type !== "link" && (