fix api /me
This commit is contained in:
parent
5e7c9dec79
commit
80ebf85347
@ -1,6 +1,8 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
import { getToken, urlHasParams } from "@utils/helper";
|
import { getToken, urlHasParams } from "@utils/helper";
|
||||||
|
import { store } from "@store/store";
|
||||||
|
import { setProfileInfo } from "@redux/outstaffingSlice";
|
||||||
|
|
||||||
const instance = axios.create({
|
const instance = axios.create({
|
||||||
baseURL: process.env.REACT_APP_API_URL,
|
baseURL: process.env.REACT_APP_API_URL,
|
||||||
@ -39,6 +41,7 @@ export const apiRequest = (
|
|||||||
window.location.replace("/auth");
|
window.location.replace("/auth");
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
// dispatch(auth(false));
|
// dispatch(auth(false));
|
||||||
|
store.dispatch(setProfileInfo({}))
|
||||||
}
|
}
|
||||||
return resolve(response);
|
return resolve(response);
|
||||||
})
|
})
|
||||||
|
@ -2,12 +2,10 @@ import React, { useEffect, useState } from "react";
|
|||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { NavLink } from "react-router-dom";
|
import { NavLink } from "react-router-dom";
|
||||||
|
|
||||||
import { getProfileInfo, setProfileInfo } from "@redux/outstaffingSlice";
|
import { getProfileInfo } from "@redux/outstaffingSlice";
|
||||||
|
|
||||||
import { urlForLocal } from "@utils/helper";
|
import { urlForLocal } from "@utils/helper";
|
||||||
|
|
||||||
import { apiRequest } from "@api/request";
|
|
||||||
|
|
||||||
import avatarMok from "assets/images/avatarMok.png";
|
import avatarMok from "assets/images/avatarMok.png";
|
||||||
|
|
||||||
export const Navigation = () => {
|
export const Navigation = () => {
|
||||||
@ -77,17 +75,17 @@ export const Navigation = () => {
|
|||||||
if (localStorage.getItem("role_status") === "18") {
|
if (localStorage.getItem("role_status") === "18") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Object.keys(profileInfo).length) {
|
// if (Object.keys(profileInfo).length) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
apiRequest(`/user/me`).then((profileInfo) =>
|
// apiRequest(`/user/me`).then((profileInfo) =>
|
||||||
dispatch(
|
// dispatch(
|
||||||
setProfileInfo(
|
// setProfileInfo(
|
||||||
profileInfo.userCard ? profileInfo.userCard : profileInfo
|
// profileInfo.userCard ? profileInfo.userCard : profileInfo
|
||||||
)
|
// )
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
}, [dispatch]);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="profileHeader__info">
|
<div className="profileHeader__info">
|
||||||
|
@ -20,21 +20,21 @@ export const ProfileHeader = () => {
|
|||||||
|
|
||||||
const [isLoggingOut, setIsLoggingOut] = useState(false);
|
const [isLoggingOut, setIsLoggingOut] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
if (Object.keys(profileInfo).length) {
|
// if (Object.keys(profileInfo).length) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
apiRequest(`/user/me`).then((profileInfo) => {
|
// apiRequest(`/user/me`).then((profileInfo) => {
|
||||||
dispatch(
|
// dispatch(
|
||||||
setProfileInfo(
|
// setProfileInfo(
|
||||||
profileInfo.userCard ? profileInfo.userCard : profileInfo
|
// profileInfo.userCard ? profileInfo.userCard : profileInfo
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
}, [dispatch]);
|
// }, [dispatch]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
apiRequest(`/user/me`).then((profileInfo) => {
|
if (!Object.keys(profileInfo).length) apiRequest(`/user/me`).then((profileInfo) => {
|
||||||
dispatch(
|
dispatch(
|
||||||
setProfileInfo(
|
setProfileInfo(
|
||||||
profileInfo.userCard ? profileInfo.userCard : profileInfo
|
profileInfo.userCard ? profileInfo.userCard : profileInfo
|
||||||
@ -49,6 +49,7 @@ export const ProfileHeader = () => {
|
|||||||
dispatch(auth(false));
|
dispatch(auth(false));
|
||||||
setIsLoggingOut(false);
|
setIsLoggingOut(false);
|
||||||
navigate("/auth");
|
navigate("/auth");
|
||||||
|
dispatch(setProfileInfo({}))
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user