Skip to content

Commit

Permalink
fix(product page): Addressed unhandled errors in the product page.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakizimana-Clement committed Jul 12, 2024
1 parent ac9b802 commit 2d5539d
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/pages/ProductsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useState } from 'react';
import { FaCaretDown, FaHeart, FaStar } from 'react-icons/fa';
import { IoFilter } from 'react-icons/io5';
import { ScaleLoader } from 'react-spinners';
import { toast } from 'sonner';
import { DynamicData } from '../@types/DynamicData';
import { searchInputs } from '../@types/SearchType';
import Button from '../components/buttons/Button';
Expand Down Expand Up @@ -43,15 +44,29 @@ const ProductsPage = () => {
});

useEffect(() => {
if (products && !products.length && tokenInfo) {
dispatch(getProducts()).unwrap();
}
const fetchProducts = async () => {
try {
if (products && !products.length && tokenInfo) {
await dispatch(getProducts()).unwrap();
}
} catch (error) {
toast.error('Error fetching products');
}
};
fetchProducts();
}, [dispatch, products, tokenInfo]);

useEffect(() => {
if (carts && !carts.length) {
dispatch(getCarts()).unwrap();
}
const fetchCarts = async () => {
try {
if (carts && !carts.length) {
await dispatch(getCarts()).unwrap();
}
} catch (error) {
toast.error('Error fetching carts');
}
};
fetchCarts();
}, [dispatch]);

useEffect(() => {
Expand Down

0 comments on commit 2d5539d

Please sign in to comment.