Pages Product
This commit is contained in:
		| @@ -1,6 +1,6 @@ | |||||||
| import React, { useEffect, useState } from "react"; | import React, { useEffect, useState } from "react"; | ||||||
| import { useStore } from "../../utils/useStore"; | import { useStore } from "../../utils/useStore"; | ||||||
| import {Button, Card, Col, Input, Row, Select} from "antd"; | import { Button, Card, Col, Input, Row, Select, message } from "antd"; | ||||||
| import { observer } from "mobx-react-lite"; | import { observer } from "mobx-react-lite"; | ||||||
| import { BuyProductModal } from "../../component/BuyProductModal"; | import { BuyProductModal } from "../../component/BuyProductModal"; | ||||||
|  |  | ||||||
| @@ -13,6 +13,8 @@ export const Product = observer(() => { | |||||||
|   const [isLoading, setIsLoading] = useState(false); |   const [isLoading, setIsLoading] = useState(false); | ||||||
|   const [productData, setProductData] = useState([]); |   const [productData, setProductData] = useState([]); | ||||||
|   const [data, setData] = useState({}); |   const [data, setData] = useState({}); | ||||||
|  |   const [kode, setKode] = useState({}); | ||||||
|  |   const [cardIndex, setCardIndex] = useState({}); | ||||||
|  |  | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     const init = async () => { |     const init = async () => { | ||||||
| @@ -49,9 +51,14 @@ export const Product = observer(() => { | |||||||
|     await store.transaction.getData(); |     await store.transaction.getData(); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   const handleBuyProduct = (data) => { |   const handleBuyProduct = async (kode) => { | ||||||
|     setData(data); |     console.log(kode); | ||||||
|     store.transaction.visibleModalTransaction = true; |     try { | ||||||
|  |       await store.product.buyProduct({ productCode: kode }); | ||||||
|  |       message.success("Success Buy Product"); | ||||||
|  |     } catch (e) { | ||||||
|  |       message.error("Failed Buy Product"); | ||||||
|  |     } | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   return ( |   return ( | ||||||
| @@ -100,8 +107,16 @@ export const Product = observer(() => { | |||||||
|           {productData.map((item, index) => ( |           {productData.map((item, index) => ( | ||||||
|             <Col key={index} xs={24} md={16} lg={8}> |             <Col key={index} xs={24} md={16} lg={8}> | ||||||
|               <Card |               <Card | ||||||
|                   onClick={() => handleBuyProduct(item)} |                 onClick={() => { | ||||||
|                   style={{cursor: "pointer"}} |                   setKode(item.code); | ||||||
|  |                   setCardIndex(index); | ||||||
|  |                 }} | ||||||
|  |                 hoverable | ||||||
|  |                 style={{ | ||||||
|  |                   cursor: "pointer", | ||||||
|  |                   borderColor: cardIndex === index ? "#2D9CDB" : "", | ||||||
|  |                   marginLeft: "10px", | ||||||
|  |                 }} | ||||||
|               > |               > | ||||||
|                 <span style={{ color: "black" }}>{item.name}</span> |                 <span style={{ color: "black" }}>{item.name}</span> | ||||||
|                 <br /> |                 <br /> | ||||||
| @@ -118,7 +133,10 @@ export const Product = observer(() => { | |||||||
|       )} |       )} | ||||||
|       {productData.length !== 0 && ( |       {productData.length !== 0 && ( | ||||||
|         <Col style={{ textAlign: "right" }}> |         <Col style={{ textAlign: "right" }}> | ||||||
|           <Button style={{backgroundColor: "#2D9CDB", color: "white"}}> |           <Button | ||||||
|  |             style={{ backgroundColor: "#2D9CDB", color: "white" }} | ||||||
|  |             onClick={() => handleBuyProduct(kode)} | ||||||
|  |           > | ||||||
|             Beli Sekarang |             Beli Sekarang | ||||||
|           </Button> |           </Button> | ||||||
|         </Col> |         </Col> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user