diff --git a/app/category-page/all-products/page.tsx b/app/category-page/all-products/page.tsx new file mode 100644 index 00000000..151c7e08 --- /dev/null +++ b/app/category-page/all-products/page.tsx @@ -0,0 +1,107 @@ +"use client"; + +import React, { useState, useEffect, Dispatch, SetStateAction } from "react"; +import ProductCard from "@/components/ProductCard"; +import logo from "@/public/belinda-images/logo.png"; +import { Container, Grid, Typography } from "@mui/material"; +// WARNING: You won't be able to connect to local backend unless you remove the env variable below. +const URL = process.env.BELINDAS_CLOSET_PUBLIC_API_URL || "http://localhost:3000/api"; +const placeholderImg = logo; +interface Product { + _id: string; + productImage: typeof placeholderImg; + productType: string[]; + productGender: string; + productSizeShoe: string; + productSizes: string; + productSizePantsWaist: string; + productSizePantsInseam: string; + productDescription: string; + isHidden: Boolean; + isSold: Boolean; +} + +async function fetchData( + categoryId: string, + setProducts: Dispatch> +) { + const apiUrl = `${URL}/products`; + const fetchUrl = `${apiUrl}`; + + try { + const res = await fetch(fetchUrl, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }); + if (!res.ok) { + throw new Error(res.statusText); + } else { + const data = await res.json(); + const filteredData = data.filter((product: Product) => !product.isHidden); + setProducts(data); + console.log(data); + } + } catch (error) { + console.error("Error getting product:", error); + } +} + +const ViewProduct = ({ categoryId }: { categoryId: string }) => { + const [products, setProducts] = useState([]); + const [filteredProducts, setFilteredProducts] = useState([]); + + useEffect(() => { + fetchData(categoryId, setProducts); // Pass categoryId to fetchData + }, [categoryId]); + + useEffect(() => { + setFilteredProducts( + products.filter((product) => !product.isHidden && !product.isSold) + ); + }, [products]); + + return ( + + + Found {filteredProducts.length} products in All Products + + + {filteredProducts.map((product, index) => ( + // + + + + ))} + + + ); +}; +export default function ProductList({ + params, +}: { + params: { categoryId: string }; +}) { + const decodedCategoryId = decodeURIComponent(params.categoryId); + + return ; +}