diff --git a/@types/index.d.ts b/@types/index.d.ts index 6d983ab9a..4af398894 100644 --- a/@types/index.d.ts +++ b/@types/index.d.ts @@ -181,9 +181,20 @@ export interface Data { updatedAt: string; products: Product; } -export interface ShopData { - products: Product; - data?: Data; +interface PaginationData { + totalItems: number; + totalPages: number; + currentPage: number; + pageSize: number; +} +interface ShopData { + code: string; + message: string; + data: ShopResponse; +} +export interface ShopResponse { + shop: Data; + pagination: PaginationData; } export interface SEOProps { diff --git a/components/Navbars/TopBar.tsx b/components/Navbars/TopBar.tsx index b95bb24d2..b0d65b424 100644 --- a/components/Navbars/TopBar.tsx +++ b/components/Navbars/TopBar.tsx @@ -544,14 +544,17 @@ function TopBar(props: { activePage: string; showDashBorad: boolean }) { height={24} alt="Cart Icon" /> - + + + +

{globalAuth?.user?.firstName} {globalAuth?.user?.lastName}

- -
+ {/*
*/} + {' '}
{/* {notificationMenu && diff --git a/modules/shop/ZuriLandingPage.tsx b/modules/shop/ZuriLandingPage.tsx index 5103353ea..87daaed32 100644 --- a/modules/shop/ZuriLandingPage.tsx +++ b/modules/shop/ZuriLandingPage.tsx @@ -39,9 +39,12 @@ const ZuriLandingPage = () => { setShowLoader(true); if (shop_id) { try { - const response = await axios.get(`https://zuriportfolio-shop-internal-api.onrender.com/api/shop/${shop_id}`); + const response = await axios.get( + `https://zuriportfolio-shop-internal-api.onrender.com/api/v1/shop/${shop_id}`, + ); setShop(response.data); + console.log('Shop Data:', response.data); setTimeout(() => { setShowLoader(false); @@ -66,20 +69,23 @@ const ZuriLandingPage = () => { }, [router.query.shop_id, shop_id]); if (shop && shop.data) { - const shopName = shop.data?.name; + const shopName = shop.data?.shop.name; + console.log('Shop Name:', shopName); } if (shop && shop.data) { - const shopP = shop.data?.products; + const shopP = shop.data?.shop.products; } useEffect(() => { if (shop) { - const shopProducts = shop.data?.products || []; + const shopProducts = shop.data?.shop.products || []; setProducts(shopProducts); } }, [shop]); - const totalPageCount = Math.ceil(products.length / productsPerPage); + + const paginationData = shop?.data?.pagination; + const totalPageCount = paginationData ? Math.ceil(paginationData.totalItems / paginationData.pageSize) : 0; const handlePageChange = (newPage: number) => { setCurrentPage(newPage); @@ -89,16 +95,16 @@ const ZuriLandingPage = () => {
- {shop ? `${shop.data?.name} Shop - Discover, Buy, and Sell` : ''} + {shop ? `${shop.data?.shop.name} Shop - Discover, Buy, and Sell` : ''} - + @@ -118,7 +124,7 @@ const ZuriLandingPage = () => {
{shop ? (
-

Hello, Welcome to {shop.data?.name}.

+

Hello, Welcome to {shop.data?.shop.name}.

) : loading ? (
@@ -144,15 +150,15 @@ const ZuriLandingPage = () => { {totalPageCount > 1 && ( )}
-
+
); }; diff --git a/modules/shop/component/productPage/ProductCard/ProductCard.tsx b/modules/shop/component/productPage/ProductCard/ProductCard.tsx index 516cb4fad..60f63cc34 100644 --- a/modules/shop/component/productPage/ProductCard/ProductCard.tsx +++ b/modules/shop/component/productPage/ProductCard/ProductCard.tsx @@ -52,7 +52,7 @@ const ProductCard: React.FC = ({ product, shopName, searchQuer } else { try { const response = await axios.post( - 'https://zuri-cart-checkout.onrender.com/api/checkout_cart/carts', + 'https://zuriportfolio-shop-internal-api.onrender.com/api/v1/checkout_cart/carts', { product_ids: [product.id], }, @@ -132,7 +132,9 @@ const ProductCard: React.FC = ({ product, shopName, searchQuer className="md:text-sm text-xs text-black font-manropeB capitalize" dangerouslySetInnerHTML={{ __html: highlightSearchQuery(product.name, searchQuery) }} >{' '} -

₦{product.price.toLocaleString()}

+

+ ₦{product.discount_price.toLocaleString()} +

{shopName && (

diff --git a/modules/shop/component/productPage/ShopProduct/ShopProductList.tsx b/modules/shop/component/productPage/ShopProduct/ShopProductList.tsx index 55f1258f9..d95bc41c8 100644 --- a/modules/shop/component/productPage/ShopProduct/ShopProductList.tsx +++ b/modules/shop/component/productPage/ShopProduct/ShopProductList.tsx @@ -13,11 +13,15 @@ interface ShopProductListProps { const ShopProductList: React.FC = ({ shop, currentPage, productsPerPage, searchQuery }) => { const shopData = shop?.data; - if (!shopData) { - return null; + if (!shopData || !Array.isArray(shopData.shop.products)) { + return ( +

+

No products available.

+
+ ); } - const filteredProducts = shopData.products.filter((product: Products) => + const filteredProducts = shopData.shop.products.filter((product: Products) => product.name.toLowerCase().includes(searchQuery.toLowerCase()), ); @@ -26,7 +30,6 @@ const ShopProductList: React.FC = ({ shop, currentPage, pr position: 'top-right', }); } - const startIndex = (currentPage - 1) * productsPerPage; const endIndex = startIndex + productsPerPage; const productsToDisplay = filteredProducts.slice(startIndex, endIndex); @@ -35,7 +38,12 @@ const ShopProductList: React.FC = ({ shop, currentPage, pr
{productsToDisplay.map((product: Products) => ( - + ))}
diff --git a/modules/shop/productDetails.tsx b/modules/shop/productDetails.tsx index 0db32e5e5..c70e55647 100644 --- a/modules/shop/productDetails.tsx +++ b/modules/shop/productDetails.tsx @@ -43,7 +43,7 @@ export default function ProductDetails() { const { id } = router.query; if (id) { setLoading(true); - fetch(`https://zuriportfolio-shop-internal-api.onrender.com/api/product/${id}`) + fetch(`https://zuriportfolio-shop-internal-api.onrender.com/api/v1/product/${id}`) .then((response) => response.json()) .then((response) => { setProduct(response.data); @@ -66,7 +66,7 @@ export default function ProductDetails() { useEffect(() => { if (shopID) { - fetch(`https://zuriportfolio-shop-internal-api.onrender.com/api/shop/${shopID}`) + fetch(`https://zuriportfolio-shop-internal-api.onrender.com/api/v1/shop/${shopID}`) .then((response) => response.json()) .then((response) => { setOtherProducts(response.data.products); @@ -178,7 +178,7 @@ export default function ProductDetails() { } else { try { const response = await axios.post( - 'https://zuri-cart-checkout.onrender.com/api/checkout_cart/carts', + 'https://zuriportfolio-shop-internal-api.onrender.com/api/v1/checkout_cart/carts', { product_ids: [product.id], }, @@ -375,7 +375,7 @@ export default function ProductDetails() { Other Products By {shopName}{' '}
- {otherProducts.length > 0 ? ( + {otherProducts && otherProducts.length > 0 ? ( <>