refactor: resolve shopping loading issue
This commit is contained in:
@@ -22,15 +22,22 @@ const ShoppingCart = () => {
|
|||||||
const { formatPrice } = useCurrency();
|
const { formatPrice } = useCurrency();
|
||||||
|
|
||||||
const getCart = async () => {
|
const getCart = async () => {
|
||||||
token = localStorage.getItem("token")
|
const token = localStorage.getItem("token");
|
||||||
if (token == null) {
|
|
||||||
setCartItems([])
|
if (!token) {
|
||||||
} else {
|
console.log("User not logged in, setting empty cart");
|
||||||
|
setCartItems([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const response = await authAxios.get("/orders/cart/");
|
const response = await authAxios.get("/orders/cart/");
|
||||||
setCartItems(response.data);
|
setCartItems(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching cart:", error);
|
||||||
|
setCartItems([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getCart();
|
getCart();
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
Reference in New Issue
Block a user