membership
This commit is contained in:
		| @@ -39,6 +39,7 @@ export const Membership = observer(() => { | |||||||
|   const [confirmLoading, setConfirmLoading] = useState(false); |   const [confirmLoading, setConfirmLoading] = useState(false); | ||||||
|   const [isLoading, setIsLoading] = useState(false); |   const [isLoading, setIsLoading] = useState(false); | ||||||
|  |  | ||||||
|  |    | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     const init = async () => { |     const init = async () => { | ||||||
|       try { |       try { | ||||||
| @@ -146,7 +147,8 @@ export const Membership = observer(() => { | |||||||
|           </Button> |           </Button> | ||||||
|           <Button |           <Button | ||||||
|             onClick={() => { |             onClick={() => { | ||||||
|               setDestination(record?.user_detail?.id); |               setDestination(record?.id); | ||||||
|  |               console.log(record?.id) | ||||||
|               setIsVisibleTopUpModal(true); |               setIsVisibleTopUpModal(true); | ||||||
|             }} |             }} | ||||||
|           > |           > | ||||||
| @@ -426,7 +428,7 @@ export const Membership = observer(() => { | |||||||
|             label="Amount" |             label="Amount" | ||||||
|             rules={[{ required: true, message: "Please input amount!" }]} |             rules={[{ required: true, message: "Please input amount!" }]} | ||||||
|           > |           > | ||||||
|             <Input /> |             <Input/> | ||||||
|           </Form.Item> |           </Form.Item> | ||||||
|         </Form> |         </Form> | ||||||
|       </Modal> |       </Modal> | ||||||
|   | |||||||
| @@ -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,7 @@ 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({}); | ||||||
|  |  | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     const init = async () => { |     const init = async () => { | ||||||
| @@ -49,9 +50,18 @@ export const Product = observer(() => { | |||||||
|     await store.transaction.getData(); |     await store.transaction.getData(); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   const handleBuyProduct = (data) => { |   const handleBuy = async (data) => { | ||||||
|     setData(data); |     setKode(data.code); | ||||||
|     store.transaction.visibleModalTransaction = true; |     //console.log(data.code) | ||||||
|  |   }; | ||||||
|  |   const handleBuyProduct = async (kode)=>{ | ||||||
|  |     console.log(kode) | ||||||
|  |     try { | ||||||
|  |       await store.product.buyProduct({productCode:kode}); | ||||||
|  |       message.success("Success Buy Product"); | ||||||
|  |     } catch (e) { | ||||||
|  |       message.error("Failed Buy Product"); | ||||||
|  |     } | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   return ( |   return ( | ||||||
| @@ -100,8 +110,8 @@ 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={() => handleBuy(item)}  | ||||||
|                 style={{ cursor: "pointer" }} |                 style={{ cursor: "pointer",backgroundColor:"#2D9CDB" }} | ||||||
|               > |               > | ||||||
|                 <span style={{ color: "black" }}>{item.name}</span> |                 <span style={{ color: "black" }}>{item.name}</span> | ||||||
|                 <br /> |                 <br /> | ||||||
| @@ -118,7 +128,9 @@ 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> | ||||||
|   | |||||||
| @@ -78,6 +78,16 @@ export class Product { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     async buyProduct(data) { | ||||||
|  |         try { | ||||||
|  |             const response = await http.post('/transaction/order').send(data); | ||||||
|  |             await this.getData(); | ||||||
|  |             return response; | ||||||
|  |         } catch (e) { | ||||||
|  |             console.error(e); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     async update(id, data) { |     async update(id, data) { | ||||||
|         try { |         try { | ||||||
|             const response = await http.put(`/product/${id}`).send(data); |             const response = await http.put(`/product/${id}`).send(data); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user