fix(Axios & Layout): add Shop-ID header to Axios instance and navigate to home on shop ID set
This commit is contained in:
@@ -10,6 +10,11 @@ const useAxios = () => {
|
|||||||
const instance = axios.create({
|
const instance = axios.create({
|
||||||
baseURL: "https://api.persain-game.com/api/v1",
|
baseURL: "https://api.persain-game.com/api/v1",
|
||||||
maxBodyLength: Infinity,
|
maxBodyLength: Infinity,
|
||||||
|
...(sessionStorage.getItem("shop_id") && {
|
||||||
|
headers: {
|
||||||
|
"Shop-ID": sessionStorage.getItem("shop_id"),
|
||||||
|
},
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.interceptors.request.use(
|
instance.interceptors.request.use(
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Outlet, useParams } from "react-router-dom";
|
import { Outlet, useNavigate, useParams } from "react-router-dom";
|
||||||
import Header from "../components/header";
|
import Header from "../components/header";
|
||||||
import Footer from "../components/footer";
|
import Footer from "../components/footer";
|
||||||
import Particle from "../components/particle";
|
import Particle from "../components/particle";
|
||||||
@@ -11,7 +11,7 @@ import { setShopId } from "../redux/slices/shop-id";
|
|||||||
|
|
||||||
const Layout = () => {
|
const Layout = () => {
|
||||||
const { configs } = useParams<{ configs: string }>();
|
const { configs } = useParams<{ configs: string }>();
|
||||||
|
const navigate = useNavigate();
|
||||||
const shopId = new URLSearchParams(window.location.search).get("shop_id");
|
const shopId = new URLSearchParams(window.location.search).get("shop_id");
|
||||||
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -33,6 +33,7 @@ const Layout = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (shopId) {
|
if (shopId) {
|
||||||
dispatch(setShopId(shopId));
|
dispatch(setShopId(shopId));
|
||||||
|
navigate("/");
|
||||||
}
|
}
|
||||||
}, [shopId, dispatch]);
|
}, [shopId, dispatch]);
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const shopIdSlice = createSlice({
|
|||||||
reducers: {
|
reducers: {
|
||||||
setShopId: (state, action: PayloadAction<string>) => {
|
setShopId: (state, action: PayloadAction<string>) => {
|
||||||
state.shop_id = action.payload;
|
state.shop_id = action.payload;
|
||||||
|
sessionStorage.setItem("shop_id", action.payload);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user