From cb865ccd5a04383c22700ee1b1f73a5006775196 Mon Sep 17 00:00:00 2001
From: Imanuel Raditya <16521421@mahasiswa.itb.ac.id>
Date: Mon, 27 Nov 2023 21:09:58 +0700
Subject: [PATCH] fix(UC04): fix bugs when adding product to cart

---
 frontend/src/components/ProductCard.tsx | 3 +--
 frontend/src/pages/TenantInfo.tsx       | 6 ++++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/frontend/src/components/ProductCard.tsx b/frontend/src/components/ProductCard.tsx
index 013db6f..5743458 100644
--- a/frontend/src/components/ProductCard.tsx
+++ b/frontend/src/components/ProductCard.tsx
@@ -23,8 +23,6 @@ export default function ProductCard({ data }: { data: ProductCardProps[] }) {
     const productlist = data.map(({ id, image, name, description, price, id_tenant }) => {
         const [isAdded, setIsAdded] = useLocalStorage<boolean>(`product-${id}`, false);
 
-        // find cartItem id_tenant
-
         const [productData, setProductData] = useState<Product[]>([]);
 
         const getProductData = async () => {
@@ -58,6 +56,7 @@ export default function ProductCard({ data }: { data: ProductCardProps[] }) {
             if (cartItems.length > 0) {
                 const cartItem = cartItems[0];
                 const cartTenantId = cartItem && productData.find((product: Product) => product.id === cartItem.id)?.id_tenant;
+                console.log(cartTenantId);
                 if (cartTenantId !== id_tenant) {
                     alert("You can't add items from different tenants to the cart!");
                     return;
diff --git a/frontend/src/pages/TenantInfo.tsx b/frontend/src/pages/TenantInfo.tsx
index eced360..55ef10d 100644
--- a/frontend/src/pages/TenantInfo.tsx
+++ b/frontend/src/pages/TenantInfo.tsx
@@ -42,7 +42,8 @@ interface ProductCard {
     image: string,
     name: string,
     description: string,
-    price: number
+    price: number,
+    id_tenant: number
 }
 
 export default function TenantInfo() {
@@ -103,7 +104,8 @@ export default function TenantInfo() {
                 image: product.image,
                 name: product.name,
                 description: product.description,
-                price: product.price
+                price: product.price,
+                id_tenant: product.id_tenant
             }
         });
 
-- 
GitLab